Skip to content

Commit 577344c

Browse files
committed
Add test
1 parent 4155a68 commit 577344c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/CompositeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class CompositeException extends Exception
1515
/**
1616
* @var Throwable[]
1717
*/
18-
public array $rest;
18+
private array $rest;
1919

2020
public function __construct(
2121
private Throwable $first,

tests/CompositeExceptionTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

Comments
 (0)