在使用SQLite对类别树进行简单测试时,使用
进行设置时测试失败的appbundle \测试\实体\ CategoryTest :: testSetProductCategory() Doctrine \ DBAL \ DBALException:执行时发生异常 ' INSERT INTO类别(title,lft,lvl,rgt,root,deletedAt, parent_id)VALUES(?,?,?,?,?,?,?)'用params [" Hook",null, null,null,null,null,null]:SQLSTATE [23000]:完整性约束 违规:19 NOT NULL约束失败:category.lft
使用MySQL数据库执行相同的测试,测试成功。测试环境数据库&模式是使用控制台命令创建的。
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();
}
doctrine:
dbal:
default_connection: test
connections:
test:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.sqlite
带有MySQL的doctrine:
dbal:
host: localhost
dbname: flyby_test
user: root
password: [password]