Skip to content

Commit 35c1b59

Browse files
authored
Use self instead of this for PHPUnit assertions (#487)
1 parent 430aa2f commit 35c1b59

21 files changed

+131
-131
lines changed

tests/Autoload/ScoperAutoloadGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function test_generate_the_autoload(Whitelist $whitelist, string $expecte
3232

3333
$actual = $generator->dump($prefix);
3434

35-
$this->assertSame($expected, $actual);
35+
self::assertSame($expected, $actual);
3636
}
3737

3838
public function provideWhitelists(): Generator

tests/ConfigurationTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public function test_it_can_be_created_without_a_file(): void
2929
{
3030
$configuration = Configuration::load();
3131

32-
$this->assertSame([], $configuration->getWhitelistedFiles());
33-
$this->assertEquals(
32+
self::assertSame([], $configuration->getWhitelistedFiles());
33+
self::assertEquals(
3434
Whitelist::create(true, true, true),
3535
$configuration->getWhitelist()
3636
);
37-
$this->assertNull($configuration->getPath());
38-
$this->assertMatchesRegularExpression('/_PhpScoper[a-z\d]{12}/', $configuration->getPrefix());
39-
$this->assertSame([], $configuration->getFilesWithContents());
40-
$this->assertEquals([new SymfonyPatcher()], $configuration->getPatchers());
37+
self::assertNull($configuration->getPath());
38+
self::assertMatchesRegularExpression('/_PhpScoper[a-z\d]{12}/', $configuration->getPrefix());
39+
self::assertSame([], $configuration->getFilesWithContents());
40+
self::assertEquals([new SymfonyPatcher()], $configuration->getPatchers());
4141
}
4242

4343
public function test_it_cannot_create_a_configuration_with_an_invalid_key(): void
@@ -56,9 +56,9 @@ public function test_it_cannot_create_a_configuration_with_an_invalid_key(): voi
5656
try {
5757
Configuration::load($this->tmp.'/scoper.inc.php');
5858

59-
$this->fail('Expected exception to be thrown.');
59+
self::fail('Expected exception to be thrown.');
6060
} catch (InvalidArgumentException $exception) {
61-
$this->assertSame(
61+
self::assertSame(
6262
'Invalid configuration key value "unknown key" found.',
6363
$exception->getMessage()
6464
);
@@ -86,14 +86,14 @@ public function test_it_can_create_a_complete_configuration(): void
8686

8787
$configuration = Configuration::load($this->tmp.DIRECTORY_SEPARATOR.'scoper.inc.php');
8888

89-
$this->assertSame([$this->tmp.DIRECTORY_SEPARATOR.'file1'], $configuration->getWhitelistedFiles());
90-
$this->assertEquals(
89+
self::assertSame([$this->tmp.DIRECTORY_SEPARATOR.'file1'], $configuration->getWhitelistedFiles());
90+
self::assertEquals(
9191
Whitelist::create(false, false, false, 'Foo', 'Bar\*'),
9292
$configuration->getWhitelist()
9393
);
94-
$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'scoper.inc.php', $configuration->getPath());
95-
$this->assertSame('MyPrefix', $configuration->getPrefix());
96-
$this->assertSame([], $configuration->getFilesWithContents());
97-
$this->assertEquals([new SymfonyPatcher()], $configuration->getPatchers());
94+
self::assertSame($this->tmp.DIRECTORY_SEPARATOR.'scoper.inc.php', $configuration->getPath());
95+
self::assertSame('MyPrefix', $configuration->getPrefix());
96+
self::assertSame([], $configuration->getFilesWithContents());
97+
self::assertEquals([new SymfonyPatcher()], $configuration->getPatchers());
9898
}
9999
}

tests/Console/Command/AddPrefixCommandIntegrationTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function test_scope_the_given_paths(): void
8585

8686
$this->appTester->run($input);
8787

88-
$this->assertSame(0, $this->appTester->getStatusCode());
88+
self::assertSame(0, $this->appTester->getStatusCode());
8989

9090
$this->assertFilesAreSame(self::FIXTURE_PATH.'/../scoped', $this->tmp);
9191
}
@@ -108,8 +108,8 @@ public function test_scope_in_quiet_mode(): void
108108

109109
$actual = $this->getNormalizeDisplay($this->appTester->getDisplay(true));
110110

111-
$this->assertSame($expected, $actual);
112-
$this->assertSame(0, $this->appTester->getStatusCode());
111+
self::assertSame($expected, $actual);
112+
self::assertSame(0, $this->appTester->getStatusCode());
113113
}
114114

