I just start testing in Symfony. And I am using Symfony/Panther to achieve testing. But I'm facing an error which is :
LogicException: HttpFoundation Response object is not available when using WebDriver.
Here is my test code:
<?php
namespace App\Tests\Controller;
use App\Repository\UserRepository;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Symfony\Component\Panther\PantherTestCase;
use Symfony\Component\Panther\Client;
class UserManagmentControllerTest extends PantherTestCase
{
/** @var AbstractDatabaseTool */
protected $databaseTool;
private ?Client $client = null;
public function setUp(): void
{
parent::setUp();
if (null === $this->client) {
$this->client = static::createPantherClient();
}
$this->databaseTool = static::getContainer()->get(DatabaseToolCollection::class)->get();
}
public function testShouldLoadAllUsersList()
{
$userRepository = static::getContainer()->get(UserRepository::class);
// retrieve the test user
$testUser = $userRepository->findOneByEmail('[email protected]');
// simulate $testUser being logged in
// $this->client->loginUser($testUser->setRoles("[\"ROLE_ADMIN\"]"));
$this->client->request('GET', '/admin/liste-des-utilisateurs');
// $this->assertResponseIsSuccessful();
// $this->client->getWebDriver()->findElement(WebDriverBy::name('rgpd'))->click();
$this->assertResponseRedirects();
}
protected function tearDown(): void
{
parent::tearDown();
$this->client->close();
unset($this->databaseTool);
}
}
In Panther documentation on github it is said that we can Use any PHPUnit assertion, including the ones provided by Symfony.
So why do I get this error ?
Thank you in advance
Php version: 8.1.7 Symfony version: 6.1.3 Panther version: 2.0
It's seems it is currently not possible if you use Panther. For simple HTTP requests they recommend to use WebTestCase. Something like this: