Skip to content

Commit 19cdd3c

Browse files
committed
Refactored tests
2 parents 9592757 + 1c65958 commit 19cdd3c

22 files changed

+138
-153
lines changed

tests/CompoundFixerTest.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,26 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Polymorphine\Dev\FixerFactory;
16-
use Polymorphine\Dev\Tests\Fixtures\FixerTestRunner;
1716

1817

1918
/** @group integrated */
2019
class CompoundFixerTest extends TestCase
2120
{
22-
private FixerTestRunner $runner;
21+
private static Fixtures\FixerTestRunner $runner;
2322

24-
protected function setUp(): void
23+
public static function setUpBeforeClass(): void
2524
{
2625
$config = FixerFactory::createFor(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'cs-fixer.php.dist');
27-
$this->runner = FixerTestRunner::withConfig($config);
26+
self::$runner = Fixtures\FixerTestRunner::withConfig($config);
2827
}
2928

30-
/**
31-
* @dataProvider fileList
32-
*
33-
* @param string $fileExpected
34-
* @param string $fileGiven
35-
*/
36-
public function testFixedFiles_MatchExpectations(string $fileExpected, string $fileGiven)
29+
/** @dataProvider fileList */
30+
public function test_FixedFiles_MatchExpectations(string $fileExpected, string $fileGiven)
3731
{
38-
$sourceCode = file_get_contents($fileGiven);
39-
$this->assertSame(file_get_contents($fileExpected), $this->runner->fix($sourceCode));
32+
self::assertSame(file_get_contents($fileExpected), self::$runner->fix(file_get_contents($fileGiven)));
4033
}
4134

42-
public function fileList(): array
35+
public static function fileList(): iterable
4336
{
4437
$files = [];
4538
foreach (array_diff(scandir(__DIR__ . '/Fixtures/code-samples/Fixer'), ['..', '.']) as $file) {

tests/Fixer/AlignedArrayValuesFixerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class AlignedArrayValuesFixerTest extends FixerTest
2020
{
21-
public function testNonAssociativeArraysAreNotChanged()
21+
public function test_NonAssociativeArrays_AreNotChanged()
2222
{
2323
$code = <<<'CODE'
2424
<?php
@@ -30,10 +30,10 @@ public function testNonAssociativeArraysAreNotChanged()
3030

3131
CODE;
3232

33-
$this->assertSame($code, $this->runner->fix($code));
33+
$this->assertUnchanged($code);
3434
}
3535

36-
public function testSingleLineArraysAreNotChanged()
36+
public function test_SingleLineArrays_AreNotChanged()
3737
{
3838
$code = <<<'CODE'
3939
<?php
@@ -42,10 +42,10 @@ public function testSingleLineArraysAreNotChanged()
4242

4343
CODE;
4444

45-
$this->assertSame($code, $this->runner->fix($code));
45+
$this->assertUnchanged($code);
4646
}
4747

48-
public function testMultilineArraysAreAligned()
48+
public function test_MultilineArrays_AreAligned()
4949
{
5050
$code = <<<'CODE'
5151
<?php
@@ -71,10 +71,10 @@ public function testMultilineArraysAreAligned()
7171

7272
CODE;
7373

74-
$this->assertSame($expected, $this->runner->fix($code));
74+
$this->assertFixed($code, $expected);
7575
}
7676

77-
public function testNotExclusivelyMultilineArraysAreNotChanged()
77+
public function test_NotExclusivelyMultilineArrays_AreNotChanged()
7878
{
7979
$code = <<<'CODE'
8080
<?php
@@ -88,7 +88,7 @@ public function testNotExclusivelyMultilineArraysAreNotChanged()
8888

8989
CODE;
9090

91-
$this->assertSame($code, $this->runner->fix($code));
91+
$this->assertUnchanged($code);
9292
}
9393

9494
protected function fixer(): FixerInterface

tests/Fixer/AlignedAssignmentsFixerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class AlignedAssignmentsFixerTest extends FixerTest
2020
{
21-
public function testVariableAssignmentsAreAligned()
21+
public function test_VariableAssignments_AreAligned()
2222
{
2323
$code = <<<'CODE'
2424
<?php
@@ -38,10 +38,10 @@ public function testVariableAssignmentsAreAligned()
3838

3939
CODE;
4040

41-
$this->assertSame($expected, $this->runner->fix($code));
41+
$this->assertFixed($code, $expected);
4242
}
4343

44-
public function testMixedKindVariableAssignmentsAreAlignedSeparately()
44+
public function test_MixedKindVariableAssignments_AreAlignedSeparately()
4545
{
4646
$code = <<<'CODE'
4747
<?php
@@ -73,10 +73,10 @@ public function testMixedKindVariableAssignmentsAreAlignedSeparately()
7373

7474
CODE;
7575

76-
$this->assertSame($expected, $this->runner->fix($code));
76+
$this->assertFixed($code, $expected);
7777
}
7878

79-
public function testMultilineAssignmentIsNotAligned()
79+
public function test_MultilineAssignment_IsNotAligned()
8080
{
8181
$code = <<<'CODE'
8282
<?php
@@ -89,7 +89,7 @@ public function testMultilineAssignmentIsNotAligned()
8989

9090
CODE;
9191

92-
$this->assertSame($code, $this->runner->fix($code));
92+
$this->assertUnchanged($code);
9393
}
9494

9595
protected function fixer(): FixerInterface

tests/Fixer/AlignedMethodChainFixerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class AlignedMethodChainFixerTest extends FixerTest
1919
{
20-
public function testSingleLineChainCallsAreNotChanged()
20+
public function test_SingleLineChainCalls_AreNotChanged()
2121
{
2222
$code = <<<'CODE'
2323
<?php
@@ -27,10 +27,10 @@ public function testSingleLineChainCallsAreNotChanged()
2727

2828
CODE;
2929

30-
$this->assertSame($code, $this->runner->fix($code));
30+
$this->assertUnchanged($code);
3131
}
3232

33-
public function testLineBreakChainCallsAreExpandedAndAligned()
33+
public function test_LineBreakChainCalls_AreExpandedAndAligned()
3434
{
3535
$code = <<<'CODE'
3636
<?php
@@ -53,10 +53,10 @@ public function testLineBreakChainCallsAreExpandedAndAligned()
5353

5454
CODE;
5555

56-
$this->assertSame($expected, $this->runner->fix($code));
56+
$this->assertFixed($code, $expected);
5757
}
5858

59-
public function testNestedMultilineChainsAreAligned()
59+
public function test_NestedMultilineChains_AreAligned()
6060
{
6161
$code = <<<'CODE'
6262
<?php
@@ -80,10 +80,10 @@ public function testNestedMultilineChainsAreAligned()
8080

8181
CODE;
8282

83-
$this->assertSame($expected, $this->runner->fix($code));
83+
$this->assertFixed($code, $expected);
8484
}
8585

86-
public function testCodeWithoutObjectOperatorIsSkipped()
86+
public function test_CodeWithoutObjectOperator_IsSkipped()
8787
{
8888
$code = <<<'CODE'
8989
<?php
@@ -92,7 +92,7 @@ public function testCodeWithoutObjectOperatorIsSkipped()
9292

9393
CODE;
9494

95-
$this->assertSame($code, $this->runner->fix($code));
95+
$this->assertUnchanged($code);
9696
}
9797

9898
protected function fixer(): AlignedMethodChainFixer

tests/Fixer/AlignedTypedPropertiesFixerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class AlignedTypedPropertiesFixerTest extends FixerTest
2020
{
21-
public function testPropertiesAreAligned()
21+
public function test_Properties_AreAligned()
2222
{
2323
$code = <<<'CODE'
2424
<?php
@@ -88,7 +88,7 @@ public function __construct(ExampleClass $self)
8888

8989
CODE;
9090

91-
$this->assertSame($expected, $this->runner->fix($code));
91+
$this->assertFixed($code, $expected);
9292
}
9393

9494
protected function fixer(): FixerInterface

tests/Fixer/BraceAfterFunctionFixerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class BraceAfterFunctionFixerTest extends FixerTest
1919
{
20-
public function testFunctionBracesFromNextLineAreMoved()
20+
public function test_FunctionBracesFromNextLine_AreMoved()
2121
{
2222
$code = <<<'CODE'
2323
<?php
@@ -38,10 +38,10 @@ function withSomething(Test $value) {
3838

3939
CODE;
4040

41-
$this->assertSame($expected, $this->runner->fix($code));
41+
$this->assertFixed($code, $expected);
4242
}
4343

44-
public function testMethodBracesFromNextLineAreMoved()
44+
public function test_MethodBracesFromNextLine_AreMoved()
4545
{
4646
$code = <<<'CODE'
4747
<?php
@@ -66,10 +66,10 @@ public function withSomething(string $value): Type {
6666

6767
CODE;
6868

69-
$this->assertSame($expected, $this->runner->fix($code));
69+
$this->assertFixed($code, $expected);
7070
}
7171

72-
public function testUnusualMethodFormattingIsFixed()
72+
public function test_UnusualMethodFormatting_IsFixed()
7373
{
7474
$code = <<<'CODE'
7575
<?php
@@ -102,7 +102,7 @@ public function GetType(string $value):Type {
102102

103103
CODE;
104104

105-
$this->assertSame($expected, $this->runner->fix($code));
105+
$this->assertFixed($code, $expected);
106106
}
107107

108108
protected function fixer(): BraceAfterFunctionFixer

tests/Fixer/BraceAfterMultilineParamMethodFixerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class BraceAfterMultilineParamMethodFixerTest extends FixerTest
1919
{
20-
public function testSingleLineDefinition_BraceFromNextLine_IsNotChanged()
20+
public function test_SingleLineDefinition_BraceFromNextLine_IsNotChanged()
2121
{
2222
$code = $this->wrap(<<<'CODE'
2323
@@ -28,10 +28,10 @@ public function withSomething(string $value, array $another): Type
2828

2929
CODE);
3030

31-
$this->assertSame($code, $this->runner->fix($code));
31+
$this->assertUnchanged($code);
3232
}
3333

34-
public function testMultilineDefinition_BraceFromNextLine_IsFixed()
34+
public function test_MultilineDefinition_BraceFromNextLine_IsFixed()
3535
{
3636
$code = $this->wrap(<<<'CODE'
3737
@@ -56,10 +56,10 @@ public function withSomething(
5656

5757
CODE, 'trait');
5858

59-
$this->assertSame($expected, $this->runner->fix($code));
59+
$this->assertFixed($code, $expected);
6060
}
6161

62-
public function testMultilineDefinition_MissingWhitespace_IsFixed()
62+
public function test_MultilineDefinition_MissingWhitespace_IsFixed()
6363
{
6464
$code = $this->wrap(<<<'CODE'
6565
@@ -83,10 +83,10 @@ public function withSomething(
8383

8484
CODE);
8585

86-
$this->assertSame($expected, $this->runner->fix($code));
86+
$this->assertFixed($code, $expected);
8787
}
8888

89-
public function testAbstractMultilineDefinition_DoesNotAffectNextMethod()
89+
public function test_AbstractMultilineDefinition_DoesNotAffectNextMethod()
9090
{
9191
$code = $this->wrap(<<<'CODE'
9292
@@ -102,7 +102,7 @@ public function withSomething(string $value): Type
102102

103103
CODE);
104104

105-
$this->assertSame($code, $this->runner->fix($code));
105+
$this->assertUnchanged($code);
106106
}
107107

108108
protected function fixer(): BraceAfterMultilineParamMethodFixer

tests/Fixer/DeclareStrictFirstLineFixerTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class DeclareStrictFirstLineFixerTest extends FixerTest
2020
{
21-
public function testFileWithoutDeclareIsUnchanged()
21+
public function test_FileWithoutDeclare_IsUnchanged()
2222
{
2323
$code = <<<'CODE'
2424
<?php
@@ -27,10 +27,10 @@ public function testFileWithoutDeclareIsUnchanged()
2727

2828
CODE;
2929

30-
$this->assertSame($code, $this->runner->fix($code));
30+
$this->assertUnchanged($code);
3131
}
3232

33-
public function testFileWithDeclareInFirstLineIsUnchanged()
33+
public function test_FileWithDeclareInFirstLine_IsUnchanged()
3434
{
3535
$code = <<<'CODE'
3636
<?php declare(strict_types=1);
@@ -39,10 +39,10 @@ public function testFileWithDeclareInFirstLineIsUnchanged()
3939

4040
CODE;
4141

42-
$this->assertSame($code, $this->runner->fix($code));
42+
$this->assertUnchanged($code);
4343
}
4444

45-
public function testFileWithDifferentDeclareIsUnchanged()
45+
public function test_FileWithDifferentDeclare_IsUnchanged()
4646
{
4747
$code = <<<'CODE'
4848
<?php
@@ -52,10 +52,10 @@ public function testFileWithDifferentDeclareIsUnchanged()
5252

5353
CODE;
5454

55-
$this->assertSame($code, $this->runner->fix($code));
55+
$this->assertUnchanged($code);
5656
}
5757

58-
public function testDeclareNotInFirstLineIsMoved()
58+
public function test_DeclareNotInFirstLine_IsMoved()
5959
{
6060
$code = <<<'CODE'
6161
<?php
@@ -72,10 +72,10 @@ public function testDeclareNotInFirstLineIsMoved()
7272

7373
CODE;
7474

75-
$this->assertSame($expected, $this->runner->fix($code));
75+
$this->assertFixed($code, $expected);
7676
}
7777

78-
public function testDeclareNotInFirstLineIsMovedWIthFollowingWhitespace()
78+
public function test_DeclareNotInFirstLine_IsMovedWIthFollowingWhitespace()
7979
{
8080
$code = <<<'CODE'
8181
<?php
@@ -95,7 +95,7 @@ public function testDeclareNotInFirstLineIsMovedWIthFollowingWhitespace()
9595

9696
CODE;
9797

98-
$this->assertSame($expected, $this->runner->fix($code));
98+
$this->assertFixed($code, $expected);
9999
}
100100

101101
protected function fixer(): FixerInterface

0 commit comments

Comments
 (0)