Skip to content

Commit deb4952

Browse files
authored
Move tests to appropriate suites (#38)
1 parent 41cf604 commit deb4952

2 files changed

Lines changed: 54 additions & 46 deletions

File tree

tests/Unit/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] // TODO: should be integration
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] // TODO: should be integration
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
{

tests/Unit/Runner/XmlFileProcessorTest.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,52 +87,6 @@ public function itAcceptsValidXmlWithoutViolations(): void
8787
self::assertFalse($report->hasViolations());
8888
}
8989

90-
#[Test] // TODO: should be integration
91-
public function itHandlesEntitiesWithoutParseErrors(): void
92-
{
93-
$xml = $this->xml(
94-
'<!DOCTYPE chapter SYSTEM "docbook.dtd">
95-
<chapter>
96-
<simpara>&link.superglobals; &php.ini; &amp;</simpara>
97-
</chapter>'
98-
);
99-
100-
$processor = $this->processor([], new EntityPreprocessor([
101-
'link.superglobals' => '',
102-
'php.ini' => '',
103-
]));
104-
105-
$report = $this->process($processor, $xml);
106-
107-
self::assertCount(
108-
0,
109-
array_filter(
110-
$report->getViolations(),
111-
fn($v) => $v->sniffCode === 'DocbookCS.Internal'
112-
)
113-
);
114-
}
115-
116-
#[Test] // TODO: should be integration
117-
public function itUsesCustomPreprocessor(): void
118-
{
119-
$processor = $this->processor([], new EntityPreprocessor([
120-
'custom.entity' => '[X]',
121-
]));
122-
123-
$xml = $this->xml('<chapter><simpara>&custom.entity;</simpara></chapter>');
124-
125-
$report = $this->process($processor, $xml);
126-
127-
self::assertCount(
128-
0,
129-
array_filter(
130-
$report->getViolations(),
131-
fn($v) => $v->sniffCode === 'DocbookCS.Internal'
132-
)
133-
);
134-
}
135-
13690
#[Test]
13791
public function itReturnsZeroViolationsWithoutSniffs(): void
13892
{

0 commit comments

Comments
 (0)