Skip to content

Commit 17d227a

Browse files
oliverkleeSam Tuke
authored andcommitted
[TASK] Use static:: instead of self:: (#87)
This will allow for subclasses to overwrite methods and constants and hence is the current recommended practice.
1 parent 782e73f commit 17d227a

File tree

8 files changed

+64
-61
lines changed

8 files changed

+64
-61
lines changed

Tests/Integration/Composer/ScriptsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ScriptsTest extends TestCase
1717
*/
1818
public function webDirectoryHasBeenCreated()
1919
{
20-
self::assertDirectoryExists($this->getAbsoluteWebDirectoryPath());
20+
static::assertDirectoryExists($this->getAbsoluteWebDirectoryPath());
2121
}
2222

2323
/**
@@ -48,15 +48,15 @@ public function webDirectoryFilesDataProvider(): array
4848
*/
4949
public function webDirectoryFilesExist(string $fileName)
5050
{
51-
self::assertFileExists($this->getAbsoluteWebDirectoryPath() . $fileName);
51+
static::assertFileExists($this->getAbsoluteWebDirectoryPath() . $fileName);
5252
}
5353

5454
/**
5555
* @test
5656
*/
5757
public function binariesDirectoryHasBeenCreated()
5858
{
59-
self::assertDirectoryExists($this->getAbsoluteBinariesDirectoryPath());
59+
static::assertDirectoryExists($this->getAbsoluteBinariesDirectoryPath());
6060
}
6161

6262
/**
@@ -84,7 +84,7 @@ public function binariesDataProvider(): array
8484
*/
8585
public function binariesExist(string $fileName)
8686
{
87-
self::assertFileExists($this->getAbsoluteBinariesDirectoryPath() . $fileName);
87+
static::assertFileExists($this->getAbsoluteBinariesDirectoryPath() . $fileName);
8888
}
8989

9090
/**
@@ -100,7 +100,7 @@ private function getBundleConfigurationFilePath(): string
100100
*/
101101
public function bundleConfigurationFileExists()
102102
{
103-
self::assertFileExists($this->getBundleConfigurationFilePath());
103+
static::assertFileExists($this->getBundleConfigurationFilePath());
104104
}
105105

106106
/**
@@ -123,7 +123,7 @@ public function bundleConfigurationFileContainsModuleBundles(string $bundleClass
123123
{
124124
$fileContents = file_get_contents($this->getBundleConfigurationFilePath());
125125

126-
self::assertContains($bundleClassName, $fileContents);
126+
static::assertContains($bundleClassName, $fileContents);
127127
}
128128

129129
/**
@@ -139,7 +139,7 @@ private function getModuleRoutesConfigurationFilePath(): string
139139
*/
140140
public function moduleRoutesConfigurationFileExists()
141141
{
142-
self::assertFileExists($this->getModuleRoutesConfigurationFilePath());
142+
static::assertFileExists($this->getModuleRoutesConfigurationFilePath());
143143
}
144144

145145
/**
@@ -163,22 +163,22 @@ public function moduleRoutesConfigurationFileContainsModuleRoutes(string $routeS
163163
{
164164
$fileContents = file_get_contents($this->getModuleRoutesConfigurationFilePath());
165165

166-
self::assertContains($routeSearchString, $fileContents);
166+
static::assertContains($routeSearchString, $fileContents);
167167
}
168168

169169
/**
170170
* @test
171171
*/
172172
public function parametersConfigurationFileExists()
173173
{
174-
self::assertFileExists(dirname(__DIR__, 3) . '/Configuration/parameters.yml');
174+
static::assertFileExists(dirname(__DIR__, 3) . '/Configuration/parameters.yml');
175175
}
176176

177177
/**
178178
* @test
179179
*/
180180
public function modulesConfigurationFileExists()
181181
{
182-
self::assertFileExists(dirname(__DIR__, 3) . '/Configuration/config_modules.yml');
182+
static::assertFileExists(dirname(__DIR__, 3) . '/Configuration/config_modules.yml');
183183
}
184184
}

