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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:15:13+00:00 2026-06-13T12:15:13+00:00

When doing unit testing using PhpUnit in ZF2, the following message shows up: Failed

  • 0

When doing unit testing using PhpUnit in ZF2, the following message shows up:

Failed asserting that 302 matches expected 200

I understand that it shown up because of the redirection command of ZF2:

return $this->redirect()->toUrl('/admin/album/add');

But when I access it in the browser, the site works find with the above code. But it fails in the unit testing.

What should I have to change?

  • 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-13T12:15:14+00:00Added an answer on June 13, 2026 at 12:15 pm

    A browser is not the same as unit testing or vice versa. Your expectations or results are different.

    A browser that receives a 302 response code HAS to redirect which means it will take the URL in the response and submit a new request. The result you see in your browser is the redirected page.

    Unit testing does not redirect. Your unit test is only doing what you direct it to do. If your unit test should test for the redirect then you evaluate the response and the correct assertion is 302 and not 200.

    If you want to make sure that the URL in the redirect is correct you’ll have to write another test that actually fetches the new page and test that response for 200 OK.

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

Sidebar

Related Questions

I have been doing TDD and was using it more as unit testing than
Doing an ajax get request works as expected using the following code: $.ajax({ type:
I'm having a bit of trouble doing some unit-testing using moq. If I have
I am doing unit testing on my iPhone app using OCUnit on XCode 3.2.3,
I'm doing unit testing on a class library that uses NHibernate for persistence. NHibernate
I am doing some unit testing for a DAO that works with postgresql. Some
I am already using unit testing to ensure that all critical bits and pieces
When doing unit testing in Android activities using ActivityInstrumentationTestCase you could use TouchUtils to
I have been doing unit testing recently and I've successfully mocked various scenarios using
I'm doing some unit testing, and mocking some properties using Moq . Now, this

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.