EcomDev_PHPUnit icon indicating copy to clipboard operation
EcomDev_PHPUnit copied to clipboard

assertRedirectToUrlRegExp does not work?

Open amenk opened this issue 12 years ago • 5 comments

I have an assertion

        $this->assertRedirectToUrlRegExp('#.*/wishlist/index/index/.*#');

This fails:

Failed asserting that request header "Location" value matches PCRE pattern "#.*/wishlist/index/index/.*#".
http://foobar.local/wishlist/index/index/wishlist_id/7/

When I debug into it, I see that \PHPUnit_Framework_Constraint_PCREMatch::matches returns true.

Also in \PHPUnit_Framework_Constraint::evaluate $success is TRUE, BUT: $returnResult is FALSE and so the result is not passed up.

The call to callProtectedByType does not specify the parameter https://github.com/IvanChepurnyi/EcomDev_PHPUnit/blob/master/lib/EcomDev/PHPUnit/Constraint/Abstract.php#L169

So I think there might be a problem?

amenk avatar Feb 11 '13 12:02 amenk

My current workaround (without touching the module)

        $responseMatch = '#.*/wishlist/index/index/.*#';
        //$this->assertRedirectToUrlRegExp($responseMatch); - does not seem to work @see https://github.com/IvanChepurnyi/EcomDev_PHPUnit/issues/80
        $this->assertRedirect();
        $locationHeader = $this->getResponse()->getSentHeader('Location');
        $this->assertTrue(preg_match($responseMatch, $locationHeader) > 0, sprintf('Location header "%s" did not match "%s"', $locationHeader, $responseMatch));

amenk avatar Feb 11 '13 12:02 amenk

some seems to happen for assertResponseBodyContains()

amenk avatar Feb 12 '13 16:02 amenk

PHPUnit: 3.7.13

amenk avatar Feb 12 '13 16:02 amenk

Please create a pull request with test for this functionality. Test should be created in EcomDev_PHPUnitTest module.

IvanChepurnyi avatar Feb 12 '13 16:02 IvanChepurnyi

The problem you are talking about, could be caused by this call: https://github.com/EcomDev/EcomDev_PHPUnit/blob/dev/lib/EcomDev/PHPUnit/Constraint/Controller/Response/Header.php#L88

It calls PHPUnit evaluate, instead of matches, so it could be the issue.

IvanChepurnyi avatar Sep 23 '13 00:09 IvanChepurnyi