|
| 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