115115
public function test_scope_in_normal_mode(): void
@@ -165,8 +165,8 @@ public function test_scope_in_normal_mode(): void
165165
$actual
166166
);
167167

168-
$this->assertSame($expected, $actual);
169-
$this->assertSame(0, $this->appTester->getStatusCode());
168+
self::assertSame($expected, $actual);
169+
self::assertSame(0, $this->appTester->getStatusCode());
170170
}
171171

172172
public function test_scope_in_verbose_mode(): void
@@ -211,8 +211,8 @@ public function test_scope_in_verbose_mode(): void
211211

212212
$actual = $this->getNormalizeDisplay($this->appTester->getDisplay(true));
213213

214-
$this->assertSame($expected, $actual);
215-
$this->assertSame(0, $this->appTester->getStatusCode());
214+
self::assertSame($expected, $actual);
215+
self::assertSame(0, $this->appTester->getStatusCode());
216216
}
217217

218218
public function test_scope_in_very_verbose_mode(): void
@@ -285,8 +285,8 @@ public function test_scope_in_very_verbose_mode(): void
285285
// Remove overly lengthy stack-trace
286286
$actual = preg_replace('/(Stack trace:(?:\n\#\d)+)\n?((?:\n\#\d{2,})+)/', '$1', $actual);
287287

288-
$this->assertSame($expected, $actual);
289-
$this->assertSame(0, $this->appTester->getStatusCode());
288+
self::assertSame($expected, $actual);
289+
self::assertSame(0, $this->appTester->getStatusCode());
290290
}
291291

292292
private function getNormalizeDisplay(string $display): string
@@ -317,7 +317,7 @@ private function assertFilesAreSame(string $expectedDir, string $actualDir): voi
317317

318318
$actual = $this->collectFiles($actualDir);
319319

320-
$this->assertSame($expected, $actual);
320+
self::assertSame($expected, $actual);
321321
}
322322

323323
private function collectFiles(string $dir): array

tests/Console/Command/AddPrefixCommandTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public function test_get_help_menu(): void
120120

121121
$actual = $this->appTester->getDisplay(true);
122122

123-
$this->assertSame($expected, $actual);
124-
$this->assertSame(0, $this->appTester->getStatusCode());
123+
self::assertSame($expected, $actual);
124+
self::assertSame(0, $this->appTester->getStatusCode());
125125

126126
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldNotHaveBeenCalled();
127127
}
@@ -143,8 +143,8 @@ public function test_get_version_menu(): void
143143

144144
$actual = $this->appTester->getDisplay(true);
145145

146-
$this->assertSame($expected, $actual);
147-
$this->assertSame(0, $this->appTester->getStatusCode());
146+
self::assertSame($expected, $actual);
147+
self::assertSame(0, $this->appTester->getStatusCode());
148148

149149
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldNotHaveBeenCalled();
150150
}
@@ -200,7 +200,7 @@ public function test_scope_the_given_paths(): void
200200

201201
$this->appTester->run($input);
202202

203-
$this->assertSame(0, $this->appTester->getStatusCode());
203+
self::assertSame(0, $this->appTester->getStatusCode());
204204

205205
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
206206
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(2);
@@ -277,7 +277,7 @@ public function test_let_the_file_unchanged_when_cannot_scope_a_file(): void
277277

278278
$this->appTester->run($input);
279279

280-
$this->assertSame(0, $this->appTester->getStatusCode());
280+
self::assertSame(0, $this->appTester->getStatusCode());
281281

282282
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
283283
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(2);
@@ -336,7 +336,7 @@ public function test_do_not_scope_duplicated_given_paths(): void
336336

337337
$this->appTester->run($input);
338338

339-
$this->assertSame(0, $this->appTester->getStatusCode());
339+
self::assertSame(0, $this->appTester->getStatusCode());
340340

341341
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
342342
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(3);
@@ -397,7 +397,7 @@ public function test_scope_the_given_paths_and_the_ones_found_by_the_finder(): v
397397

398398
$this->appTester->run($input);
399399

400-
$this->assertSame(0, $this->appTester->getStatusCode());
400+
self::assertSame(0, $this->appTester->getStatusCode());
401401

