1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AMQPAL\Adapter; |
4
|
|
|
|
5
|
|
|
class AdapterFactoryTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
public function testSetAdapters() |
8
|
|
|
{ |
9
|
|
|
$adapters = [ |
10
|
|
|
'foo' => AdapterStub::class, |
11
|
|
|
'bar' => AdapterStub::class, |
12
|
|
|
]; |
13
|
|
|
|
14
|
|
|
$factory = new AdapterFactory(); |
15
|
|
|
$factory->setAdapters($adapters); |
16
|
|
|
|
17
|
|
|
static::assertEquals($adapters, $factory->getAdapters()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testAddAdapter() |
21
|
|
|
{ |
22
|
|
|
$factory = new AdapterFactory(); |
23
|
|
|
$factory->setAdapters([]); |
24
|
|
|
|
25
|
|
|
static::assertEquals([], $factory->getAdapters()); |
26
|
|
|
|
27
|
|
|
$factory->setAdapter('foo', AdapterStub::class); |
28
|
|
|
static::assertEquals(['foo' => AdapterStub::class], $factory->getAdapters()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testCreateAdapter() |
32
|
|
|
{ |
33
|
|
|
$adapters = [ |
34
|
|
|
'foo' => AdapterStub::class, |
35
|
|
|
'bar' => AdapterStub::class, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
$factory = new AdapterFactory(); |
39
|
|
|
$factory->setAdapters($adapters); |
40
|
|
|
|
41
|
|
|
static::assertEquals($adapters, $factory->getAdapters()); |
42
|
|
|
|
43
|
|
|
$options = [ |
44
|
|
|
'name' => 'foo', |
45
|
|
|
'options' => [ |
46
|
|
|
'host' => 'foo-hostname' |
47
|
|
|
] |
48
|
|
|
]; |
49
|
|
|
$adapter = $factory->createAdapter($options); |
50
|
|
|
|
51
|
|
|
static::assertInstanceOf(AdapterStub::class, $adapter); |
52
|
|
|
static::assertEquals($adapter->options, ['host' => 'foo-hostname']); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @expectedException \AMQPAL\Adapter\Exception\InvalidArgumentException |
57
|
|
|
* @expectedExceptionMessage Unable to find 'name' key. |
58
|
|
|
*/ |
59
|
|
|
public function testCreateAdapterWithNoName() |
60
|
|
|
{ |
61
|
|
|
$adapters = []; |
62
|
|
|
|
63
|
|
|
$factory = new AdapterFactory(); |
64
|
|
|
$factory->setAdapters($adapters); |
65
|
|
|
|
66
|
|
|
$options = [ |
67
|
|
|
'options' => [ |
68
|
|
|
|
69
|
|
|
] |
70
|
|
|
]; |
71
|
|
|
$factory->createAdapter($options); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @expectedException \AMQPAL\Adapter\Exception\InvalidArgumentException |
76
|
|
|
* @expectedExceptionMessage Unable to find 'options' key. |
77
|
|
|
*/ |
78
|
|
|
public function testCreateAdapterWithNoOptions() |
79
|
|
|
{ |
80
|
|
|
$adapters = []; |
81
|
|
|
|
82
|
|
|
$factory = new AdapterFactory(); |
83
|
|
|
$factory->setAdapters($adapters); |
84
|
|
|
|
85
|
|
|
$options = [ |
86
|
|
|
'name' => 'foo', |
87
|
|
|
]; |
88
|
|
|
$factory->createAdapter($options); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @expectedException \AMQPAL\Adapter\Exception\OutOfBoundsException |
93
|
|
|
* @expectedExceptionMessage Unable to find adapter 'foo'. |
94
|
|
|
*/ |
95
|
|
|
public function testCreateAdapterWithInvalidAdapter() |
96
|
|
|
{ |
97
|
|
|
$adapters = []; |
98
|
|
|
|
99
|
|
|
$factory = new AdapterFactory(); |
100
|
|
|
$factory->setAdapters($adapters); |
101
|
|
|
|
102
|
|
|
$options = [ |
103
|
|
|
'name' => 'foo', |
104
|
|
|
'options' => [] |
105
|
|
|
]; |
106
|
|
|
$factory->createAdapter($options); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: