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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:14:42+00:00 2026-05-20T14:14:42+00:00

I have a unit tests for Zend Framework controllers extending Zend_Test_PHPUnit_ControllerTestCase . The tests

  • 0

I have a unit tests for Zend Framework controllers extending Zend_Test_PHPUnit_ControllerTestCase.

The tests are dispatching an action, which forwards to another action, like this:

// AdminControllerTest.php

public testAdminAction()    
   $this->dispath('/admin/index/index');
   // forwards to login page
   $this->assertModule('user');
   $this->assertController('profile');
   $this->assertController('login');
   $this->assertResponseCode(401);
}

// NewsControllerTest.php

public testIndexAction()
{
     $this->dispatch('/news/index/index');
     $this->assertModule('news');
     $this->assertController('index');
     $this->assertController('index');
     $this->assertResponseCode(200);

}

Both of the tests are passing when they are run as a seperate tests.
When I run them in the same test suite, the second one fails.
Instead dispatching /news/index/index the previous request is dispatched (user module).

How to trace this bug? Looks like I have some global state somewhere in the application, but I’m unable do debug this. How can I dump the objects between the tests in the suite? setUpBefore/AfterClass are static, so there are no so many data about the object instances.

I know this is a kind of guess what question. It’s hard to provide reliable data here, because they would took to much place, so feel free to ask for details.

The whole unit test setup is more or less like described in: Testing Zend Framework MVC Applications – phly, boy, phly or Testing Zend Framework Controllers « Federico Cargnelutti.

Solution:

I’ve determined the issue (after a little nap). The problem was not in unit test setup, but in the tested code.

I use different ACL objects based on module name. Which one to use was determined by static call to action helper, which cached the result in a private static variable to speed things up. This cache was executed only when run in a test suite. I just need more unit tests for this code 🙂

(I’m sorry for such a rubbish post, but I’ve stuck with this for a day and I hoped someone else experienced similar kind of this Heisenbug with unit tests in general)

  • 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-05-20T14:14:42+00:00Added an answer on May 20, 2026 at 2:14 pm

    You may try clearingrequest and response objects before dispatching each action, like this:

    $this->resetRequest()
         ->resetResponse()
         ->dispatch('/news/index/index');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been creating Unit tests like crazy and find that I'm often having
I have a coworker who writes unit tests for objects which fill their fields
I have read many posts about setting up unit testing in Zend Framework and
I use Zend_Test for unit testing in Zend Framework. I have configured the bootstrap
I have been getting into Unit Testing with Zend Framework. I am getting used
I have a number of projects in a solution file that have unit tests
I am trying to be a good programmer and have unit tests for my
I'm working on a Spring MVC project, and I have unit tests for all
My understanding is that you have to write unit tests that isolate functionality. So
How would you maintain the legacy applications that: Has no unit tests have big

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.