forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleRegistryTest.php
92 lines (72 loc) · 2.98 KB
/
SimpleRegistryTest.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Enqueue\AsyncEventDispatcher\Tests;
use Enqueue\AsyncEventDispatcher\EventTransformer;
use Enqueue\AsyncEventDispatcher\Registry;
use Enqueue\AsyncEventDispatcher\SimpleRegistry;
use Enqueue\Test\ClassExtensionTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
class SimpleRegistryTest extends TestCase
{
use ClassExtensionTrait;
public function testShouldImplementRegistryInterface()
{
$this->assertClassImplements(Registry::class, SimpleRegistry::class);
}
public function testShouldAllowGetTransportNameByEventName()
{
$registry = new SimpleRegistry([
'fooEvent' => 'fooTrans',
], []);
$this->assertEquals('fooTrans', $registry->getTransformerNameForEvent('fooEvent'));
}
public function testShouldAllowDefineTransportNameAsRegExpPattern()
{
$registry = new SimpleRegistry([
'/.*/' => 'fooRegExpTrans',
'fooEvent' => 'fooTrans',
], []);
// guard
$this->assertEquals('fooTrans', $registry->getTransformerNameForEvent('fooEvent'));
$this->assertEquals('fooRegExpTrans', $registry->getTransformerNameForEvent('fooRegExpEvent'));
}
public function testThrowIfNotSupportedEventGiven()
{
$registry = new SimpleRegistry([
'fooEvent' => 'fooTrans',
], []);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('There is no transformer registered for the given event fooNotSupportedEvent');
$registry->getTransformerNameForEvent('fooNotSupportedEvent');
}
public function testThrowIfThereIsNoRegisteredTransformerWithSuchName()
{
$registry = new SimpleRegistry([], [
'fooTrans' => 'foo_trans_id',
]);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('There is no transformer named fooNotRegisteredName');
$registry->getTransformer('fooNotRegisteredName');
}
public function testThrowIfObjectAssocWithTransportNameNotInstanceOfEventTransformer()
{
$container = new Container();
$container->set('foo_trans_id', new \stdClass());
$registry = new SimpleRegistry([], [
'fooTrans' => new \stdClass(),
]);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The container must return instance of Enqueue\AsyncEventDispatcher\EventTransformer but got stdClass');
$registry->getTransformer('fooTrans');
}
public function testShouldReturnEventTransformer()
{
$eventTransformerMock = $this->createMock(EventTransformer::class);
$container = new Container();
$container->set('foo_trans_id', $eventTransformerMock);
$registry = new SimpleRegistry([], [
'fooTrans' => $eventTransformerMock,
]);
$this->assertSame($eventTransformerMock, $registry->getTransformer('fooTrans'));
}
}