|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Yiisoft\ErrorHandler\Tests; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +final class CompositeExceptionTest extends TestCase |
| 10 | +{ |
| 11 | + public function testExceptions() |
| 12 | + { |
| 13 | + $exception1 = new \Exception('Exception 1', 123, new \Exception('Previous exception')); |
| 14 | + $exception2 = new \Exception('Exception 2'); |
| 15 | + $exception = new \Yiisoft\ErrorHandler\CompositeException( |
| 16 | + $exception1, |
| 17 | + $exception2, |
| 18 | + ); |
| 19 | + |
| 20 | + $this->assertSame('Exception 1', $exception->getMessage()); |
| 21 | + $this->assertSame(123, $exception->getCode()); |
| 22 | + $this->assertSame($exception1, $exception->getPrevious()); |
| 23 | + $this->assertSame($exception1, $exception->getFirstException()); |
| 24 | + $this->assertSame([$exception2], $exception->getPreviousExceptions()); |
| 25 | + } |
| 26 | + |
| 27 | + public function testOnlyOneException() |
| 28 | + { |
| 29 | + $exception1 = new \Exception('Exception 1', 123, new \Exception('Previous exception')); |
| 30 | + $exception = new \Yiisoft\ErrorHandler\CompositeException($exception1); |
| 31 | + |
| 32 | + $this->assertSame('Exception 1', $exception->getMessage()); |
| 33 | + $this->assertSame(123, $exception->getCode()); |
| 34 | + $this->assertSame($exception1, $exception->getPrevious()); |
| 35 | + $this->assertSame($exception1, $exception->getFirstException()); |
| 36 | + $this->assertSame([], $exception->getPreviousExceptions()); |
| 37 | + } |
| 38 | +} |
0 commit comments