Tests/Integration/Controller/AbstractControllerTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ protected function setUp()
7676
$this->initializeDatabaseTester();
7777
$this->bootstrap = Bootstrap::getInstance()->setEnvironment(Environment::TESTING)->configure();
7878
$this->entityManager = $this->bootstrap->getEntityManager();
79-
self::assertTrue($this->entityManager->isOpen());
79+
static::assertTrue($this->entityManager->isOpen());
8080

81-
$this->client = self::createClient(['environment' => Environment::TESTING]);
81+
$this->client = static::createClient(['environment' => Environment::TESTING]);
8282
}
8383

8484
/**
@@ -226,8 +226,8 @@ protected function authenticatedJsonRequest(
226226
array $server = [],
227227
string $content = null
228228
): Crawler {
229-
$this->getDataSet()->addTable(self::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
230-
$this->getDataSet()->addTable(self::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv');
229+
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
230+
$this->getDataSet()->addTable(static::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv');
231231
$this->applyDatabaseChanges();
232232

233233
$serverWithAuthentication = $server;
@@ -256,7 +256,7 @@ protected function getDecodedJsonResponseContent(): array
256256
*/
257257
protected function assertJsonResponseContentEquals(array $expected)
258258
{
259-
self::assertSame($expected, $this->getDecodedJsonResponseContent());
259+
static::assertSame($expected, $this->getDecodedJsonResponseContent());
260260
}
261261

262262
/**
@@ -270,8 +270,8 @@ protected function assertHttpStatusWithJsonContentType(int $status)
270270
{
271271
$response = $this->client->getResponse();
272272

273-
self::assertSame($status, $response->getStatusCode());
274-
self::assertContains('application/json', (string)$response->headers);
273+
static::assertSame($status, $response->getStatusCode());
274+
static::assertContains('application/json', (string)$response->headers);
275275
}
276276

277277
/**
@@ -334,7 +334,7 @@ protected function assertHttpForbidden()
334334
{
335335
$this->assertHttpStatusWithJsonContentType(Response::HTTP_FORBIDDEN);
336336

337-
self::assertSame(
337+
static::assertSame(
338338
[
339339
'code' => Response::HTTP_FORBIDDEN,
340340
'message' => 'No valid session key was provided as basic auth password.',
@@ -352,7 +352,7 @@ protected function assertHttpMethodNotAllowed()
352352
{
353353
$response = $this->client->getResponse();
354354

355-
self::assertSame(Response::HTTP_METHOD_NOT_ALLOWED, $response->getStatusCode());
355+
static::assertSame(Response::HTTP_METHOD_NOT_ALLOWED, $response->getStatusCode());
356356
}
357357

358358
/**
@@ -365,7 +365,7 @@ protected function assertHttpConflict()
365365
{
366366
$this->assertHttpStatusWithJsonContentType(Response::HTTP_CONFLICT);
367367

368-
self::assertSame(
368+
static::assertSame(
369369
[
370370
'code' => Response::HTTP_CONFLICT,
371371
'message' => 'This resource already exists.',

Tests/Integration/Controller/ListControllerTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ListControllerTest extends AbstractControllerTest
3232
*/
3333
public function controllerIsAvailableViaContainer()
3434
{
35-
self::assertInstanceOf(ListController::class, $this->client->getContainer()->get(ListController::class));
35+
static::assertInstanceOf(ListController::class, $this->client->getContainer()->get(ListController::class));
3636
}
3737

