Skip to content

Commit 5e9e07d

Browse files
committed
qa: provide tests for ErrorEvent
Adds ErrorEventTest, to test the behavior of ErrorEvent. Discovered a typo on the constructor as a result, which is now fixed.
1 parent 2b13283 commit 5e9e07d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/ErrorEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ErrorEvent extends \Exception
2121

2222
public function __construct(object $event, callable $listener, Throwable $throwable)
2323
{
24-
parent::__construct($throwable->getMessage, $throwable->getCode(), $throwable);
24+
parent::__construct($throwable->getMessage(), $throwable->getCode(), $throwable);
2525
$this->event = $event;
2626
$this->listener = $listener;
2727
}

test/ErrorEventTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* @see https://github.com/phly/phly-event-dispatcher for the canonical source repository
4+
* @copyright Copyright (c) 2019 Matthew Weier O'Phinney (https:/mwop.net)
5+
* @license https://github.com/phly/phly-event-dispatcher/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace PhlyTest\EventDispatcher;
11+
12+
use Phly\EventDispatcher\ErrorEvent;
13+
use PhlyTest\EventDispatcher\TestAsset\TestEvent;
14+
use PHPUnit\Framework\TestCase;
15+
use RuntimeException;
16+
17+
class ErrorEventTest extends TestCase
18+
{
19+
public function testErrorEventComposesEventListenerAndThrowable()
20+
{
21+
$message = 'ERROR MESSAGE';
22+
$code = 12345;
23+
$event = new TestEvent();
24+
$listener = function (TestEvent $event) {
25+
};
26+
$exception = new RuntimeException($message, $code);
27+
28+
$errorEvent = new ErrorEvent($event, $listener, $exception);
29+
30+
$this->assertSame($event, $errorEvent->getEvent());
31+
$this->assertSame($listener, $errorEvent->getListener());
32+
$this->assertSame($exception, $errorEvent->getThrowable());
33+
34+
$this->assertSame($message, $errorEvent->getMessage());
35+
$this->assertSame($code, $errorEvent->getCode());
36+
$this->assertSame($exception, $errorEvent->getPrevious());
37+
}
38+
}

0 commit comments

Comments
 (0)