Skip to content

Commit 28585f1

Browse files
committed
test: move tests to appropriate suites
1 parent add07cb commit 28585f1

4 files changed

Lines changed: 88 additions & 80 deletions

File tree

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

33
declare(strict_types=1);
44

5-
namespace DocbookCS\Tests\Unit;
5+
namespace DocbookCS\Tests\Feature;
66

77
use DocbookCS\Application;
88
use DocbookCS\Config\ConfigData;
@@ -112,7 +112,7 @@ private function readStream(mixed $stream): string
112112
return stream_get_contents($stream) ?: '';
113113
}
114114

115-
#[Test] // TODO: should be feature
115+
#[Test]
116116
public function itPrintsHelpAndExitsWithZero(): void
117117
{
118118
$app = new Application(['docbook-cs', '--help'], $this->stdout, $this->stderr);
@@ -124,7 +124,7 @@ public function itPrintsHelpAndExitsWithZero(): void
124124
self::assertSame('', $this->readStream($this->stderr));
125125
}
126126

127-
#[Test] // TODO: should be feature
127+
#[Test]
128128
public function itPrintsVersionAndExitsWithZero(): void
129129
{
130130
$app = new Application(['docbook-cs', '--version'], $this->stdout, $this->stderr);
@@ -136,7 +136,7 @@ public function itPrintsVersionAndExitsWithZero(): void
136136
self::assertSame('', $this->readStream($this->stderr));
137137
}
138138

