PHPUnit and Zend Framework assertRedirectTo () problem

I had a problem with assertRedirectTo () in the test I created, below is the code I used:

public function testLoggedInIndexAction() {
  $this->dispatch('/');
  $this->assertController('index');
  $this->resetResponse();
  $this->request->setPost(array(
   'type' => 'login',
   'username' => 'root',
   'password' => 'asdasd',
  ));
  $this->request->setMethod('POST');
  $this->dispatch('/');
  $this->assertRedirectTo('/feed/');
}

You register through /(index.php/) and send the message details there, and it redirects you to / feed / (index.php / feed /). The details I supplied are correct and should work, however I am having problems due to which PHPUnit says they are incorrect:

There was 1 failure:

1) IndexControllerTest::testLoggedInIndexAction
Failed asserting response redirects to "/feed/"

/home/public_html/mashhr/library/Zend/Test/PHPUnit/Constraint/Redirect.php:190
/home/public_html/mashhr/library/Zend/Test/PHPUnit/ControllerTestCase.php:701
/home/public_html/mashhr/tests/application/controllers/UserControllerTest.php:36
+3
source share
5 answers

@poelinca: No, this is just the case when Zend_Test is not valid when registering a redirect (even if it was called correctly!)

, , , Zend_Test . , , - assertRedirect, .

, Zend, , , . , : , .

. http://framework.zend.com/issues/browse/ZF-7496. : , , .

- Redirects , ! - ( , , OP), .

+3

, . :

$this->assertRedirect();
$responseHeaders = $this->response->getHeaders();
$this->assertTrue(count($responseHeaders) != 0);
$this->assertArrayHasKey('value', $responseHeaders[0]);
// in my case I'm redirecting to another module
$this->assertEquals('/module/controller/action', $responseHeaders[0]['value']);
+3

http://zend-framework-community.634137.n4.nabble.com/Zend-Test-failing-on-AssertRedirectTo-td3325845.html#a4451217

...

. ( , ):

// controller modules/picking/orders/product
$orderId = $this->_getParam('oId');    
if (empty($orderId)) {
    return $this->_redirect('picking/orders/browse/invalid/empty');
}

// test
$this->dispatch('picking/orders/product');
$this->assertRedirect(); // ok
$this->assertRedirectTo('picking/orders/browse'); // error
$this->assertRedirectTo('picking/orders/browse/invalid/empty'); // error

, !


, , , :

'.../public//picking/orders/browse/invalid/empty'
'.../public/picking/orders/browse/invalid/empty'

... !;)

+1

, , , (id , ).

, , , ( eaven , ) , . , , // .

0

, , Url URL ( ), PHPUnit (, , PHPUnit ).

URL- URL- .

0

Source: https://habr.com/ru/post/1776123/


All Articles