Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:34:53+00:00 2026-06-05T18:34:53+00:00

What I am trying to do is to get instance of Doctrine EM (using

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:34:55+00:00Added an answer on June 5, 2026 at 6:34 pm

    This works for me (taken from ZendCast Many-to-Many with Doctrine 2)

        class ModelTestCase
            extends PHPUnit_Framework_TestCase
        {
            /**
             *
             * @var \Bisna\Application\Container\DoctrineContainer
             */
            protected $doctrineContainer;
    
    
          public function setUp()
        {
            global $application;
            $application->bootstrap();
            $this->doctrineContainer = Zend_Registry::get('doctrine');
    
            $em = $this->doctrineContainer->getEntityManager();
            $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
            $tool->dropDatabase();
            $tool->createSchema($em->getMetadataFactory()->getAllMetadata());
    
            parent::setUp();
        }
    

    Bootstrap.php for the unit tests looks like this:

    <?php
        // Define path to application directory
        defined('APPLICATION_PATH')
           || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
    
        // Define application environment
        define('APPLICATION_ENV', 'testing');
    
        // Ensure library/ is on include_path
        set_include_path(implode(PATH_SEPARATOR, array(
           realpath(APPLICATION_PATH . '/../library'),
           get_include_path()
        )));
    
    
        /** Zend_Application */
        require_once 'Zend/Application.php';
        require_once 'ModelTestCase.php';
        require_once 'ControllerTestCase.php';
        // Create application, bootstrap, and run
        $application = new Zend_Application(
           APPLICATION_ENV,
           APPLICATION_PATH . '/configs/application.ini'
        );
        //$application->bootstrap();
        clearstatcache();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my application running in AppHarbor using a RavenDB instance. I've
I am trying to get an instance of a class to the load an
I'm trying to get a backend instance running on GAE Java but it's not
I'm trying to get one instance of using NSNotificationCenter with addObserver and postNotificationName but
I am trying to get SQL Server instance(s) running on my PC. SqlDataSourceEnumerator instance
Instance A is trying to restore instance B's window, but I can't get the
I'm trying to get the instance name of my class. The way I do
I have sugar crm instance and i was trying to get some data from
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.