139-
#[Test] // TODO: should be feature
139+
#[Test]
140140
public function itReturnsErrorWhenConfigCannotBeLoaded(): void
141141
{
142142
$app = new Application(
@@ -151,7 +151,7 @@ public function itReturnsErrorWhenConfigCannotBeLoaded(): void
151151
self::assertStringContainsString('Error:', $this->readStream($this->stderr));
152152
}
153153

154-
#[Test] // TODO: should be feature
154+
#[Test]
155155
public function itHandlesSeparateConfigArgument(): void
156156
{
157157
$app = new Application(
@@ -166,7 +166,7 @@ public function itHandlesSeparateConfigArgument(): void
166166
self::assertStringContainsString('Error:', $this->readStream($this->stderr));
167167
}
168168

169-
#[Test] // TODO: should be feature
169+
#[Test]
170170
public function itAcceptsPathsWithoutCrashing(): void
171171
{
172172
$app = new Application(
@@ -180,7 +180,7 @@ public function itAcceptsPathsWithoutCrashing(): void
180180
self::assertContains($exitCode, [0, 1, 2]);
181181
}
182182

183-
#[Test] // TODO: should be feature
183+
#[Test]
184184
public function itSupportsQuietFlag(): void
185185
{
186186
$app = new Application(['docbook-cs', '--quiet'], $this->stdout, $this->stderr);
@@ -190,7 +190,7 @@ public function itSupportsQuietFlag(): void
190190
self::assertContains($exitCode, [0, 1, 2]);
191191
}
192192

193-
#[Test] // TODO: should be feature
193+
#[Test]
194194
public function itSupportsReportFormats(): void
195195
{
196196
foreach (['console', 'json', 'checkstyle'] as $format) {
@@ -206,7 +206,7 @@ public function itSupportsReportFormats(): void
206206
}
207207
}
208208

209-
#[Test] // TODO: should be feature
209+
#[Test]
210210
public function itSupportsColorFlags(): void
211211
{
212212
foreach (['--colors', '--no-colors'] as $flag) {
@@ -222,7 +222,7 @@ public function itSupportsColorFlags(): void
222222
}
223223
}
224224

225-
#[Test] // TODO: should be feature
225+
#[Test]
226226
public function helpShortCircuitsExecution(): void
227227
{
228228
$app = new Application(
@@ -238,7 +238,7 @@ public function helpShortCircuitsExecution(): void
238238
self::assertSame('', $this->readStream($this->stderr));
239239
}
240240

241-
#[Test] // TODO: should be feature
241+
#[Test]
242242
public function versionShortCircuitsExecution(): void
243243
{
244244
$app = new Application(
@@ -254,7 +254,7 @@ public function versionShortCircuitsExecution(): void
254254
self::assertSame('', $this->readStream($this->stderr));
255255
}
256256

257-
#[Test] // TODO: should be feature
257+
#[Test]
258258
public function itResolvesRelativeOverridePathsAgainstCwd(): void
259259
{
260260
$app = new Application(
@@ -270,7 +270,7 @@ public function itResolvesRelativeOverridePathsAgainstCwd(): void
270270
self::assertNotSame(2, $exitCode);
271271
}
272272

273-
#[Test] // TODO: should be feature
273+
#[Test]
274274
public function itCatchesRuntimeErrorFromRunner(): void
275275
{
276276
$app = new Application(
@@ -285,7 +285,7 @@ public function itCatchesRuntimeErrorFromRunner(): void
285285
self::assertStringContainsString('Runtime error:', $this->readStream($this->stderr));
286286
}
287287

288-
#[Test] // TODO: should be feature
288+
#[Test]
289289
public function itSupportsSeparateReportArgument(): void
290290
{
291291
$app = new Application(
@@ -299,7 +299,7 @@ public function itSupportsSeparateReportArgument(): void
299299
self::assertContains($exitCode, [0, 1, 2]);
300300
}
301301

302-
#[Test] // TODO: should be feature
302+
#[Test]
303303
public function itPassesThroughAbsoluteOverridePaths(): void
304304
{
305305
$app = new Application(
@@ -313,7 +313,7 @@ public function itPassesThroughAbsoluteOverridePaths(): void
313313
self::assertNotSame(2, $exitCode);
314314
}
315315

316-
#[Test] // TODO: should be feature
316+
#[Test]
317317
public function itSuppressesProgressWhenQuietFlagIsSet(): void
318318
{
319319
$app = new Application(
@@ -328,7 +328,7 @@ public function itSuppressesProgressWhenQuietFlagIsSet(): void
328328
self::assertSame('', $this->readStream($this->stderr));
329329
}
330330

331-
#[Test] // TODO: should be feature
331+
#[Test]
332332
public function itSuppressesProgressForStructuredReportFormats(): void
333333
{
334334
foreach (['json', 'checkstyle'] as $format) {
@@ -351,7 +351,7 @@ public function itSuppressesProgressForStructuredReportFormats(): void
351351
}
352352
}
353353

354-
#[Test] // TODO: should be feature
354+
#[Test]
355355
public function itShowsPerformanceWhenPerfFlagIsEnabled(): void
356356
{
357357
$app = new Application(
@@ -374,7 +374,7 @@ public function itShowsPerformanceWhenPerfFlagIsEnabled(): void
374374
self::assertStringContainsString('PERFORMANCE', $output);
375375
}
376376

377-
#[Test] // TODO: should be feature
377+
#[Test]
378378
public function itDoesNotShowPerformanceByDefault(): void
379379
{
380380
$app = new Application(

tests/Unit/Runner/SniffRunnerTest.php renamed to tests/Integration/Runner/SniffRunnerTest.php

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

33
declare(strict_types=1);
44

5-
namespace DocbookCS\Tests\Unit\Runner;
5+
namespace DocbookCS\Tests\Integration\Runner;
66

77
use DocbookCS\Config\ConfigData;
88
use DocbookCS\Config\SniffEntry;
@@ -86,7 +86,7 @@ private function createConfig(array $sniffs = []): ConfigData
8686
);
8787
}
8888

89-
#[Test] // TODO: should be integration
89+
#[Test]
9090
public function itProcessesFilesWithoutViolations(): void
9191
{
9292
$config = $this->createConfig();
@@ -99,7 +99,7 @@ public function itProcessesFilesWithoutViolations(): void
9999
self::assertCount(0, $report->getFileReports());
100100
}
101101

102-
#[Test] // TODO: should be integration
102+
#[Test]
103103
public function itUsesOverridePathsWhenProvided(): void
104104
{
105105
$config = $this->createConfig();
@@ -113,7 +113,7 @@ public function itUsesOverridePathsWhenProvided(): void
113113
self::assertSame(1, $report->getFilesScanned());
114114
}
115115

116-
#[Test] // TODO: should be integration
116+
#[Test]
117117
public function itCallsProgressMethods(): void
118118
{
119119
$progress = $this->createMock(ProgressInterface::class);
@@ -134,7 +134,7 @@ public function itCallsProgressMethods(): void
134134
$runner->run($this->planPaths($config));
135135
}
136136

137-
#[Test] // TODO: should be integration
137+
#[Test]
138138
public function itAddsFileReportsForFilesWithViolations(): void
139139
{
140140
$sniff = new class (RunMode::Sniff) implements SniffInterface {
@@ -177,7 +177,7 @@ public function setProperty(string $name, string $value): void
177177
self::assertTrue($report->hasViolations());
178178
}
179179

180-
#[Test] // TODO: should be integration
180+
#[Test]
181181
public function itStoresAbsolutePathsInFileReports(): void
182182
{
183183
$sniff = new class (RunMode::Sniff) implements SniffInterface {
@@ -223,7 +223,7 @@ public function setProperty(string $name, string $value): void
223223
}
224224
}
225225

226-
#[Test] // TODO: should be integration
226+
#[Test]
227227
public function itPassesPropertiesToSniffs(): void
228228
{
229229
$sniffClass = new class (RunMode::Sniff) implements SniffInterface {
@@ -260,7 +260,7 @@ public function process(\DOMDocument $document, File $file): array
260260
self::assertSame(RunMode::Fix, $sniffClass::$capturedMode);
261261
}
262262

263-
#[Test] // TODO: should be integration
263+
#[Test]
264264
public function itThrowsWhenSniffClassDoesNotExist(): void
265265
{
266266
$config = $this->createConfig(sniffs: [new SniffEntry('NonExistent\\FakeSniff')]);
@@ -273,7 +273,7 @@ public function itThrowsWhenSniffClassDoesNotExist(): void
273273
$runner->run($this->planPaths($config));
274274
}
275275

276-
#[Test] // TODO: should be integration
276+
#[Test]
277277
public function itThrowsWhenClassDoesNotImplementSniffInterface(): void
278278
{
279279
$config = $this->createConfig(sniffs: [new SniffEntry(\stdClass::class)]);
@@ -286,7 +286,7 @@ public function itThrowsWhenClassDoesNotImplementSniffInterface(): void
286286
$runner->run($this->planPaths($config));
287287
}
288288

289-
#[Test] // TODO: should be integration
289+
#[Test]
290290
public function itFiltersFilesToOnlyThoseInTheDiff(): void
291291
{
292292
$config = $this->createConfig();
@@ -298,7 +298,7 @@ public function itFiltersFilesToOnlyThoseInTheDiff(): void
298298
self::assertSame(1, $report->getFilesScanned());
299299
}
300300

301-
#[Test] // TODO: should be integration
301+
#[Test]
302302
public function itScansNoFilesWhenDiffContainsNoMatchingPaths(): void
303303
{
304304
$config = $this->createConfig();
@@ -310,7 +310,7 @@ public function itScansNoFilesWhenDiffContainsNoMatchingPaths(): void
310310
self::assertSame(0, $report->getFilesScanned());
311311
}
312312

313-
#[Test] // TODO: should be integration
313+
#[Test]
314314
public function itMatchesWhenDiffPathEqualsDiscoveredPath(): void
315315
{
316316
$config = $this->createConfig();
@@ -324,7 +324,7 @@ public function itMatchesWhenDiffPathEqualsDiscoveredPath(): void
324324
self::assertSame(1, $report->getFilesScanned());
325325
}
326326

327-
#[Test] // TODO: should be integration
327+
#[Test]
328328
public function itScansAllFilesWhenNoDiffIsGiven(): void
329329
{
330330
$config = $this->createConfig();
@@ -335,7 +335,7 @@ public function itScansAllFilesWhenNoDiffIsGiven(): void
335335
self::assertSame(2, $report->getFilesScanned());
336336
}
337337

338-
#[Test] // TODO: should be integration
338+
#[Test]
339339
public function itScansLexicallyEquivalentWideTargetsOnlyOnce(): void
340340
{
341341
$directory = sys_get_temp_dir() . '/docbook-cs-scan-' . bin2hex(random_bytes(6));
@@ -380,7 +380,7 @@ public function itScansLexicallyEquivalentWideTargetsOnlyOnce(): void
380380
}
381381
}
382382

383-
#[Test] // TODO: should be integration
383+
#[Test]
384384
public function itReportsNoViolationsForFilesInDiffWithoutAddedLines(): void
385385
{
386386
$sniff = new class (RunMode::Sniff) implements SniffInterface {

tests/Integration/Runner/XmlFileProcessorPipelineTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,52 @@ public function itAppliesFixesToTheOriginalSourceWhenEntitiesExpandBeforeTheViol
7272
}
7373
}
7474

75+
#[Test]
76+
public function itHandlesEntitiesWithoutParseErrors(): void
77+
{
78+
$xml = $this->xml(
79+
'<!DOCTYPE chapter SYSTEM "docbook.dtd">
80+
<chapter>
81+
<simpara>&link.superglobals; &php.ini; &amp;</simpara>
82+
</chapter>'
83+
);
84+
85+
$processor = $this->processor([], new EntityPreprocessor([
86+
'link.superglobals' => '',
87+
'php.ini' => '',
88+
]));
89+
90+
$report = $this->process($processor, $xml);
91+
92+
self::assertCount(
93+
0,
94+
array_filter(
95+
$report->getViolations(),
96+
fn($v) => $v->sniffCode === 'DocbookCS.Internal'
97+
)
98+
);
99+
}
100+
101+
#[Test]
102+
public function itUsesCustomPreprocessor(): void
103+
{
104+
$processor = $this->processor([], new EntityPreprocessor([
105+
'custom.entity' => '[X]',
106+
]));
107+
108+
$xml = $this->xml('<chapter><simpara>&custom.entity;</simpara></chapter>');
109+
110+
$report = $this->process($processor, $xml);
111+
112+
self::assertCount(
113+
0,
114+
array_filter(
115+
$report->getViolations(),
116+
fn($v) => $v->sniffCode === 'DocbookCS.Internal'
117+
)
118+
);
119+
}
120+
75121
private function process(XmlFileProcessor $processor, string $content, string $path = 'input.xml'): FileReport
76122
{
77123
return $processor->process(new File($path, $content))->fileReport;
@@ -90,6 +136,14 @@ private function processFile(XmlFileProcessor $processor, string $path): FileRep
90136
return $result->fileReport;
91137
}
92138

139+
private function xml(string $body): string
140+
{
141+
return <<<XML
142+
<?xml version="1.0" encoding="UTF-8"?>
143+
$body
144+
XML;
145+
}
146+
93147
/** @param list<SniffInterface> $sniffs */
94148
private function processor(array $sniffs = [], ?EntityPreprocessor $pre = null): XmlFileProcessor
95149
{

0 commit comments

Comments
 (0)