我正在尝试对我的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致命错误:在第98行的/var/www/symfony/vendor/doctrine-dbal/lib/Doctrine/DBAL/Statement.php中的非对象上调用成员函数bindValue()PHP堆栈跟踪:PHP 1 . ()/ 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/php/PHPUnit/TextUI/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/PHPUnit/Framework/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/php/PHPUnit/Framework/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:64 9 PHP 11. PHPUnit_Framework_TestCase-> runTest()/ usr / share / php / PHPPUnit / Framework / TestCase.php:787 PHP 12. ReflectionMethod-> invokeArgs()/usr/share/php/PHPUnit/Framework/TestCase.php: 925 PHP 13. Yitznewton \ FreermsBundle \ Tests \ Utility \ IpRangeTest-> testSetEndIpForSingle_UpdateSingle_SetsEndIp()/var/www/symfony/src/Yitznewton/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. Doctrine \ 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的/供应商/教义/ LIB /学说/ ORM /持留/ BasicEntityPersister.php:2 33

任何见解?谢谢!