Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/PantherTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
namespace Symfony\Component\Panther;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\ForwardCompatTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\Panther\Client as PantherClient;

if (\class_exists(WebTestCase::class)) {
Expand All @@ -31,6 +34,7 @@
if ($canUseAssertions) {
abstract class PantherTestCase extends WebTestCase
{
use ForwardCompatTestTrait;
use PantherTestCaseTrait;
use WebTestAssertionsTrait {
assertPageTitleSame as private baseAssertPageTitleSame;
Expand Down Expand Up @@ -60,6 +64,43 @@ public static function assertPageTitleContains(string $expectedTitle, string $me

self::baseAssertPageTitleContains($expectedTitle, $message);
}

private function doTearDown()
{
parent::tearDown();
self::getClient(null);
}

// Copied from WebTestCase to allow assertions to work with createClient

/**
* Creates a KernelBrowser.
*
* @param array $options An array of options to pass to the createKernel method
* @param array $server An array of server parameters
*
* @return KernelBrowser A KernelBrowser instance
*/
protected static function createClient(array $options = [], array $server = [])
{
$kernel = static::bootKernel($options);

try {
/**
* @var KernelBrowser
*/
$client = $kernel->getContainer()->get('test.client');
} catch (ServiceNotFoundException $e) {
if (class_exists(KernelBrowser::class)) {
throw new \LogicException('You cannot create the client used in functional tests if the "framework.test" config is not set to true.');
}
throw new \LogicException('You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit"');
}

$client->setServerParameters($server);

return self::getClient($client);
}
}
} else {
abstract class PantherTestCase extends WebTestCase
Expand Down