What I am trying to do is to get instance of Doctrine EM (using Bisna Library to load it) in unit test. I can get the instance in controller/model when it’s running in ‘normal’ (not unit testing) mode. And I am going insane of comparing line-by-line code with project where it works 🙁
Unit test:
<?php
class Application_Models_UserTest extends PHPUNit_Framework_TestCase
{
protected $_em;
protected $_model;
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->_em = Zend_Registry::get('doctrine')->getEntityManager();
$this->_model = new Application_Model_User();
parent::setUp();
//$this->_em = Zend_Registry::get('doctrine')->getEntityManager();
//$this->_model = new Application_Model_User();
}
I get:
1) Application_Models_UserTest::testGetByEmailExists
Zend_Exception: No entry is registered for key 'doctrine'
/var/www/html/social_test/library/vendor/Zend/Registry.php:147
/var/www/html/social_test/tests/application/models/UserTest.php:10
As you can see from commented lines, I tried (being desperate) to get doctrine EM instance after parent::setUp() call, unsuccessfully. Thought that parent::setUp() finishes initializing app and it might help.
I am running it with phpunit -c phpunit.xml. phpunit.xml:
<phpunit bootstrap="./bootstrap.php">
<testsuite name="Application Test Suite">
<directory>./application</directory>
</testsuite>
<testsuite name="Library Test Suite">
<directory>./library</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../../library</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./public/report" charset="UTF-8"
yui="true" highlight = "true" lowUpperBound="50" highLowerBound="80" />
</logging>
</phpunit>
Unit testing bootstrap.php is also standard and untouched. Plugin path is specified in application.ini and it’s in production section (so it’s inherited in testing section).
ZF version 1.11.11.
This works for me (taken from ZendCast Many-to-Many with Doctrine 2)
Bootstrap.php for the unit tests looks like this: