|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Firstred\PostNL\Tests\Exception; |
| 6 | + |
| 7 | +use Firstred\PostNL\Exception\CifException; |
| 8 | +use Monolog\Test\TestCase; |
| 9 | +use PHPUnit\Framework\Attributes\TestDox; |
| 10 | + |
| 11 | +#[TestDox(text: 'The CifException object')] |
| 12 | +class CifExceptionTest extends TestCase |
| 13 | +{ |
| 14 | + #[TestDox(text: 'Test creating a CifException with a single error')] |
| 15 | + public function testSingleError(): void |
| 16 | + { |
| 17 | + $exception = new CifException(message: 'A test exception', code: 400); |
| 18 | + |
| 19 | + $this->assertEquals(expected: 'A test exception', actual: $exception->getMessage()); |
| 20 | + $this->assertEquals(expected: 400, actual: $exception->getCode()); |
| 21 | + $this->assertEquals(expected: [ |
| 22 | + [ |
| 23 | + 'message' => 'A test exception', |
| 24 | + 'description' => 'A test exception', |
| 25 | + 'code' => 400, |
| 26 | + ], |
| 27 | + ], actual: $exception->getMessagesDescriptionsAndCodes()); |
| 28 | + } |
| 29 | + |
| 30 | + #[TestDox(text: 'Test creating a CifException with multiple errors')] |
| 31 | + public function testMultipleError(): void |
| 32 | + { |
| 33 | + $exceptionData = [ |
| 34 | + [ |
| 35 | + 'message' => 'First exception', |
| 36 | + 'description' => 'First description', |
| 37 | + 'code' => 400, |
| 38 | + ], |
| 39 | + [ |
| 40 | + 'message' => 'Second exception', |
| 41 | + 'description' => 'First description', |
| 42 | + 'code' => 401, |
| 43 | + ], |
| 44 | + ]; |
| 45 | + $exception = new CifException(message: $exceptionData, code: 0); |
| 46 | + |
| 47 | + $this->assertEquals(expected: 'First exception (First description)', actual: $exception->getMessage()); |
| 48 | + $this->assertEquals(expected: 400, actual: $exception->getCode()); |
| 49 | + $this->assertEquals(expected: $exceptionData, actual: $exception->getMessagesDescriptionsAndCodes()); |
| 50 | + } |
| 51 | +} |
0 commit comments