Skip to content

Commit 3852771

Browse files
gnutixSimperfit
authored andcommitted
Remove override of 'client' property and use dynamic call instead of static for makeClient().
1 parent 2437031 commit 3852771

5 files changed

Lines changed: 58 additions & 66 deletions

File tree

src/Test/WebTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ protected function makeClient($authentication = false, array $params = []): Clie
410410
$session->save();
411411
}
412412

413-
return $client;
413+
return static::$client = $client;
414414
}
415415

416416
/**

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ConfigurationTest extends WebTestCase
2525

2626
public function setUp(): void
2727
{
28-
$client = static::makeClient();
29-
$this->clientContainer = $client->getContainer();
28+
static::$client = $this->makeClient();
29+
$this->clientContainer = static::$client->getContainer();
3030
}
3131

3232
/**

tests/Test/WebTestCaseConfigLeanFrameworkTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected static function getKernelClass(): string
3535

3636
public function testAssertStatusCode(): void
3737
{
38-
$client = static::makeClient();
38+
$client = $this->makeClient();
3939

4040
$path = '/';
4141
$client->request('GET', $path);
@@ -45,7 +45,7 @@ public function testAssertStatusCode(): void
4545

4646
public function testAssertValidationErrorsTriggersError(): void
4747
{
48-
$client = static::makeClient();
48+
$client = $this->makeClient();
4949

5050
$path = '/form';
5151
$client->request('GET', $path);

tests/Test/WebTestCaseConfigTest.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Liip\Acme\Tests\Test;
1515

1616
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
17-
use Liip\FunctionalTestBundle\Annotations\DisableDatabaseCache;
1817
use Liip\FunctionalTestBundle\Annotations\QueryCount;
1918
use Liip\FunctionalTestBundle\Test\WebTestCase;
2019
use Liip\Acme\Tests\AppConfig\AppConfigKernel;
@@ -36,9 +35,6 @@
3635
*/
3736
class WebTestCaseConfigTest extends WebTestCase
3837
{
39-
/** @var \Symfony\Bundle\FrameworkBundle\Client client */
40-
private $client = null;
41-
4238
protected static function getKernelClass(): string
4339
{
4440
return AppConfigKernel::class;
@@ -51,16 +47,16 @@ public function testIndexAuthenticationArray(): void
5147
{
5248
$this->loadFixtures([]);
5349

54-
$this->client = static::makeClient([
50+
static::$client = $this->makeClient([
5551
'username' => 'foobar',
5652
'password' => '12341234',
5753
]);
5854

5955
$path = '/';
6056

61-
$crawler = $this->client->request('GET', $path);
57+
$crawler = static::$client->request('GET', $path);
6258

63-
$this->assertStatusCode(200, $this->client);
59+
$this->assertStatusCode(200, static::$client);
6460

6561
$this->assertSame(1,
6662
$crawler->filter('html > body')->count());
@@ -85,13 +81,13 @@ public function testIndexAuthenticationTrue(): void
8581
{
8682
$this->loadFixtures([]);
8783

88-
$this->client = static::makeClient(true);
84+
static::$client = $this->makeClient(true);
8985

9086
$path = '/';
9187

92-
$crawler = $this->client->request('GET', $path);
88+
$crawler = static::$client->request('GET', $path);
9389

94-
$this->assertStatusCode(200, $this->client);
90+
$this->assertStatusCode(200, static::$client);
9591

9692
$this->assertSame(1,
9793
$crawler->filter('html > body')->count());
@@ -127,13 +123,13 @@ public function testIndexAuthenticationLoginAs(): void
127123
$loginAs
128124
);
129125

130-
$this->client = static::makeClient();
126+
static::$client = $this->makeClient();
131127

132128
$path = '/';
133129

134-
$crawler = $this->client->request('GET', $path);
130+
$crawler = static::$client->request('GET', $path);
135131

136-
$this->assertStatusCode(200, $this->client);
132+
$this->assertStatusCode(200, static::$client);
137133

138134
$this->assertSame(1,
139135
$crawler->filter('html > body')->count());
@@ -171,12 +167,12 @@ public function testAllowedQueriesExceededException(): void
171167
$this->loginAs($repository->getReference('user'),
172168
'secured_area');
173169

174-
$this->client = static::makeClient();
170+
static::$client = $this->makeClient();
175171

176172
// One another query to load the second user.
177173
$path = '/user/2';
178174

179-
$this->client->request('GET', $path);
175+
static::$client->request('GET', $path);
180176
}
181177

182178
/**
@@ -194,13 +190,12 @@ public function testAnnotationAndException(): void
194190
$this->loadFixtures([
195191
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
196192
]);
197-
198-
$this->client = static::makeClient();
193+
static::$client = $this->makeClient();
199194

200195
// One query to load the second user
201196
$path = '/user/1';
202197

203-
$this->client->request('GET', $path);
198+
static::$client->request('GET', $path);
204199
}
205200

206201
/**

tests/Test/WebTestCaseTest.php

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
*/
2626
class WebTestCaseTest extends WebTestCase
2727
{
28-
/** @var \Symfony\Bundle\FrameworkBundle\Client client */
29-
private $client = null;
30-
3128
public function setUp(): void
3229
{
3330
static::$class = AppKernel::class;
34-
$this->client = static::makeClient();
31+
static::$client = $this->makeClient();
3532
}
3633

3734
public static function getKernelClass()
@@ -54,7 +51,7 @@ public function testMakeClient(): void
5451
{
5552
$this->assertInstanceOf(
5653
'Symfony\Bundle\FrameworkBundle\Client',
57-
static::makeClient()
54+
$this->makeClient()
5855
);
5956
}
6057

@@ -81,7 +78,7 @@ public function testIndex(): void
8178
$path = '/';
8279

8380
/** @var \Symfony\Component\DomCrawler\Crawler $crawler */
84-
$crawler = $this->client->request('GET', $path);
81+
$crawler = static::$client->request('GET', $path);
8582

8683
$this->assertSame(1,
8784
$crawler->filter('html > body')->count());
@@ -110,9 +107,9 @@ public function testIndexAssertStatusCode(): void
110107

111108
$path = '/';
112109

113-
$this->client->request('GET', $path);
110+
static::$client->request('GET', $path);
114111

115-
$this->assertStatusCode(200, $this->client);
112+
$this->assertStatusCode(200, static::$client);
116113
}
117114

118115
/**
@@ -124,10 +121,10 @@ public function testAssertStatusCodeFail(): void
124121

125122
$path = '/';
126123

127-
$this->client->request('GET', $path);
124+
static::$client->request('GET', $path);
128125

129126
try {
130-
$this->assertStatusCode(-1, $this->client);
127+
$this->assertStatusCode(-1, static::$client);
131128
} catch (AssertionFailedError $e) {
132129
$this->assertStringStartsWith(
133130
'HTTP/1.1 200 OK',
@@ -154,10 +151,10 @@ public function testAssertStatusCodeException(): void
154151

155152
$path = '/user/2';
156153

157-
$this->client->request('GET', $path);
154+
static::$client->request('GET', $path);
158155

159156
try {
160-
$this->assertStatusCode(-1, $this->client);
157+
$this->assertStatusCode(-1, static::$client);
161158
} catch (AssertionFailedError $e) {
162159
$string = <<<'EOF'
163160
No user found
@@ -180,9 +177,9 @@ public function testIndexIsSuccesful(): void
180177

181178
$path = '/';
182179

183-
$this->client->request('GET', $path);
180+
static::$client->request('GET', $path);
184181

185-
$this->isSuccessful($this->client->getResponse());
182+
$this->isSuccessful(static::$client->getResponse());
186183
}
187184

188185
/**
@@ -240,11 +237,11 @@ public function test404Error(): void
240237

241238
$path = '/missing_page';
242239

243-
$this->client->request('GET', $path);
240+
static::$client->request('GET', $path);
244241

245-
$this->assertStatusCode(404, $this->client);
242+
$this->assertStatusCode(404, static::$client);
246243

247-
$this->isSuccessful($this->client->getResponse(), false);
244+
$this->isSuccessful(static::$client->getResponse(), false);
248245
}
249246

250247
/**
@@ -704,23 +701,23 @@ public function testForm(): void
704701

705702
$path = '/form';
706703

707-
$crawler = $this->client->request('GET', $path);
704+
$crawler = static::$client->request('GET', $path);
708705

709-
$this->assertStatusCode(200, $this->client);
706+
$this->assertStatusCode(200, static::$client);
710707

711708
$form = $crawler->selectButton('Submit')->form();
712-
$crawler = $this->client->submit($form);
709+
$crawler = static::$client->submit($form);
713710

714-
$this->assertStatusCode(200, $this->client);
711+
$this->assertStatusCode(200, static::$client);
715712

716-
$this->assertValidationErrors(['children[name].data'], $this->client->getContainer());
713+
$this->assertValidationErrors(['children[name].data'], static::$client->getContainer());
717714

718715
// Try again with the fields filled out.
719716
$form = $crawler->selectButton('Submit')->form();
720717
$form->setValues(['form[name]' => 'foo bar']);
721-
$crawler = $this->client->submit($form);
718+
$crawler = static::$client->submit($form);
722719

723-
$this->assertStatusCode(200, $this->client);
720+
$this->assertStatusCode(200, static::$client);
724721

725722
$this->assertContains(
726723
'Name submitted.',
@@ -739,23 +736,23 @@ public function testFormWithEmbed(): void
739736

740737
$path = '/form-with-embed';
741738

742-
$crawler = $this->client->request('GET', $path);
739+
$crawler = static::$client->request('GET', $path);
743740

744-
$this->assertStatusCode(200, $this->client);
741+
$this->assertStatusCode(200, static::$client);
745742

746743
$form = $crawler->selectButton('Submit')->form();
747-
$crawler = $this->client->submit($form);
744+
$crawler = static::$client->submit($form);
748745

749-
$this->assertStatusCode(200, $this->client);
746+
$this->assertStatusCode(200, static::$client);
750747

751-
$this->assertValidationErrors(['children[name].data'], $this->client->getContainer());
748+
$this->assertValidationErrors(['children[name].data'], static::$client->getContainer());
752749

753750
// Try again with the fields filled out.
754751
$form = $crawler->selectButton('Submit')->form();
755752
$form->setValues(['form[name]' => 'foo bar']);
756-
$crawler = $this->client->submit($form);
753+
$crawler = static::$client->submit($form);
757754

758-
$this->assertStatusCode(200, $this->client);
755+
$this->assertStatusCode(200, static::$client);
759756

760757
$this->assertContains(
761758
'Name submitted.',
@@ -774,16 +771,16 @@ public function testFormWithException(): void
774771

775772
$path = '/form';
776773

777-
$crawler = $this->client->request('GET', $path);
774+
$crawler = static::$client->request('GET', $path);
778775

779-
$this->assertStatusCode(200, $this->client);
776+
$this->assertStatusCode(200, static::$client);
780777

781778
$form = $crawler->selectButton('Submit')->form();
782-
$this->client->submit($form);
779+
static::$client->submit($form);
783780

784-
$this->assertStatusCode(200, $this->client);
781+
$this->assertStatusCode(200, static::$client);
785782

786-
$this->assertValidationErrors([''], $this->client->getContainer());
783+
$this->assertValidationErrors([''], static::$client->getContainer());
787784
}
788785

789786
/**
@@ -796,14 +793,14 @@ public function testFormWithExceptionAssertStatusCode(): void
796793

797794
$path = '/form';
798795

799-
$crawler = $this->client->request('GET', $path);
796+
$crawler = static::$client->request('GET', $path);
800797

801798
$form = $crawler->selectButton('Submit')->form();
802799

803-
$this->client->submit($form);
800+
static::$client->submit($form);
804801

805802
try {
806-
$this->assertStatusCode(-1, $this->client);
803+
$this->assertStatusCode(-1, static::$client);
807804
} catch (AssertionFailedError $e) {
808805
$string = <<<'EOF'
809806
Unexpected validation errors:
@@ -826,14 +823,14 @@ public function testJsonIsSuccesful(): void
826823
{
827824
$this->loadFixtures([]);
828825

829-
$this->client = static::makeClient();
826+
static::$client = $this->makeClient();
830827

831828
$path = '/json';
832829

833-
$this->client->request('GET', $path);
830+
static::$client->request('GET', $path);
834831

835832
$this->isSuccessful(
836-
$this->client->getResponse(),
833+
static::$client->getResponse(),
837834
true,
838835
'application/json'
839836
);
@@ -843,6 +840,6 @@ public function tearDown(): void
843840
{
844841
parent::tearDown();
845842

846-
$this->client = null;
843+
static::$client = null;
847844
}
848845
}

0 commit comments

Comments
 (0)