|
1
|
|
|
<?php |
|
2
|
|
|
namespace Mathielen\ImportEngine\Storage\Provider; |
|
3
|
|
|
|
|
4
|
|
|
use Mathielen\ImportEngine\Storage\ServiceStorage; |
|
5
|
|
|
use Mathielen\ImportEngine\ValueObject\StorageSelection; |
|
6
|
|
|
|
|
7
|
|
|
class ServiceStorageProviderTest extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var ServiceStorageProvider |
|
12
|
|
|
*/ |
|
13
|
|
|
private $serviceStorageProvider; |
|
14
|
|
|
|
|
15
|
|
|
protected function setUp() |
|
16
|
|
|
{ |
|
17
|
|
|
$containerMock = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); |
|
18
|
|
|
$containerMock |
|
19
|
|
|
->expects($this->any()) |
|
20
|
|
|
->method('get') |
|
21
|
|
|
->will($this->returnValue(new TestService())); |
|
22
|
|
|
|
|
23
|
|
|
$this->serviceStorageProvider = new ServiceStorageProvider($containerMock, array('serviceA'=>array('methods'=>array('myCallableMethod')))); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testStorageWithArguments() |
|
27
|
|
|
{ |
|
28
|
|
|
$selection = new StorageSelection(array(new TestService(), 'myCallableMethod', 'arguments'=>array(1,2))); |
|
29
|
|
|
$actualResult = $this->serviceStorageProvider->storage($selection); |
|
30
|
|
|
|
|
31
|
|
|
$expectedResult = new ServiceStorage(array(new TestService(), 'myCallableMethod'), array(1,2)); |
|
32
|
|
|
$this->assertEquals($expectedResult, $actualResult); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testStorage() |
|
36
|
|
|
{ |
|
37
|
|
|
$callable = function () { return array('data'); }; |
|
38
|
|
|
|
|
39
|
|
|
$selection = new StorageSelection($callable); |
|
40
|
|
|
$actualResult = $this->serviceStorageProvider->storage($selection); |
|
41
|
|
|
|
|
42
|
|
|
$expectedResult = new ServiceStorage($callable); |
|
43
|
|
|
$this->assertEquals($expectedResult, $actualResult); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testSelect() |
|
47
|
|
|
{ |
|
48
|
|
|
$id = array( |
|
49
|
|
|
'service' => 'serviceA', |
|
50
|
|
|
'method' => 'myCallableMethod' |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
$actualResult = $this->serviceStorageProvider->select($id); |
|
54
|
|
|
$expectedResult = new StorageSelection(array(new TestService(), 'myCallableMethod', null)); |
|
55
|
|
|
$this->assertEquals($expectedResult, $actualResult); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @dataProvider getExceptionData |
|
60
|
|
|
* @expectedException InvalidArgumentException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testException($id) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->serviceStorageProvider->select($id); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getExceptionData() |
|
68
|
|
|
{ |
|
69
|
|
|
return array( |
|
70
|
|
|
array('invalid_format'), |
|
71
|
|
|
array(array('service'=>'Unknown Service', 'method'=>'abc')), |
|
72
|
|
|
array(array('service'=>'serviceA', 'method'=>'Unknown Method')) |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
class TestService |
|
79
|
|
|
{ |
|
80
|
|
|
|
|
81
|
|
|
public function myCallableMethod() {} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|