NewApiFactoryTest::testCreate()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 37
rs 8.8571
c 2
b 0
f 1
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Tests\Unit\Component\EveApi\Account\ApiKeyInfo;
3
4
use Mockery as m;
5
use Tarioch\EveapiFetcherBundle\Component\EveApi\Account\ApiKeyInfo\NewApiFactory;
6
7
class NewApiFactoryTest extends \PHPUnit_Framework_TestCase
8
{
9
    private $entityManager;
10
    private $repository;
11
    private $api1;
12
    private $api2;
13
14
    private $factory;
15
16
    public function testCreate()
17
    {
18
        $accessMask = 'accessMask';
19
        $keyType = 'keyType';
20
        $apiId1 = 'apiId1';
21
        $apiId2 = 'apiId2';
22
        $section1 = 'section1';
23
        $ownerId1 = 'ownerId1';
24
        $ownerId2 = 'ownerId2';
25
26
        $expected = array(
27
            $apiId1 => array(
28
                $ownerId1 => $this->api1,
29
                $ownerId2 => $this->api1
30
            ),
31
            $apiId2 => array(
32
                0 => $this->api2
33
            )
34
        );
35
36
        $this->entityManager->shouldReceive('getRepository')
37
            ->with('TariochEveapiFetcherBundle:Api')
38
            ->andReturn($this->repository);
39
        $this->repository->shouldReceive('loadValidApis')
40
            ->with($accessMask, $keyType)
41
            ->andReturn(array($this->api1, $this->api2));
42
43
        $this->api1->shouldReceive('getApiId')->andReturn($apiId1);
44
        $this->api1->shouldReceive('getSection')->andReturn($section1);
45
46
        $this->api2->shouldReceive('getApiId')->andReturn($apiId2);
47
        $this->api2->shouldReceive('getSection')->andReturn('account');
48
49
        $actual = $this->factory->createNewApiMap($accessMask, $keyType, array($ownerId1, $ownerId2));
50
51
        $this->assertEquals($expected, $actual);
52
    }
53
54
    protected function setUp()
55
    {
56
        $this->entityManager = m::mock('Doctrine\ORM\EntityManager');
57
        $this->repository = m::mock('Tarioch\EveapiFetcherBundle\Entity\ApiRepository');
58
        $this->api1 = m::mock('Tarioch\EveapiFetcherBundle\Entity\Api');
59
        $this->api2 = m::mock('Tarioch\EveapiFetcherBundle\Entity\Api');
60
61
        $this->factory = new NewApiFactory($this->entityManager);
62
    }
63
}
64