|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Calvert\DndErrors\Tests\Archetype; |
| 4 | + |
| 5 | +use Calvert\DndErrors\Archetype\Paladin; |
| 6 | +use Calvert\DndErrors\ErrorContext; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +final class PaladinTest extends TestCase |
| 10 | +{ |
| 11 | + private Paladin $paladin; |
| 12 | + |
| 13 | + protected function setUp(): void |
| 14 | + { |
| 15 | + $this->paladin = new Paladin(); |
| 16 | + } |
| 17 | + |
| 18 | + public function testGetSlugReturnsPaladin(): void |
| 19 | + { |
| 20 | + $this->assertSame('paladin', $this->paladin->getSlug()); |
| 21 | + } |
| 22 | + |
| 23 | + public function testRenderContainsMessage(): void |
| 24 | + { |
| 25 | + $context = new ErrorContext( |
| 26 | + type: 'Error', |
| 27 | + message: 'Test error message', |
| 28 | + file: '/path/to/file.php', |
| 29 | + line: 42 |
| 30 | + ); |
| 31 | + |
| 32 | + $output = $this->paladin->render($context); |
| 33 | + |
| 34 | + $this->assertStringContainsString('Test error message', $output); |
| 35 | + $this->assertStringContainsString('/path/to/file.php:42', $output); |
| 36 | + } |
| 37 | + |
| 38 | + public function testRenderContainsPaladinEmoji(): void |
| 39 | + { |
| 40 | + $context = new ErrorContext( |
| 41 | + type: 'Error', |
| 42 | + message: 'Test error', |
| 43 | + ); |
| 44 | + |
| 45 | + $output = $this->paladin->render($context); |
| 46 | + |
| 47 | + // Should contain paladin emoji (✨ or ⚔️) |
| 48 | + $this->assertTrue( |
| 49 | + str_contains($output, '✨') || str_contains($output, '⚔️'), |
| 50 | + 'Output should contain paladin emoji' |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + public function testRenderIncludesLocationWhenProvided(): void |
| 55 | + { |
| 56 | + $context = new ErrorContext( |
| 57 | + type: 'Error', |
| 58 | + message: 'Test error', |
| 59 | + file: 'test.php', |
| 60 | + line: 10 |
| 61 | + ); |
| 62 | + |
| 63 | + $output = $this->paladin->render($context); |
| 64 | + |
| 65 | + $this->assertStringContainsString('test.php:10', $output); |
| 66 | + } |
| 67 | + |
| 68 | + public function testRenderShowsUnknownLocationWhenFileOrLineMissing(): void |
| 69 | + { |
| 70 | + $context = new ErrorContext( |
| 71 | + type: 'Error', |
| 72 | + message: 'Test error', |
| 73 | + ); |
| 74 | + |
| 75 | + $output = $this->paladin->render($context); |
| 76 | + |
| 77 | + $this->assertStringContainsString('Unknown location', $output); |
| 78 | + } |
| 79 | + |
| 80 | + public function testRenderForFatalError(): void |
| 81 | + { |
| 82 | + $context = new ErrorContext( |
| 83 | + type: 'fatal', |
| 84 | + message: 'Fatal error occurred', |
| 85 | + ); |
| 86 | + |
| 87 | + $output = $this->paladin->render($context); |
| 88 | + |
| 89 | + // Fatal errors should have special headers |
| 90 | + $this->assertStringContainsString('Fatal error occurred', $output); |
| 91 | + } |
| 92 | +} |
| 93 | + |
0 commit comments