I'm playing a little bit with Zend_Test package and I've found a (IMHO) wrong
behaviour of resetRequest and resetResponse methods. In the example provided
on the documentation there is a testcase with the simulation of a request
from a logged user:

 public function testValidLoginShouldGoToProfilePage()
    {
        $this->request->setMethod('POST')
              ->setPost(array(
                  'username' => 'foobar',
                  'password' => 'foobar'
              ));
        $this->dispatch('/user/login');
        $this->assertRedirectTo('/user/view');

        $this->resetRequest()
             ->resetResponse();

        $this->request->setMethod('GET')
             ->setPost(array());
        $this->dispatch('/user/view');
        $this->assertRoute('default');
        $this->assertModule('default');
        $this->assertController('user');
        $this->assertAction('view');
        $this->assertNotRedirect();
        $this->assertQuery('dl');
        $this->assertQueryContentContains('h2', 'User: foobar');
    }

I've replicated this snippet adapting it to my app and I've seen two things:
- $this->resetRequest()->resetResponse(); call only sets request and
response to null and clears the Zend_Registry instance, so it's mandatory to
execute the following code:
$this->request->setMethod('GET')->setPost(array());

- the setPost function doesn't reset the $_POST global variable, instead if
it's called as in the exampe it has no effect. This is a snipplet of my test
case:

                // login with valid admin
                $this->getRequest()->setMethod('POST')->setPost(
                                array ('username' => 'fabio', 'password' => 
'fabio'));
                $this->dispatch('/login');
                $this->assertRedirectTo('/');

                $this->resetRequest()->resetResponse();
                $this->getRequest()->setPost(array());
                
                //$_POST = array();
                
                //**check for missing body
                $this->getRequest()->setMethod('POST')->setPost(
                                array ('subject' => 'aa', 'language' => 
'test'));
                $this->dispatch('/message/compose');
                Zend_Debug::dump($_POST);


And this is the output of the dump:

array(4) {
  ["username"] => string(5) "fabio"
  ["password"] => string(5) "fabio"
  ["language"] => string(4) "test"
  ["subject"] => string(2) "aa"
}

Therefore the post array is not reset... If I decomment in my code the line
$_POST = array(); the test works as expected and everything goes fine:

array(2) {
  ["language"] => string(4) "test"
  ["subject"] => string(2) "aa"
}

I want to post an issue report on the tracker, but I don't have the create
issue privilege, I tried to wrote an email to ask for it but nobody has
answered me and I still haven't the privilege...



-- 
View this message in context: 
http://www.nabble.com/Zend_Test_PHPUnit_ControllerTestCase-reset-methods-doesn%27t-reset-post-array-tp21625452p21625452.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to