testCreateServiceWithConfig()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 26
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
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\DataMapper\DataMapperInterface;
12
use Thorr\Persistence\DataMapper\Manager\DataMapperManager;
13
use Thorr\Persistence\DataMapper\Manager\DataMapperManagerFactory;
14
use Thorr\Persistence\Test\Asset;
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' => [] ];
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
43
                    case 'DiAbstractServiceFactory': return $diAbstractFactory;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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