Skip to content

Commit cd440c1

Browse files
committed
[TASK] Add tests for invalid guides.xml error handling
Adds integration tests that verify: - Invalid guides.xml shows helpful error message instead of PHP Fatal error - XSD validation error includes line number - Valid guides.xml files still render successfully
1 parent bb9a162 commit cd440c1

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace T3Docs\Typo3DocsTheme\Integration;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Process\Process;
9+
10+
/**
11+
* Tests error handling for invalid guides.xml configurations.
12+
*/
13+
final class InvalidGuidesXmlTest extends TestCase
14+
{
15+
private const FIXTURES_PATH = __DIR__ . '/tests/invalid-guides-xml/input';
16+
17+
public function testInvalidGuidesXmlShowsHelpfulErrorMessage(): void
18+
{
19+
$binPath = dirname(__DIR__, 2) . '/bin/guides';
20+
21+
$process = new Process([
22+
'php',
23+
$binPath,
24+
'run',
25+
'--config=' . self::FIXTURES_PATH,
26+
self::FIXTURES_PATH,
27+
]);
28+
29+
$process->run();
30+
31+
// Should fail with exit code 1, not crash with fatal error
32+
self::assertSame(1, $process->getExitCode(), 'Expected exit code 1 for invalid guides.xml');
33+
34+
$stderr = $process->getErrorOutput();
35+
36+
// Should contain helpful error message, not PHP fatal error
37+
self::assertStringContainsString('Invalid guides.xml configuration', $stderr);
38+
self::assertStringNotContainsString('PHP Fatal error', $stderr);
39+
self::assertStringNotContainsString('Stack trace', $stderr);
40+
41+
// Should reference documentation
42+
self::assertStringContainsString('https://docs.typo3.org', $stderr);
43+
}
44+
45+
public function testInvalidGuidesXmlShowsLineNumber(): void
46+
{
47+
$binPath = dirname(__DIR__, 2) . '/bin/guides';
48+
49+
$process = new Process([
50+
'php',
51+
$binPath,
52+
'run',
53+
'--config=' . self::FIXTURES_PATH,
54+
self::FIXTURES_PATH,
55+
]);
56+
57+
$process->run();
58+
59+
$stderr = $process->getErrorOutput();
60+
61+
// Should show XSD validation error with line number
62+
self::assertStringContainsString('Line 3', $stderr);
63+
self::assertStringContainsString('theme', $stderr);
64+
}
65+
66+
public function testValidGuidesXmlRendersSuccessfully(): void
67+
{
68+
$binPath = dirname(__DIR__, 2) . '/bin/guides';
69+
$validFixturePath = __DIR__ . '/tests/getting-started/input';
70+
71+
// Skip if fixture doesn't exist
72+
if (!is_dir($validFixturePath)) {
73+
self::markTestSkipped('Valid fixture not available');
74+
}
75+
76+
$outputPath = sys_get_temp_dir() . '/render-guides-test-' . uniqid();
77+
78+
$process = new Process([
79+
'php',
80+
$binPath,
81+
'run',
82+
'--config=' . $validFixturePath,
83+
'--output=' . $outputPath,
84+
$validFixturePath,
85+
]);
86+
87+
$process->run();
88+
89+
// Clean up
90+
if (is_dir($outputPath)) {
91+
system('rm -rf ' . escapeshellarg($outputPath));
92+
}
93+
94+
// Should succeed
95+
self::assertSame(0, $process->getExitCode(), 'Expected exit code 0 for valid guides.xml. Error: ' . $process->getErrorOutput());
96+
}
97+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=====
2+
Test
3+
=====
4+
5+
This should not render due to invalid guides.xml.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<guides xmlns="https://www.phpdoc.org/guides">
3+
<theme name="typo3docs" />
4+
<project title="Test" />
5+
</guides>

0 commit comments

Comments
 (0)