|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Stefano Torresi (http://stefanotorresi.it) |
|
4
|
|
|
* @license See the file LICENSE.txt for copying permission. |
|
5
|
|
|
* ************************************************ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Thorr\Persistence\Test\DataMapper\Manager; |
|
9
|
|
|
|
|
10
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
11
|
|
|
use Thorr\Persistence\Test\Asset; |
|
12
|
|
|
use Thorr\Persistence\DataMapper\DataMapperInterface; |
|
13
|
|
|
use Thorr\Persistence\DataMapper\Manager\DataMapperManager; |
|
14
|
|
|
use Thorr\Persistence\DataMapper\Manager\DataMapperManagerFactory; |
|
15
|
|
|
use Zend\ServiceManager\Di\DiAbstractServiceFactory; |
|
16
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
17
|
|
|
|
|
18
|
|
|
class DataMapperManagerFactoryTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testCreateService() |
|
21
|
|
|
{ |
|
22
|
|
|
$factory = new DataMapperManagerFactory(); |
|
23
|
|
|
$serviceLocator = $this->getMock(ServiceLocatorInterface::class); |
|
24
|
|
|
|
|
25
|
|
|
$dataMapperManager = $factory->createService($serviceLocator); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertInstanceOf(DataMapperManager::class, $dataMapperManager); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testDISupport() |
|
31
|
|
|
{ |
|
32
|
|
|
$factory = new DataMapperManagerFactory(); |
|
33
|
|
|
$serviceLocator = $this->getMock(ServiceLocatorInterface::class); |
|
34
|
|
|
$diAbstractFactory = $this->getMockBuilder(DiAbstractServiceFactory::class) |
|
35
|
|
|
->disableOriginalConstructor() |
|
36
|
|
|
->getMock(); |
|
37
|
|
|
|
|
38
|
|
|
$serviceLocator->expects($this->atLeastOnce()) |
|
39
|
|
|
->method('get') |
|
40
|
|
|
->willReturnCallback(function ($arg) use ($diAbstractFactory) { |
|
41
|
|
|
switch ($arg) { |
|
42
|
|
|
case 'Config': return [ 'di' => [] ]; |
|
|
|
|
|
|
43
|
|
|
case 'DiAbstractServiceFactory': return $diAbstractFactory; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
}); |
|
46
|
|
|
|
|
47
|
|
|
$serviceLocator->expects($this->atLeastOnce()) |
|
48
|
|
|
->method('has') |
|
49
|
|
|
->with('Di') |
|
50
|
|
|
->willReturn(true); |
|
51
|
|
|
|
|
52
|
|
|
$dataMapperManager = $factory->createService($serviceLocator); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertAttributeContains($diAbstractFactory, 'abstractFactories', $dataMapperManager); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testCreateServiceWithConfig() |
|
58
|
|
|
{ |
|
59
|
|
|
$factory = new DataMapperManagerFactory(); |
|
60
|
|
|
$serviceLocator = $this->getMock(ServiceLocatorInterface::class); |
|
61
|
|
|
$dataMapper = $this->getMock(DataMapperInterface::class); |
|
62
|
|
|
$dataMapper->expects($this->any())->method('getEntityClass')->willReturn(Asset\Entity::class); |
|
63
|
|
|
|
|
64
|
|
|
$serviceLocator |
|
65
|
|
|
->expects($this->any()) |
|
66
|
|
|
->method('get') |
|
67
|
|
|
->with('Config') |
|
68
|
|
|
->willReturn([ |
|
69
|
|
|
'thorr_persistence_dmm' => [ |
|
70
|
|
|
'services' => [ |
|
71
|
|
|
'foo' => $dataMapper |
|
72
|
|
|
] |
|
73
|
|
|
] |
|
74
|
|
|
]) |
|
75
|
|
|
; |
|
76
|
|
|
|
|
77
|
|
|
$dataMapperManager = $factory->createService($serviceLocator); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertInstanceOf(DataMapperManager::class, $dataMapperManager); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertSame($dataMapper, $dataMapperManager->get('foo')); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.