-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathResourcesTest.php
149 lines (109 loc) · 5.7 KB
/
ResourcesTest.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Enqueue\Tests;
use Enqueue\Redis\RedisConnectionFactory;
use Enqueue\Resources;
use Enqueue\Wamp\WampConnectionFactory;
use Interop\Queue\ConnectionFactory;
use PHPUnit\Framework\TestCase;
class ResourcesTest extends TestCase
{
public function testShouldBeFinal()
{
$rc = new \ReflectionClass(Resources::class);
$this->assertTrue($rc->isFinal());
}
public function testShouldConstructorBePrivate()
{
$rc = new \ReflectionClass(Resources::class);
$this->assertTrue($rc->getConstructor()->isPrivate());
}
public function testShouldGetAvailableConnectionsInExpectedFormat()
{
$availableConnections = Resources::getAvailableConnections();
$this->assertInternalType('array', $availableConnections);
$this->assertArrayHasKey(RedisConnectionFactory::class, $availableConnections);
$connectionInfo = $availableConnections[RedisConnectionFactory::class];
$this->assertArrayHasKey('schemes', $connectionInfo);
$this->assertSame(['redis'], $connectionInfo['schemes']);
$this->assertArrayHasKey('supportedSchemeExtensions', $connectionInfo);
$this->assertSame(['predis', 'phpredis'], $connectionInfo['supportedSchemeExtensions']);
$this->assertArrayHasKey('package', $connectionInfo);
$this->assertSame('enqueue/redis', $connectionInfo['package']);
}
public function testShouldGetKnownConnectionsInExpectedFormat()
{
$availableConnections = Resources::getKnownConnections();
$this->assertInternalType('array', $availableConnections);
$this->assertArrayHasKey(RedisConnectionFactory::class, $availableConnections);
$connectionInfo = $availableConnections[RedisConnectionFactory::class];
$this->assertArrayHasKey('schemes', $connectionInfo);
$this->assertSame(['redis'], $connectionInfo['schemes']);
$this->assertArrayHasKey('supportedSchemeExtensions', $connectionInfo);
$this->assertSame(['predis', 'phpredis'], $connectionInfo['supportedSchemeExtensions']);
$this->assertArrayHasKey('package', $connectionInfo);
$this->assertSame('enqueue/redis', $connectionInfo['package']);
}
public function testThrowsIfConnectionClassNotImplementConnectionFactoryInterfaceOnAddConnection()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The connection factory class "stdClass" must implement "Interop\Queue\ConnectionFactory" interface.');
Resources::addConnection(\stdClass::class, [], [], 'foo');
}
public function testThrowsIfNoSchemesProvidedOnAddConnection()
{
$connectionClass = $this->getMockClass(ConnectionFactory::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Schemes could not be empty.');
Resources::addConnection($connectionClass, [], [], 'foo');
}
public function testThrowsIfNoPackageProvidedOnAddConnection()
{
$connectionClass = $this->getMockClass(ConnectionFactory::class);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Package name could not be empty.');
Resources::addConnection($connectionClass, ['foo'], [], '');
}
public function testShouldAllowRegisterConnectionThatIsNotInstalled()
{
Resources::addConnection('theConnectionClass', ['foo'], [], 'foo');
$knownConnections = Resources::getKnownConnections();
$this->assertInternalType('array', $knownConnections);
$this->assertArrayHasKey('theConnectionClass', $knownConnections);
$availableConnections = Resources::getAvailableConnections();
$this->assertInternalType('array', $availableConnections);
$this->assertArrayNotHasKey('theConnectionClass', $availableConnections);
}
public function testShouldAllowGetPreviouslyRegisteredConnection()
{
$connectionClass = $this->getMockClass(ConnectionFactory::class);
Resources::addConnection(
$connectionClass,
['fooscheme', 'barscheme'],
['fooextension', 'barextension'],
'foo/bar'
);
$availableConnections = Resources::getAvailableConnections();
$this->assertInternalType('array', $availableConnections);
$this->assertArrayHasKey($connectionClass, $availableConnections);
$connectionInfo = $availableConnections[$connectionClass];
$this->assertArrayHasKey('schemes', $connectionInfo);
$this->assertSame(['fooscheme', 'barscheme'], $connectionInfo['schemes']);
$this->assertArrayHasKey('supportedSchemeExtensions', $connectionInfo);
$this->assertSame(['fooextension', 'barextension'], $connectionInfo['supportedSchemeExtensions']);
$this->assertArrayHasKey('package', $connectionInfo);
$this->assertSame('foo/bar', $connectionInfo['package']);
}
public function testShouldHaveRegisteredWampConfiguration()
{
$availableConnections = Resources::getKnownConnections();
$this->assertInternalType('array', $availableConnections);
$this->assertArrayHasKey(WampConnectionFactory::class, $availableConnections);
$connectionInfo = $availableConnections[WampConnectionFactory::class];
$this->assertArrayHasKey('schemes', $connectionInfo);
$this->assertSame(['wamp', 'ws'], $connectionInfo['schemes']);
$this->assertArrayHasKey('supportedSchemeExtensions', $connectionInfo);
$this->assertSame([], $connectionInfo['supportedSchemeExtensions']);
$this->assertArrayHasKey('package', $connectionInfo);
$this->assertSame('enqueue/wamp', $connectionInfo['package']);
}
}