NamespaceDeclarationSniffTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 46
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDetection() 0 17 1
A testFixing() 0 22 1
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