Skip to content

Commit 0012151

Browse files
committed
Cleanup
1 parent a9af14f commit 0012151

File tree

6 files changed

+109
-247
lines changed

6 files changed

+109
-247
lines changed

SlevomatCodingStandard/Sniffs/TestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected static function assertAllFixedInFile(File $phpcsFile): void
122122
self::assertStringEqualsFile(preg_replace('~(\\.php)$~', '.fixed\\1', $phpcsFile->getFilename()), $phpcsFile->fixer->getContents());
123123
}
124124

125-
protected static function getSniffName(): string
125+
private static function getSniffName(): string
126126
{
127127
return preg_replace(
128128
[
@@ -139,12 +139,12 @@ protected static function getSniffName(): string
139139
);
140140
}
141141

142-
protected static function getSniffClassName(): string
142+
private static function getSniffClassName(): string
143143
{
144144
return substr(static::class, 0, -strlen('Test'));
145145
}
146146

147-
protected static function getSniffClassReflection(): ReflectionClass
147+
private static function getSniffClassReflection(): ReflectionClass
148148
{
149149
static $reflections = [];
150150

tests/Sniffs/Namespaces/FullyQualifiedExceptionsSniffTest.php

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,40 @@
22

33
namespace SlevomatCodingStandard\Sniffs\Namespaces;
44

5-
use PHP_CodeSniffer\Files\File;
65
use SlevomatCodingStandard\Sniffs\TestCase;
76
use Throwable;
87
use TypeError;
98

109
class FullyQualifiedExceptionsSniffTest extends TestCase
1110
{
1211

13-
public function testNonFullyQualifiedExceptionInTypeHint(): void
12+
public function test(): void
1413
{
15-
self::assertSniffError(
16-
$this->getFileReport(),
17-
3,
18-
FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION,
19-
'FooException'
20-
);
21-
}
14+
$report = self::checkFile(__DIR__ . '/data/fullyQualifiedExceptionNames.php');
2215

23-
public function testNonFullyQualifiedExceptionInThrow(): void
24-
{
25-
self::assertSniffError(
26-
$this->getFileReport(),
27-
6,
28-
FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION,
29-
'FooException'
30-
);
31-
}
16+
// Not fully qualified exception in type hint
17+
self::assertSniffError($report, 3, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, 'FooException');
3218

33-
public function testNonFullyQualifiedExceptionInCatch(): void
34-
{
35-
self::assertSniffError(
36-
$this->getFileReport(),
37-
7,
38-
FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION,
39-
'BarException'
40-
);
41-
self::assertSniffError(
42-
$this->getFileReport(),
43-
9,
44-
FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION,
45-
Throwable::class
46-
);
47-
self::assertSniffError(
48-
$this->getFileReport(),
49-
11,
50-
FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION,
51-
TypeError::class
52-
);
53-
}
19+
// Not fully qualified exception in throw
20+
self::assertSniffError($report, 6, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, 'FooException');
5421

55-
public function testFullyQualifiedExceptionInTypeHint(): void
56-
{
57-
self::assertNoSniffError($this->getFileReport(), 16);
58-
}
22+
// Not fully qualified exception in catch
23+
self::assertSniffError($report, 7, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, 'BarException');
24+
self::assertSniffError($report, 9, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, Throwable::class);
25+
self::assertSniffError($report, 11, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, TypeError::class);
5926

60-
public function testFullyQualifiedExceptionInThrow(): void
61-
{
62-
self::assertNoSniffError($this->getFileReport(), 19);
63-
}
27+
// Fully qualified exception in type hint
28+
self::assertNoSniffError($report, 16);
6429

65-
public function testFullyQualifiedExceptionInCatch(): void
66-
{
67-
self::assertNoSniffError($this->getFileReport(), 20);
68-
self::assertNoSniffError($this->getFileReport(), 22);
69-
self::assertNoSniffError($this->getFileReport(), 24);
70-
self::assertNoSniffError($this->getFileReport(), 26);
71-
self::assertNoSniffError($this->getFileReport(), 28);
30+
// Fully qualified exception in throw
31+
self::assertNoSniffError($report, 19);
32+
33+
// Fully qualified exception in catch
34+
self::assertNoSniffError($report, 20);
35+
self::assertNoSniffError($report, 22);
36+
self::assertNoSniffError($report, 24);
37+
self::assertNoSniffError($report, 26);
38+
self::assertNoSniffError($report, 28);
7239
}
7340

7441
public function testClassSuffixedErrorOrExceptionIsNotAnExceptionButReported(): void
@@ -117,9 +84,32 @@ public function testFixableFullyQualified(): void
11784
self::assertAllFixedInFile($report);
11885
}
11986

120-
private function getFileReport(): File
87+
public function testWithSpecialExceptionNames(): void
12188
{
122-
return self::checkFile(__DIR__ . '/data/fullyQualifiedExceptionNames.php');
89+
$report = self::checkFile(
90+
__DIR__ . '/data/fullyQualifiedSpecialExceptionNames.php',
91+
[
92+
'specialExceptionNames' => [
93+
'Foo\SomeError',
94+
'Lorem\Ipsum\SomeOtherError',
95+
],
96+
]
97+
);
98+
99+
// Throwing used exception
100+
self::assertSniffError($report, 12, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, 'FooError');
101+
102+
// Catching partially used exception
103+
self::assertSniffError($report, 13, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, 'Foo\SomeException');
104+
105+
// Throwing exception from same namespace
106+
self::assertSniffError($report, 18, FullyQualifiedExceptionsSniff::CODE_NON_FULLY_QUALIFIED_EXCEPTION, 'SomeOtherError');
107+
108+
// Catching fully qualified exception
109+
self::assertNoSniffError($report, 15);
110+
111+
// Catching fully qualified exception from same namespace
112+
self::assertNoSniffError($report, 17);
123113
}
124114

125115
}

tests/Sniffs/Namespaces/FullyQualifiedExceptionsSniffWithSpecialNamesTest.php

Lines changed: 0 additions & 69 deletions
This file was deleted.

tests/Sniffs/Namespaces/MultipleUsesPerLineSniffTest.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,19 @@
22

33
namespace SlevomatCodingStandard\Sniffs\Namespaces;
44

5-
use PHP_CodeSniffer\Files\File;
65
use SlevomatCodingStandard\Sniffs\TestCase;
76

87
class MultipleUsesPerLineSniffTest extends TestCase
98
{
109

1110
public function testMultipleUsesPerLine(): void
1211
{
13-
self::assertSniffError(
14-
$this->getFileReport(),
15-
5,
16-
MultipleUsesPerLineSniff::CODE_MULTIPLE_USES_PER_LINE
17-
);
18-
}
12+
$report = self::checkFile(__DIR__ . '/data/multipleUsesPerLine.php');
1913

20-
public function testIgnoreCommasInClosureUse(): void
21-
{
22-
self::assertNoSniffError($this->getFileReport(), 7);
23-
}
14+
self::assertSniffError($report, 5, MultipleUsesPerLineSniff::CODE_MULTIPLE_USES_PER_LINE);
2415

25-
private function getFileReport(): File
26-
{
27-
return self::checkFile(__DIR__ . '/data/multipleUsesPerLine.php');
16+
// Ignore commas in closure use
17+
self::assertNoSniffError($report, 7);
2818
}
2919

3020
}

0 commit comments

Comments
 (0)