|
14 | 14 | namespace Symfony\Component\Panther;
|
15 | 15 |
|
16 | 16 | use PHPUnit\Framework\TestCase;
|
| 17 | +use Symfony\Bundle\FrameworkBundle\KernelBrowser; |
| 18 | +use Symfony\Bundle\FrameworkBundle\Test\ForwardCompatTestTrait; |
17 | 19 | use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
|
18 | 20 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
19 | 21 | use Symfony\Component\BrowserKit\AbstractBrowser;
|
| 22 | +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
20 | 23 | use Symfony\Component\Panther\Client as PantherClient;
|
21 | 24 |
|
22 | 25 | if (\class_exists(WebTestCase::class)) {
|
|
31 | 34 | if ($canUseAssertions) {
|
32 | 35 | abstract class PantherTestCase extends WebTestCase
|
33 | 36 | {
|
| 37 | + use ForwardCompatTestTrait; |
34 | 38 | use PantherTestCaseTrait;
|
35 | 39 | use WebTestAssertionsTrait {
|
36 | 40 | assertPageTitleSame as private baseAssertPageTitleSame;
|
@@ -60,6 +64,43 @@ public static function assertPageTitleContains(string $expectedTitle, string $me
|
60 | 64 |
|
61 | 65 | self::baseAssertPageTitleContains($expectedTitle, $message);
|
62 | 66 | }
|
| 67 | + |
| 68 | + private function doTearDown() |
| 69 | + { |
| 70 | + parent::tearDown(); |
| 71 | + self::getClient(null); |
| 72 | + } |
| 73 | + |
| 74 | + // Copied from WebTestCase to allow assertions to work with createClient |
| 75 | + |
| 76 | + /** |
| 77 | + * Creates a KernelBrowser. |
| 78 | + * |
| 79 | + * @param array $options An array of options to pass to the createKernel method |
| 80 | + * @param array $server An array of server parameters |
| 81 | + * |
| 82 | + * @return KernelBrowser A KernelBrowser instance |
| 83 | + */ |
| 84 | + protected static function createClient(array $options = [], array $server = []) |
| 85 | + { |
| 86 | + $kernel = static::bootKernel($options); |
| 87 | + |
| 88 | + try { |
| 89 | + /** |
| 90 | + * @var KernelBrowser |
| 91 | + */ |
| 92 | + $client = $kernel->getContainer()->get('test.client'); |
| 93 | + } catch (ServiceNotFoundException $e) { |
| 94 | + if (class_exists(KernelBrowser::class)) { |
| 95 | + throw new \LogicException('You cannot create the client used in functional tests if the "framework.test" config is not set to true.'); |
| 96 | + } |
| 97 | + 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"'); |
| 98 | + } |
| 99 | + |
| 100 | + $client->setServerParameters($server); |
| 101 | + |
| 102 | + return self::getClient($client); |
| 103 | + } |
63 | 104 | }
|
64 | 105 | } else {
|
65 | 106 | abstract class PantherTestCase extends WebTestCase
|
|
0 commit comments