402402
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
403403
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(3);
@@ -448,7 +448,7 @@ function (string $prefix): bool {
448448

449449
$this->appTester->run($input);
450450

451-
$this->assertSame(0, $this->appTester->getStatusCode());
451+
self::assertSame(0, $this->appTester->getStatusCode());
452452

453453
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalled();
454454
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalled();
@@ -509,7 +509,7 @@ public function test_scope_the_current_working_directory_if_no_path_given(): voi
509509

510510
$this->appTester->run($input);
511511

512-
$this->assertSame(0, $this->appTester->getStatusCode());
512+
self::assertSame(0, $this->appTester->getStatusCode());
513513

514514
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
515515
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(1);
@@ -570,7 +570,7 @@ public function test_an_output_directory_can_be_given(): void
570570

571571
$this->appTester->run($input);
572572

573-
$this->assertSame(0, $this->appTester->getStatusCode());
573+
self::assertSame(0, $this->appTester->getStatusCode());
574574

575575
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
576576
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(2);
@@ -632,7 +632,7 @@ public function test_relative_output_directory_are_made_absolute(): void
632632

633633
$this->appTester->run($input);
634634

635-
$this->assertSame(0, $this->appTester->getStatusCode());
635+
self::assertSame(0, $this->appTester->getStatusCode());
636636

637637
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
638638
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(2);
@@ -660,9 +660,9 @@ public function test_throws_an_error_when_passing_a_non_existent_config(): void
660660
try {
661661
$this->appTester->run($input);
662662

663-
$this->fail('Expected exception to be thrown.');
663+
self::fail('Expected exception to be thrown.');
664664
} catch (RuntimeException $exception) {
665-
$this->assertSame(
665+
self::assertSame(
666666
sprintf(
667667
'Could not find the configuration file "%sunknown".',
668668
$this->tmp.DIRECTORY_SEPARATOR
@@ -723,11 +723,11 @@ public function test_attempts_to_use_patch_file_in_current_directory(): void
723723

724724
$this->appTester->run($input);
725725

726-
$this->assertSame(0, $this->appTester->getStatusCode());
726+
self::assertSame(0, $this->appTester->getStatusCode());
727727

728-
$this->assertCount(2, $patchersFound);
729-
$this->assertEquals(new SymfonyPatcher(), $patchersFound[0]);
730-
$this->assertEquals('Hello world!', $patchersFound[1]());
728+
self::assertCount(2, $patchersFound);
729+
self::assertEquals(new SymfonyPatcher(), $patchersFound[0]);
730+
self::assertEquals('Hello world!', $patchersFound[1]());
731731

732732
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(2);
733733

@@ -752,9 +752,9 @@ public function test_throws_an_error_if_patch_file_returns_an_array_with_invalid
752752
try {
753753
$this->appTester->run($input);
754754

755-
$this->fail('Expected exception to be thrown.');
755+
self::fail('Expected exception to be thrown.');
756756
} catch (InvalidArgumentException $exception) {
757-
$this->assertSame(
757+
self::assertSame(
758758
'Expected patchers to be an array of callables, the "0" element is not.',
759759
$exception->getMessage()
760760
);
@@ -809,7 +809,7 @@ public function test_can_scope_projects_with_invalid_files(): void
809809

810810
$this->appTester->run($input);
811811

812-
$this->assertSame(0, $this->appTester->getStatusCode());
812+
self::assertSame(0, $this->appTester->getStatusCode());
813813

814814
$this->fileSystemProphecy->mkdir(Argument::cetera())->shouldHaveBeenCalledTimes(1);
815815
$this->fileSystemProphecy->isAbsolutePath(Argument::cetera())->shouldHaveBeenCalledTimes(1);

tests/ContainerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function test_it_can_instantiate_its_services(string $getterName): void
3030
{
3131
$result = (new Container())->$getterName();
3232

33-
$this->assertNotNull($result);
33+
self::assertNotNull($result);
3434
}
3535

3636
/**
@@ -41,12 +41,12 @@ public function test_it_always_returns_the_same_instance_on_a_container_basis(st
4141
$container = new Container();
4242
$anotherContainer = new Container();
4343

44-
$this->assertSame(
44+
self::assertSame(
4545
$container->$getterName(),
4646
$container->$getterName()
4747
);
4848

49-
$this->assertNotSame(
49+
self::assertNotSame(
5050
$container->$getterName(),
5151
$anotherContainer->$getterName()
5252
);

tests/FunctionsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public function test_it_can_create_an_application(): void
2727
$app1 = Application::create();
2828
$app2 = Application::create();
2929

30-
$this->assertNotSame($app1, $app2);
30+
self::assertNotSame($app1, $app2);
3131
}
3232

3333
public function test_it_gets_the_PHP_Scoper_version(): void
3434
{
3535
$version = get_php_scoper_version();
3636

37-
$this->assertStringContainsString('@', $version);
37+
self::assertStringContainsString('@', $version);
3838
}
3939

4040
/**
@@ -44,7 +44,7 @@ public function test_get_the_common_path(array $paths, string $expected): void
4444
{
4545
$actual = get_common_path($paths);
4646

47-
$this->assertSame($expected, $actual);
47+
self::assertSame($expected, $actual);
4848
}
4949

5050
/**
@@ -54,7 +54,7 @@ public function test_it_can_chain_iterators(array $iterators, array $expected):
5454
{
5555
$actual = iterator_to_array(chain(...$iterators), true);
5656

57-
$this->assertSame($expected, $actual);
57+
self::assertSame($expected, $actual);
5858
}
5959

6060
public function providePaths(): Generator

tests/MakefileE2ETest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function test_the_e2e_test_executes_all_the_e2e_sub_rules(): void
3636
$mainE2ERule = $this->retrieveE2ERule($contents);
3737
$e2eSubRules = $this->retrieveSubE2ERules($contents);
3838

39-
$this->assertSame($e2eSubRules, $mainE2ERule);
39+
self::assertSame($e2eSubRules, $mainE2ERule);
4040
}
4141

4242
/**
@@ -49,7 +49,7 @@ private function retrieveE2ERule(string $makefileContents): array
4949
$makefileContents,
5050
$matches
5151
)) {
52-
$this->assertFalse(false, 'Expected the string input to match the regex');
52+
self::assertFalse(false, 'Expected the string input to match the regex');
5353
}
5454

5555
return array_values(
@@ -75,7 +75,7 @@ private function retrieveSubE2ERules(string $makefileContents): array
7575
$makefileContents,
7676
$matches
7777
)) {
78-
$this->assertFalse(false, 'Expected the string input to match the regex');
78+
self::assertFalse(false, 'Expected the string input to match the regex');
7979
}
8080

8181
return array_values(

tests/Patcher/SymfonyPatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test_patch_the_Symfony_DependencyInjectionContainer_PhpDumper(st
2929
{
3030
$actual = (new SymfonyPatcher())->__invoke($filePath, 'Humbug', $contents);
3131

32-
$this->assertSame($expected, $actual);
32+
self::assertSame($expected, $actual);
3333
}
3434

3535
public function provideFiles(): Generator

tests/PhpParser/TraverserFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public function test_creates_a_new_traverser_at_each_call(): void
4343
$firstTraverser = $traverserFactory->create($phpScoper, $prefix, $whitelist);
4444
$secondTraverser = $traverserFactory->create($phpScoper, $prefix, $whitelist);
4545

46-
$this->assertNotSame($firstTraverser, $secondTraverser);
46+
self::assertNotSame($firstTraverser, $secondTraverser);
4747
}
4848
}

tests/ReflectorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test_it_can_identify_internal_classes(string $class, bool $expec
2929
{
3030
$actual = (new Reflector())->isClassInternal($class);
3131

32-
$this->assertSame($expected, $actual);
32+
self::assertSame($expected, $actual);
3333
}
3434

3535
/**
@@ -39,7 +39,7 @@ public function test_it_can_identify_internal_functions(string $class, bool $exp
3939
{
4040
$actual = (new Reflector())->isFunctionInternal($class);
4141

42-
$this->assertSame($expected, $actual);
42+
self::assertSame($expected, $actual);
4343
}
4444

4545
/**
@@ -49,7 +49,7 @@ public function test_it_can_identify_internal_constants(string $class, bool $exp
4949
{
5050
$actual = (new Reflector())->isConstantInternal($class);
5151

52-
$this->assertSame($expected, $actual);
52+
self::assertSame($expected, $actual);
5353
}
5454

5555
public function provideClasses(): Generator

0 commit comments

Comments
 (0)