/
ListenerExceptionCollectionModeTest.php
60 lines (50 loc) · 1.73 KB
/
ListenerExceptionCollectionModeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* This file is part of prooph/service-bus.
* (c) 2014-2021 Alexander Miertsch <kontakt@codeliner.ws>
* (c) 2015-2021 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ProophTest\ServiceBus\Plugin;
use PHPUnit\Framework\TestCase;
use Prooph\ServiceBus\CommandBus;
use Prooph\ServiceBus\EventBus;
use Prooph\ServiceBus\Exception\RuntimeException;
use Prooph\ServiceBus\Plugin\ListenerExceptionCollectionMode;
class ListenerExceptionCollectionModeTest extends TestCase
{
private $eventBus;
protected function setUp(): void
{
$this->eventBus = new class() extends EventBus {
public function isCollectExceptionsModeOn(): bool
{
return (bool) $this->collectExceptions;
}
};
$this->cut = new ListenerExceptionCollectionMode();
}
/**
* @test
*/
public function it_enables_collect_exceptions_mode_if_attached_and_disables_mode_if_detached_again(): void
{
$plugin = new ListenerExceptionCollectionMode();
$plugin->attachToMessageBus($this->eventBus);
$this->assertTrue($this->eventBus->isCollectExceptionsModeOn());
$plugin->detachFromMessageBus($this->eventBus);
$this->assertFalse($this->eventBus->isCollectExceptionsModeOn());
}
/**
* @test
*/
public function it_throws_exception_if_message_bus_is_not_an_event_bus(): void
{
$this->expectException(RuntimeException::class);
$plugin = new ListenerExceptionCollectionMode();
$plugin->attachToMessageBus(new CommandBus());
}
}