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 7876907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:14:34+00:00 2026-06-03T03:14:34+00:00

I have a Zend Framework application with modules and I want to setup PHPUnit

  • 0

I have a Zend Framework application with modules and I want to setup PHPUnit testing.

This is the project folder

- project/
   -application/
      - controllers/
          - indexController.php
      - modules/
         - mycore/
            - controllers/
                -  ActionsController.php
            - views/
                - ...
   - ...
   - tests/
      - application/
         - controllers/
            -IndexControllerTest.php
         - modules/
            - mycore/
                - controllers/
                   - ActionsControllerTest.php
      ControllerTestCase.php
      Bootstrap.php
      phpunit.xml

This is the content of each setup file in the test folder

ControllerTestCase.php

require_once 'Zend/Application.php';
require_once 'Zend/Auth.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';

class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase {
    protected $application

    public function setUp() {
        $this->bootstrap = array($this, 'appBootstrap');
        parent::setUp();
    }

    public function appBootstrap() {
        $this->application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . '/configs/application.ini');
        $bootstrap = $this->application->getBootstrap()->bootstrap();

        $front = Zend_Controller_Front::getInstance();
        $front->setControllerDirectory(APPLICATION_PATH . '/controllers','default');
        $front->addModuleDirectory(APPLICATION_PATH . '/modules');

        return $bootstrap;
    }

    public function tearDown() {
        Zend_Auth::getInstance()->clearIdentity();
        $this->resetRequest();
        $this->resetResponse();
        parent::tearDown();
    }

    protected  function _doLogin($identity = null) {
        if ( $identity === null ) {
            $identity = $this->_generateFakeIdentity();
        }
        Zend_Auth::getInstance()->getStorage()->write( $identity );
    }

    protected function _generateFakeIdentity() {
        $identity = new stdClass();
        $identity->RecID                     = 3;
        $identity->user_firstname            = '****';
        $identity->user_lastname             = '********';
        $identity->confirmed                 = true;
        $identity->enabled                   = true;

        return $identity;
    }

    protected  function _doLogout() {
        Zend_Auth::getInstance()->clearIdentity();
    }
}

Bootstrap.php

error_reporting(E_ALL);
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

require_once 'Zend/Loader/Autoloader.php';

phpunit.xml

<phpunit bootstrap="./bootstrap.php" colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true" >
    <testsuite name="Application Test Suite">
        <directory>./</directory>
    </testsuite>
    <testsuite name="Library Test Suite">
        <directory>./library</directory>
    </testsuite>

    <filter>
        <!-- If Zend Framework is inside your project's library, uncomment this filter -->
        <!-- 
        <whitelist>
            <directory suffix=".php">../../library/Zend</directory>
        </whitelist>
        -->
    </filter>
</phpunit>

And this is the content of the module test

ActionsControllerTest.php

class Mycore_ActionsControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{

    public $module;

    public function setUp()
    {
        $this->module = 'mycore';
        $this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
        $_SERVER['HTTP_HOST'] = 'unittest_host';
        $_SERVER['REQUEST_URI'] = '/';
        parent::setUp();
    }

    public function testIndexAction()
    {
        $this->dispatch("/");
        // assertions
        $this->assertModule('mycore');
        $this->assertController('actions');
        $this->assertAction('index');        
    }


}

And this is the result:

Starting test 'IndexControllerTest::testIndexAction'.
.
Starting test 'Mycore_ActionsControllerTest::testIndexAction'.
F

Time: 1 second, Memory: 14.00Mb

There was 1 failure:

1) Mycore_ActionsControllerTest::testIndexAction
Failed asserting last module used <"default"> was "mycore"

/project/library/Zend/Test/PHPUnit/ControllerTestCase.php:929
/project/tests/application/modules/mycore/controllers/ActionsControllerTest.php:21

All the tests within a module are working fine but when I start testing module controllers I get this error.
I have searched all over the internet but couldn’t find a fix for this error, so I hope someone can help me.

  • 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-03T03:14:35+00:00Added an answer on June 3, 2026 at 3:14 am

    What you are getting is not an error, it is a failing test.

    That’s probably happening because you are dispatching to ‘/’ which looks for the default action in the default controller of the default module. If you dispatch to ‘/mycore’ or ‘/mycore/actions/index’ you will probably find the test passes.

    For your test to pass without changing it you will need to change your default route to point to ‘/mycore/actions/index’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Zend Framework/Doctrine 2 application.: /app /modules /blog /controllers /BlogController.php /domain /entities /services /PostService.php /repositories
I have a PHP MVC application using Zend Framework. As presented in the quickstart,
My setup: Ubuntu LAMP, application built w/ zend framework My Problem: I have a
All, I have a PHP Web application built using Zend Framework and MVC with
I have a Zend Framework application based on the quick-start setup. I've gotten the
i have been using a modular structure for my zend framework application. This is
I am working on a Zend Framework application with PHP. I have a form
I have a Zend Framework modular application set up. One of my modules is
I'm building a web application using PHP5.3 and Zend Framework 1.9.4. i have an
I have project written in Zend Framework and it works fine most of environments.

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.