1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TMV\Laminas\Messenger\Test\Subscriber; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
8
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; |
11
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; |
12
|
|
|
use TMV\Laminas\Messenger\Subscriber\DoctrineClearEntityManagerWorkerSubscriber; |
13
|
|
|
|
14
|
|
|
class DoctrineClearEntityManagerWorkerSubscriberTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testSubscribedEvents(): void |
17
|
|
|
{ |
18
|
|
|
$managerRegistry = $this->prophesize(ManagerRegistry::class); |
19
|
|
|
$subscriber = new DoctrineClearEntityManagerWorkerSubscriber($managerRegistry->reveal()); |
20
|
|
|
|
21
|
|
|
$events = []; |
22
|
|
|
foreach (DoctrineClearEntityManagerWorkerSubscriber::getSubscribedEvents() as $key => $value) { |
23
|
|
|
$events[$key] = $value; |
24
|
|
|
$this->assertIsCallable([$subscriber, $value]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$this->assertSame([ |
28
|
|
|
WorkerMessageHandledEvent::class => 'onWorkerMessageHandled', |
29
|
|
|
WorkerMessageFailedEvent::class => 'onWorkerMessageFailed', |
30
|
|
|
], $events); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testOnWorkerMessageHandled(): void |
34
|
|
|
{ |
35
|
|
|
$entityManager = $this->prophesize(EntityManagerInterface::class); |
36
|
|
|
$managerRegistry = $this->prophesize(ManagerRegistry::class); |
37
|
|
|
|
38
|
|
|
$managerRegistry->getManagers()->willReturn([$entityManager->reveal()]); |
39
|
|
|
$entityManager->clear()->shouldBeCalled(); |
40
|
|
|
|
41
|
|
|
$subscriber = new DoctrineClearEntityManagerWorkerSubscriber($managerRegistry->reveal()); |
42
|
|
|
$subscriber->onWorkerMessageHandled(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testOnWorkerMessageFailed(): void |
46
|
|
|
{ |
47
|
|
|
$entityManager = $this->prophesize(EntityManagerInterface::class); |
48
|
|
|
$managerRegistry = $this->prophesize(ManagerRegistry::class); |
49
|
|
|
|
50
|
|
|
$managerRegistry->getManagers()->willReturn([$entityManager->reveal()]); |
51
|
|
|
$entityManager->clear()->shouldBeCalled(); |
52
|
|
|
|
53
|
|
|
$subscriber = new DoctrineClearEntityManagerWorkerSubscriber($managerRegistry->reveal()); |
54
|
|
|
$subscriber->onWorkerMessageFailed(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|