mercredi 8 avril 2015

Gedmo\Tree test: SQLite fails, MySQL passes

In a simple test of a Category tree using SQLite, the test fails during setup with



AppBundle\Tests\Entity\CategoryTest::testSetProductCategory() Doctrine\DBAL\DBALException: An exception occurred while executing 'INSERT INTO category (title, lft, lvl, rgt, root, deletedAt, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?)' with params ["Hook", null, null, null, null, null, null]: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: category.lft



Performing the same test with a MySQL database the test succeeds. Test environment databases & schemas are created with console commands.


test setup:



public function setUp()
{
self::bootKernel();
$this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager()
;
$product = new \AppBundle\Entity\Product();
$product->setName('foo');
$this->em->persist($product);

$cat = new \AppBundle\Entity\Category();
$cat->setTitle('Hook');
$this->em->persist($cat);

$child = new \AppBundle\Entity\Category();
$child->setTitle('Dry');
$child->setParent($cat);
$this->em->persist($child);

$this->em->flush();
}


config_test.yml with SQLite:



doctrine:
dbal:
default_connection: test
connections:
test:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.sqlite


config_test.yml with MySQL:



doctrine:
dbal:
host: localhost
dbname: flyby_test
user: root
password: [password]

Aucun commentaire:

Enregistrer un commentaire