Я пытаюсь протестировать результаты событий жизненного цикла в моих сущностях Doctrine2.PrePersist работает, но не PreUpdate:
// in Entity class:
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function setEndIpForSingle()
{
if (isset($this->startIp) && !isset($this->endIp)) {
$this->setEndIp($this->startIp);
}
}
// in test:
class IpRangeTest extends OrmTestCase
{
protected $_em;
protected function setUp()
{
$reader = new AnnotationReader();
$reader->setIgnoreNotImportedAnnotations(true);
$reader->setEnableParsePhpImports(true);
$metadataDriver = new AnnotationDriver(
$reader, 'Yitznewton\\FreermsBundle\\Entity'
);
$this->_em = $this->_getTestEntityManager();
$this->_em->getConfiguration()
->setMetadataDriverImpl($metadataDriver);
$this->_em->getConfiguration()->setEntityNamespaces(array(
'YitznewtonFreermsBundle' => 'Yitznewton\\FreermsBundle\\Entity'));
}
public function testSetEndIpForSingle_UpdateSingle_SetsEndIp()
{
$ipRange = new IpRange();
$ipRange->setStartIp('192.245.1.1');
$ipRange->setEndIp('192.245.1.2');
$this->_em->persist($ipRange);
$this->_em->flush(); // this is line 68
$ipRange->setStartIp('192.245.2.1');
$ipRange->setEndIp(null);
$this->_em->flush();
$this->assertEquals('192.245.2.1', $ipRange->getEndIp(),
'IpRange::endIp set on update of single IP address');
}
Результат:
Неустранимая ошибка PHP: вызов функции-члена bindValue () для необъекта в / var / www /symfony / vendor / doctrine-dbal / lib / Doctrine / DBAL / Statement.php в строке 98 Трассировка стека PHP: PHP 1. {main} () / usr / bin / phpunit: 0 PHP 2. PHPUnit_TextUI_Command :: main () /usr / bin / phpunit: 44 PHP 3. PHPUnit_TextUI_Command-> run () /usr/share/php/PHPUnit/TextUI/Command.php:125 PHP 4. PHPUnit_TextUI_TestRunner-> doRun () / usr / share / phpTextUI / Command.php: 187 PHP 5. PHPUnit_Framework_TestSuite-> run () /usr/share/php/PHPUnit/TextUI/TestRunner.php:325 PHP 6. PHPUnit_Framework_TestSuite-> run () / usr / share / php / PHPFramework / TestSuite.php: 705 PHP 7. PHPUnit_Framework_TestSuite-> runTest () /usr/share/php/PHPUnit/Framework/TestSuite.php:745 PHP 8. PHPUnit_Framework_TestCase-> run () / usr / share / phpFramework / TestSuite.php: 772 PHP 9. PHPUnit_Framework_TestResult-> run () /usr/share/php/PHPUnit/Framework/TestCase.php:734 PHP 10. PHPUnit_Framework_TestCase-> runBare () /usr/share/php/PHPUnit/Framework/TestResult.php:649 PHP 11. PHPUnit_Framework_TestCase-> runTest () /usr/share/php/PHPUnit/Framework.p78.CGReflectionMethod-> invokeArgs () /usr/share/php/PHPUnit/Framework/TestCase.php:925 PHP 13.FreermsBundle / Tests / Utility / IpRangeTest.php: 0 PHP 14. Doctrine \ ORM \ EntityManager-> flush () /var/www/symfony/src/Yitznewton/FreermsBundle/Tests/Utility/IpRangeTest.php:68 PHP 15. Doct\ ORM \ UnitOfWork-> commit () /var/www/symfony/vendor/doctrine/lib/Doctrine/ORM/EntityManager.php:334 PHP 16. Doctrine \ ORM \ UnitOfWork-> executeInserts () / var / www / symfony/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php:292 PHP 17. Doctrine \ ORM \ Persisters \ BasicEntityPersister-> executeInserts () / var / www / symfony / vendor / doctrine / lib / Doctrine / ORM / UnitOfWork.php: 726 PHP 18. Doctrine \ DBAL \ Statement-> bindValue () / var / www / symfony / vendor / doctrine / lib / Doctrine / ORM / Persisters / BasicEntityPersister.php: 233
Есть идеи?Спасибо!