panther
panther copied to clipboard
Error in a `PantherTestCase` when using assertion from `BrowserKitAssertionsTrait` like `assertResponseIsSuccessful`
In a PantherTestCase
When we use an assertion from the BrowserKitAssertionsTrait
, we get a TypeError
:
TypeError : Return value of Symfony\Component\Panther\PantherTestCase::getResponse() must be an instance of Symfony\Component\HttpFoundation\Response, instance of Symfony\Component\BrowserKit\Response returned
/var/www/html/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:148
/var/www/html/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:36
For exemple I have that error with that two function.
$this->assertResponseStatusCodeSame(302);
$this->assertResponseIsSuccessful();
I use BrowserKit
(createHttpBrowserClient
) as client.
We should return a better error message, but it's not possible to use these assertions with Panther because WebDriver doesn't give access to the HTTP headers.
Thank you for the fast answer. Is that also the case when we use the HttpBrowserClient
?
Because the following expression work when client is a HttpBrowserClient
(created with createHttpBrowserClient()
method) :
$this->assertEquals(200, $client->getResponse()->getStatusCode(), $client->getResponse()->getContent());
If some methods of the trait BrowserKitAssertionsTrait
should never be used regardless of the client in a PantherTestCase
, maybe that methods should be made private when used in trait src/WebTestAssertionsTrait.php
?
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait as BaseWebTestAssertionsTrait;
use BaseWebTestAssertionsTrait {
assertPageTitleSame as private baseAssertPageTitleSame;
assertPageTitleContains as private baseAssertPageTitleContains;
}