Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b50107

Browse files
[FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait
1 parent a6b306d commit 3b50107

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/WebTestAssertionsTrait.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,19 @@ public static function assertRouteSame($expectedRoute, array $parameters = [], s
186186
self::assertThat(static::getRequest(), $constraint, $message);
187187
}
188188

189-
private static function getClient(): KernelBrowser
189+
private static function getClient(KernelBrowser $newClient = null): ?KernelBrowser
190190
{
191-
if (!static::$client instanceof KernelBrowser) {
192-
static::fail(\sprintf('A client must be set to make assertions on it. Did you forget to call "%s::createClient"?', __CLASS__));
191+
static $client;
192+
193+
if (0 < \func_num_args()) {
194+
return $client = $newClient;
195+
}
196+
197+
if (!$client instanceof KernelBrowser) {
198+
static::fail(\sprintf('A client must be set to make assertions on it. Did you forget to call "%s::createClient()"?', __CLASS__));
193199
}
194200

195-
return static::$client;
201+
return $client;
196202
}
197203

198204
private static function getCrawler(): Crawler

src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ abstract class WebTestCase extends KernelTestCase
2323
{
2424
use WebTestAssertionsTrait;
2525

26-
/** @var KernelBrowser|null */
27-
protected static $client;
28-
2926
protected function doTearDown(): void
3027
{
3128
parent::doTearDown();
32-
33-
static::$client = null;
29+
self::getClient(null);
3430
}
3531

3632
/**
@@ -56,6 +52,6 @@ protected static function createClient(array $options = [], array $server = [])
5652

5753
$client->setServerParameters($server);
5854

59-
return static::$client = $client;
55+
return self::getClient($client);
6056
}
6157
}

src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,9 @@ private function getTester(KernelBrowser $client): WebTestCase
277277
return new class($client) extends WebTestCase {
278278
use WebTestAssertionsTrait;
279279

280-
protected static $client;
281-
282280
public function __construct(KernelBrowser $client)
283281
{
284-
static::$client = $client;
282+
self::getClient($client);
285283
}
286284
};
287285
}

0 commit comments

Comments
 (0)