|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Zenify\CodingStandard\Tests\Sniffs\Namespaces\NamespaceDeclaration; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Zenify\CodingStandard\Tests\CodeSnifferRunner; |
|
9
|
|
|
use ZenifyCodingStandard\Sniffs\Namespaces\NamespaceDeclarationSniff; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
final class NamespaceDeclarationSniffTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
public function testDetection() |
|
16
|
|
|
{ |
|
17
|
|
|
$codeSnifferRunner = new CodeSnifferRunner(NamespaceDeclarationSniff::NAME); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertSame(1, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong.php')); |
|
20
|
|
|
$this->assertSame(1, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong2.php')); |
|
21
|
|
|
$this->assertSame(1, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/wrong3.php')); |
|
22
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct.php')); |
|
23
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct2.php')); |
|
24
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct3.php')); |
|
25
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct4.php')); |
|
26
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct5.php')); |
|
27
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct6.php')); |
|
28
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct7.php')); |
|
29
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct8.php')); |
|
30
|
|
|
$this->assertSame(0, $codeSnifferRunner->getErrorCountInFile(__DIR__ . '/correct9.php')); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function testFixing() |
|
35
|
|
|
{ |
|
36
|
|
|
$codeSnifferRunner = new CodeSnifferRunner(NamespaceDeclarationSniff::NAME); |
|
37
|
|
|
|
|
38
|
|
|
$fixedContent = $codeSnifferRunner->getFixedContent(__DIR__ . '/wrong.php'); |
|
39
|
|
|
$this->assertSame(file_get_contents(__DIR__ . '/wrong-fixed.php'), $fixedContent); |
|
40
|
|
|
|
|
41
|
|
|
$fixedContent = $codeSnifferRunner->getFixedContent(__DIR__ . '/wrong2.php'); |
|
42
|
|
|
$this->assertSame(file_get_contents(__DIR__ . '/wrong-fixed.php'), $fixedContent); |
|
43
|
|
|
|
|
44
|
|
|
$fixedContent = $codeSnifferRunner->getFixedContent(__DIR__ . '/wrong3.php'); |
|
45
|
|
|
$this->assertSame(file_get_contents(__DIR__ . '/wrong3-fixed.php'), $fixedContent); |
|
46
|
|
|
|
|
47
|
|
|
$fixedContent = $codeSnifferRunner->getFixedContent(__DIR__ . '/wrong4.php'); |
|
48
|
|
|
$this->assertSame(file_get_contents(__DIR__ . '/wrong3-fixed.php'), $fixedContent); |
|
49
|
|
|
|
|
50
|
|
|
$fixedContent = $codeSnifferRunner->getFixedContent(__DIR__ . '/wrong5.php'); |
|
51
|
|
|
$this->assertSame(file_get_contents(__DIR__ . '/wrong5-fixed.php'), $fixedContent); |
|
52
|
|
|
|
|
53
|
|
|
$fixedContent = $codeSnifferRunner->getFixedContent(__DIR__ . '/wrong6.php'); |
|
54
|
|
|
$this->assertSame(file_get_contents(__DIR__ . '/wrong6-fixed.php'), $fixedContent); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|