3838
/**
@@ -50,8 +50,8 @@ public function getListsWithoutSessionKeyReturnsForbiddenStatus()
5050
*/
5151
public function getListsWithExpiredSessionKeyReturnsForbiddenStatus()
5252
{
53-
$this->getDataSet()->addTable(self::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
54-
$this->getDataSet()->addTable(self::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv');
53+
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
54+
$this->getDataSet()->addTable(static::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv');
5555
$this->applyDatabaseChanges();
5656

5757
$this->client->request(
@@ -80,7 +80,7 @@ public function getListsWithCurrentSessionKeyReturnsOkayStatus()
8080
*/
8181
public function getListsWithCurrentSessionKeyReturnsListData()
8282
{
83-
$this->getDataSet()->addTable(self::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
83+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
8484
$this->applyDatabaseChanges();
8585

8686
$this->authenticatedJsonRequest('get', '/api/v2/lists');
@@ -116,7 +116,7 @@ public function getListsWithCurrentSessionKeyReturnsListData()
116116
*/
117117
public function getListMembersForExistingListWithoutSessionKeyReturnsForbiddenStatus()
118118
{
119-
$this->getDataSet()->addTable(self::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
119+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
120120
$this->applyDatabaseChanges();
121121

122122
$this->client->request('get', '/api/v2/lists/1/members');
@@ -129,9 +129,9 @@ public function getListMembersForExistingListWithoutSessionKeyReturnsForbiddenSt
129129
*/
130130
public function getListMembersForExistingListWithExpiredSessionKeyReturnsForbiddenStatus()
131131
{
132-
$this->getDataSet()->addTable(self::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
133-
$this->getDataSet()->addTable(self::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
134-
$this->getDataSet()->addTable(self::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv');
132+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
133+
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
134+
$this->getDataSet()->addTable(static::TOKEN_TABLE_NAME, __DIR__ . '/Fixtures/AdministratorToken.csv');
135135
$this->applyDatabaseChanges();
136136

137137
$this->client->request(
@@ -160,7 +160,7 @@ public function getListMembersWithCurrentSessionKeyForInexistentListReturnsNotFo
160160
*/
161161
public function getListMembersWithCurrentSessionKeyForExistingListReturnsOkayStatus()
162162
{
163-
$this->getDataSet()->addTable(self::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
163+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
164164
$this->applyDatabaseChanges();
165165

166166
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/members');
@@ -173,7 +173,7 @@ public function getListMembersWithCurrentSessionKeyForExistingListReturnsOkaySta
173173
*/
174174
public function getListMembersWithCurrentSessionKeyForExistingListWithoutSubscribersReturnsEmptyArray()
175175
{
176-
$this->getDataSet()->addTable(self::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
176+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
177177
$this->applyDatabaseChanges();
178178

179179
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/members');
@@ -186,9 +186,9 @@ public function getListMembersWithCurrentSessionKeyForExistingListWithoutSubscri
186186
*/
187187
public function getListMembersWithCurrentSessionKeyForExistingListWithSubscribersReturnsSubscribers()
188188
{
189-
$this->getDataSet()->addTable(self::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
190-
$this->getDataSet()->addTable(self::SUBSCRIBER_TABLE_NAME, __DIR__ . '/Fixtures/Subscriber.csv');
191-
$this->getDataSet()->addTable(self::SUBSCRIPTION_TABLE_NAME, __DIR__ . '/Fixtures/Subscription.csv');
189+
$this->getDataSet()->addTable(static::LISTS_TABLE_NAME, __DIR__ . '/Fixtures/SubscriberList.csv');
190+
$this->getDataSet()->addTable(static::SUBSCRIBER_TABLE_NAME, __DIR__ . '/Fixtures/Subscriber.csv');
191+
$this->getDataSet()->addTable(static::SUBSCRIPTION_TABLE_NAME, __DIR__ . '/Fixtures/Subscription.csv');
192192
$this->applyDatabaseChanges();
193193

194194
$this->authenticatedJsonRequest('get', '/api/v2/lists/2/members');

Tests/Integration/Controller/SessionControllerTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ protected function setUp()
3434
*/
3535
public function controllerIsAvailableViaContainer()
3636
{
37-
self::assertInstanceOf(SessionController::class, $this->client->getContainer()->get(SessionController::class));
37+
static::assertInstanceOf(
38+
SessionController::class,
39+
$this->client->getContainer()->get(SessionController::class)
40+
);
3841
}
3942

4043
/**
@@ -130,7 +133,7 @@ public function postSessionsWithValidIncompleteJsonReturnsError400(string $jsonD
130133
*/
131134
public function postSessionsWithInvalidCredentialsReturnsNotAuthorized()
132135
{
133-
$this->getDataSet()->addTable(self::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
136+
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
134137
$this->applyDatabaseChanges();
135138

136139
$loginName = 'john.doe';
@@ -153,7 +156,7 @@ public function postSessionsWithInvalidCredentialsReturnsNotAuthorized()
153156
*/
154157
public function postSessionsActionWithValidCredentialsReturnsCreatedHttpStatus()
155158
{
156-
$this->getDataSet()->addTable(self::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
159+
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
157160
$this->applyDatabaseChanges();
158161

159162
$loginName = 'john.doe';
@@ -171,7 +174,7 @@ public function postSessionsActionWithValidCredentialsReturnsCreatedHttpStatus()
171174
public function postSessionsActionWithValidCredentialsCreatesToken()
172175
{
173176
$administratorId = 1;
174-
$this->getDataSet()->addTable(self::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
177+
$this->getDataSet()->addTable(static::ADMINISTRATOR_TABLE_NAME, __DIR__ . '/Fixtures/Administrator.csv');
175178
$this->applyDatabaseChanges();
176179

177180
$loginName = 'john.doe';
@@ -187,9 +190,9 @@ public function postSessionsActionWithValidCredentialsCreatesToken()
187190

188191
/** @var AdministratorToken $token */
189192
$token = $this->administratorTokenRepository->find($tokenId);
190-
self::assertNotNull($token);
191-
self::assertSame($key, $token->getKey());
192-
self::assertSame($expiry, $token->getExpiry()->format(\DateTime::ATOM));
193-
self::assertSame($administratorId, $token->getAdministrator()->getId());
193+
static::assertNotNull($token);
194+
static::assertSame($key, $token->getKey());
195+
static::assertSame($expiry, $token->getExpiry()->format(\DateTime::ATOM));
196+
static::assertSame($administratorId, $token->getAdministrator()->getId());
194197
}
195198
}

Tests/Integration/Controller/SubscriberControllerTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp()
3737
*/
3838
public function controllerIsAvailableViaContainer()
3939
{
40-
self::assertInstanceOf(
40+
static::assertInstanceOf(
4141
SubscriberController::class,
4242
$this->client->getContainer()->get(SubscriberController::class)
4343
);
@@ -68,7 +68,7 @@ public function postSubscribersWithoutSessionKeyReturnsForbiddenStatus()
6868
*/
6969
public function postSubscribersWithValidSessionKeyAndMinimalValidSubscriberDataCreatesResource()
7070
{
71-
$this->touchDatabaseTable(self::SUBSCRIBER_TABLE_NAME);
71+
$this->touchDatabaseTable(static::SUBSCRIBER_TABLE_NAME);
7272

7373
$email = '[email protected]';
7474
$jsonData = ['email' => $email];
@@ -83,7 +83,7 @@ public function postSubscribersWithValidSessionKeyAndMinimalValidSubscriberDataC
8383
*/
8484
public function postSubscribersWithValidSessionKeyAndMinimalValidDataReturnsIdAndUniqueId()
8585
{
86-
$this->touchDatabaseTable(self::SUBSCRIBER_TABLE_NAME);
86+
$this->touchDatabaseTable(static::SUBSCRIBER_TABLE_NAME);
8787

8888
$email = '[email protected]';
8989
$jsonData = ['email' => $email];
@@ -92,16 +92,16 @@ public function postSubscribersWithValidSessionKeyAndMinimalValidDataReturnsIdAn
9292

9393
$responseContent = $this->getDecodedJsonResponseContent();
9494

95-
self::assertGreaterThan(0, $responseContent['id']);
96-
self::assertRegExp('/^[0-9a-f]{32}$/', $responseContent['unique_id']);
95+
static::assertGreaterThan(0, $responseContent['id']);
96+
static::assertRegExp('/^[0-9a-f]{32}$/', $responseContent['unique_id']);
9797
}
9898

9999
/**
100100
* @test
101101
*/
102102
public function postSubscribersWithValidSessionKeyAndValidDataCreatesSubscriber()
103103
{
104-
$this->touchDatabaseTable(self::SUBSCRIBER_TABLE_NAME);
104+
$this->touchDatabaseTable(static::SUBSCRIBER_TABLE_NAME);
105105

106106
$email = '[email protected]';
107107
$jsonData = ['email' => $email];
@@ -111,15 +111,15 @@ public function postSubscribersWithValidSessionKeyAndValidDataCreatesSubscriber(
111111
$responseContent = $this->getDecodedJsonResponseContent();
112112

113113
$subscriberId = $responseContent['id'];
114-
self::assertInstanceOf(Subscriber::class, $this->subscriberRepository->find($subscriberId));
114+
static::assertInstanceOf(Subscriber::class, $this->subscriberRepository->find($subscriberId));
115115
}
116116

117117
/**
118118
* @test
119119
*/
120120
public function postSubscribersWithValidSessionKeyAndExistingEmailAddressCreatesConflictStatus()
121121
{
122-
$this->getDataSet()->addTable(self::SUBSCRIBER_TABLE_NAME, __DIR__ . '/Fixtures/Subscriber.csv');
122+
$this->getDataSet()->addTable(static::SUBSCRIBER_TABLE_NAME, __DIR__ . '/Fixtures/Subscriber.csv');
123123
$this->applyDatabaseChanges();
124124

125125
$email = '[email protected]';
@@ -159,7 +159,7 @@ public function invalidSubscriberDataProvider(): array
159159
*/
160160
public function postSubscribersWithInvalidDataCreatesUnprocessableEntityStatus(array $jsonData)
161161
{
162-
$this->touchDatabaseTable(self::SUBSCRIBER_TABLE_NAME);
162+
$this->touchDatabaseTable(static::SUBSCRIBER_TABLE_NAME);
163163

164164
$this->authenticatedJsonRequest('post', '/api/v2/subscribers', [], [], [], json_encode($jsonData));
165165

@@ -171,7 +171,7 @@ public function postSubscribersWithInvalidDataCreatesUnprocessableEntityStatus(a
171171
*/
172172
public function postSubscribersWithValidSessionKeyAssignsProvidedSubscriberData()
173173
{
174-
$this->touchDatabaseTable(self::SUBSCRIBER_TABLE_NAME);
174+
$this->touchDatabaseTable(static::SUBSCRIBER_TABLE_NAME);
175175

176176
$email = '[email protected]';
177177
$jsonData = [
@@ -186,10 +186,10 @@ public function postSubscribersWithValidSessionKeyAssignsProvidedSubscriberData(
186186

187187
$responseContent = $this->getDecodedJsonResponseContent();
188188

189-
self::assertSame($email, $responseContent['email']);
190-
self::assertTrue($responseContent['confirmed']);
191-
self::assertTrue($responseContent['blacklisted']);
192-
self::assertTrue($responseContent['html_email']);
193-
self::assertTrue($responseContent['disabled']);
189+
static::assertSame($email, $responseContent['email']);
190+
static::assertTrue($responseContent['confirmed']);
191+
static::assertTrue($responseContent['blacklisted']);
192+
static::assertTrue($responseContent['html_email']);
193+
static::assertTrue($responseContent['disabled']);
194194
}
195195
}

0 commit comments

Comments
 (0)