Isotope getProduct() liefert null
Im Integrationstest meiner extension habe ich den folgenden Testcase. Das Item ist mit dem Produkt id 88 verknüpft und $objItem wird noch richtig geholt. Dass das Produkt nicht geholt wird, liegt vielleicht an meiner Deklaration ( $GLOBALS['TL_MODELS']['tl_iso_product'] = Product::class; )? Wenn ich Standard::class verwende statt Product::class, ist es eigentlich richtiger, oder? Weil die Objekte ja nur von Standard gebildet werden können. Aber auch das führt leider zum selben Fehler.
PHP-Code:
<?php
declare(strict_types=1);
namespace Nahati\ContaoIsotopeStockBundle\Tests\Integration\EventListener;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Framework\Adapter;
use Contao\Database;
use Contao\TestCase\FunctionalTestCase;
use Isotope\Model\Product;
use Isotope\Model\Product\Standard;
use Isotope\Model\ProductCollection;
use Isotope\Model\ProductCollection\Cart;
use Isotope\Model\ProductCollectionItem;
use Nahati\ContaoIsotopeStockBundle\EventListener\UpdateItemInCollectionListener;
/**
* Test the UpdateItemInCollectionListener class.
*/
class UpdateItemInCollectionListenerTest extends FunctionalTestCase
{
private ContaoFramework $framework;
private Adapter $databaseAdapter;
private ProductCollectionItem $objItem;
private Cart $objCart;
private mixed $arrSet;
private Standard $objProduct;
private mixed $return;
// In constructor we initialize the neccessary environment once for all tests
public function __construct()
{
parent::__construct();
static::bootKernel();
$this->framework = static::getContainer()->get('contao.framework');
$this->framework->initialize();
/** @varAdapter<Database> $databaseAdapter */
$this->databaseAdapter = $this->framework->getAdapter(Database::class);
// Drop all tables
foreach ($this->databaseAdapter->getInstance()->listTables() as $table) {
$sql = 'DROP TABLE IF EXISTS ' . $table;
$this->databaseAdapter->getInstance()->execute($sql);
};
// Create tables and insert data
$this->loadFixture('zfr00_cleverquir-4-Produkte-Im Warenkorb.sql');
// These assignments link the tables with the model classes. Now we can use the model classes to access and manipulate the data in the tables.
$GLOBALS['TL_MODELS']['tl_iso_product'] = Product::class;
$GLOBALS['TL_MODELS']['tl_iso_product_collection'] = ProductCollection::class;
$GLOBALS['TL_MODELS']['tl_iso_product_collection_item'] = ProductCollectionItem::class;
}
private function loadFixture(string $fileName): void
{
$sql = file_get_contents(__DIR__ . '/..' . '/Fixtures/' . $fileName);
$this->databaseAdapter->getInstance()->execute($sql);
// $this->connection->executeStatement($sql);
}
/**
* setup() is called for each Testcase and contains the basic setup for the tests.
* Override this method if you need to change the basic setup.
*/
public function setUp(): void
{
parent::setUp();
// Instantiate a Cart object with id '263'
$this->objCart = Cart::findByPk('263');
}
public function testUpdateItemInCollectionListenerReturnsUnchangedQuantityWhenProductIsNotAVariantAndProductHasUnlimitedQuantity(): void
{
// Instantiate the Item with id '3105' of this Cart
$this->objItem = ProductCollectionItem::findByPk('3105');
/** @varStandard|null $objProduct */
$objProduct = $this->objItem->getProduct() ?? null;
// ...
}
}
Die sourcen finden sich auf github: https://github.com/nahati/contao-iso...tree/2.0.1-dev