Skip to content

Commit ef68658

Browse files
aymanrbclaude
andcommitted
Add dedicated exception tests and include Exception dir in coverage
Exception classes had no direct tests, so their inheritance chain, message propagation, and newly added classes (InvalidTemplateSyntaxException, InvalidTemplateVariableNameException) were unverified. ExceptionTest covers all exception classes for correct base-class inheritance and message preservation. Also remove the src/Exception coverage exclusion from phpunit.xml so exception code is now tracked in the coverage report. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b0fcc50 commit ef68658

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@
1414
<include>
1515
<directory suffix=".php">src</directory>
1616
</include>
17-
<exclude>
18-
<directory suffix=".php">src/Exception</directory>
19-
</exclude>
2017
</source>
2118
</phpunit>

tests/Exception/ExceptionTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace aymanrb\UnstructuredTextParser\Tests\Exception;
6+
7+
use aymanrb\UnstructuredTextParser\Exception\InvalidParsedDataKeyException;
8+
use aymanrb\UnstructuredTextParser\Exception\InvalidParseFileException;
9+
use aymanrb\UnstructuredTextParser\Exception\InvalidTemplateSyntaxException;
10+
use aymanrb\UnstructuredTextParser\Exception\InvalidTemplatesDirectoryException;
11+
use aymanrb\UnstructuredTextParser\Exception\InvalidTemplateVariableNameException;
12+
use aymanrb\UnstructuredTextParser\Exception\UnstructuredTextParserException;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ExceptionTest extends TestCase
16+
{
17+
public function testAllExceptionsExtendBaseException(): void
18+
{
19+
$this->assertInstanceOf(UnstructuredTextParserException::class, new InvalidParseFileException());
20+
$this->assertInstanceOf(UnstructuredTextParserException::class, new InvalidParsedDataKeyException());
21+
$this->assertInstanceOf(UnstructuredTextParserException::class, new InvalidTemplatesDirectoryException());
22+
$this->assertInstanceOf(UnstructuredTextParserException::class, new InvalidTemplateSyntaxException());
23+
$this->assertInstanceOf(UnstructuredTextParserException::class, new InvalidTemplateVariableNameException());
24+
}
25+
26+
public function testBaseExceptionExtendsRuntimeException(): void
27+
{
28+
$this->assertInstanceOf(\Exception::class, new UnstructuredTextParserException());
29+
}
30+
31+
public function testInvalidTemplatesDirectoryExceptionPreservesMessage(): void
32+
{
33+
$message = 'Invalid templates directory provided';
34+
$exception = new InvalidTemplatesDirectoryException($message);
35+
36+
$this->assertSame($message, $exception->getMessage());
37+
}
38+
39+
public function testInvalidParseFileExceptionPreservesMessage(): void
40+
{
41+
$path = '/some/missing/file.txt';
42+
$exception = new InvalidParseFileException($path);
43+
44+
$this->assertSame($path, $exception->getMessage());
45+
}
46+
47+
public function testInvalidParsedDataKeyExceptionPreservesMessage(): void
48+
{
49+
$message = 'Undefined results key: myKey';
50+
$exception = new InvalidParsedDataKeyException($message);
51+
52+
$this->assertSame($message, $exception->getMessage());
53+
}
54+
55+
public function testInvalidTemplateSyntaxExceptionPreservesMessage(): void
56+
{
57+
$message = 'Template produced an invalid regex pattern: No error';
58+
$exception = new InvalidTemplateSyntaxException($message);
59+
60+
$this->assertSame($message, $exception->getMessage());
61+
}
62+
63+
public function testInvalidTemplateVariableNameExceptionPreservesMessage(): void
64+
{
65+
$message = 'Invalid template variable name "my-var"';
66+
$exception = new InvalidTemplateVariableNameException($message);
67+
68+
$this->assertSame($message, $exception->getMessage());
69+
}
70+
}

0 commit comments

Comments
 (0)