-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsFixerConfigGeneratorTest.php
More file actions
97 lines (83 loc) · 2.88 KB
/
CsFixerConfigGeneratorTest.php
File metadata and controls
97 lines (83 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace KaririCode\Devkit\Tests\Unit\Configuration;
use KaririCode\Devkit\Configuration\CsFixerConfigGenerator;
use KaririCode\Devkit\Core\ProjectContext;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(CsFixerConfigGenerator::class)]
final class CsFixerConfigGeneratorTest extends TestCase
{
private CsFixerConfigGenerator $generator;
protected function setUp(): void
{
$this->generator = new CsFixerConfigGenerator();
}
private function makeContext(array $rules = ['@PSR12' => true]): ProjectContext
{
return new ProjectContext(
projectRoot: '/project',
projectName: 'test/project',
namespace: 'Test\\Project',
phpVersion: '8.4',
phpstanLevel: 9,
psalmLevel: 3,
sourceDirs: ['/project/src'],
testDirs: ['/project/tests'],
excludeDirs: [],
testSuites: [],
coverageExclude: [],
csFixerRules: $rules,
rectorSets: [],
toolVersions: [],
);
}
#[Test]
public function toolNameReturnsCsFixer(): void
{
$this->assertSame('cs-fixer', $this->generator->toolName());
}
#[Test]
public function outputPathReturnsPhpCsFixerPhp(): void
{
$this->assertSame('php-cs-fixer.php', $this->generator->outputPath());
}
#[Test]
public function generateContainsPhpDeclaration(): void
{
$output = $this->generator->generate($this->makeContext());
$this->assertStringContainsString('<?php', $output);
}
#[Test]
public function generateContainsSourceDir(): void
{
$output = $this->generator->generate($this->makeContext());
$this->assertStringContainsString("->in(__DIR__ . '/../src')", $output);
}
#[Test]
public function generateContainsTestDir(): void
{
$output = $this->generator->generate($this->makeContext());
$this->assertStringContainsString("->in(__DIR__ . '/../tests')", $output);
}
#[Test]
public function generateContainsRulesFromContext(): void
{
$output = $this->generator->generate($this->makeContext(['@PSR12' => true, 'array_syntax' => ['syntax' => 'short']]));
$this->assertStringContainsString('@PSR12', $output);
$this->assertStringContainsString('array_syntax', $output);
}
#[Test]
public function generateContainsCacheFile(): void
{
$output = $this->generator->generate($this->makeContext());
$this->assertStringContainsString('.php-cs-fixer.cache', $output);
}
#[Test]
public function generateContainsRiskyAllowed(): void
{
$output = $this->generator->generate($this->makeContext());
$this->assertStringContainsString('setRiskyAllowed(true)', $output);
}
}