Failed Conditions
Branch master (116909)
by Guilherme
09:02
created

ClientManagerTest::testGetClientByPublicId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 1
b 0
f 1
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Tests\Manager;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use LoginCidadao\OAuthBundle\Entity\Client;
15
use LoginCidadao\OAuthBundle\Entity\ClientRepository;
16
use LoginCidadao\OpenIDBundle\Manager\ClientManager;
17
use Symfony\Component\EventDispatcher\EventDispatcher;
18
19
class ClientManagerTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testGetClientById()
22
    {
23
        $id = 123;
24
25
        $repo = $this->getClientRepository();
26
        $repo->expects($this->once())->method('find')->willReturn(new Client());
27
28
        $em = $this->getEntityManager();
29
        $em->expects($this->once())->method('getRepository')->with('LoginCidadaoOAuthBundle:Client')
30
            ->willReturn($repo);
31
32
        $manager = new ClientManager($em, $this->getDispatcher());
33
        $manager->getClientById($id);
34
    }
35
36
    public function testGetClientByPublicId()
37
    {
38
        $id = '123_randomIdHere';
39
40
        $repo = $this->getClientRepository();
41
        $repo->expects($this->once())->method('findOneBy')
42
            ->with(['id' => 123, 'randomId' => 'randomIdHere'])
43
            ->willReturn(new Client());
44
45
        $em = $this->getEntityManager();
46
        $em->expects($this->once())->method('getRepository')->with('LoginCidadaoOAuthBundle:Client')
47
            ->willReturn($repo);
48
49
        $manager = new ClientManager($em, $this->getDispatcher());
50
        $manager->getClientById($id);
51
    }
52
53
    /**
54
     * @return EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
55
     */
56
    private function getEntityManager()
57
    {
58
        $em = $this->getMock('Doctrine\ORM\EntityManagerInterface');
59
60
        return $em;
61
    }
62
63
    /**
64
     * @return ClientRepository|\PHPUnit_Framework_MockObject_MockObject
65
     */
66
    private function getClientRepository()
67
    {
68
        $repo = $this->getMockBuilder('LoginCidadao\OAuthBundle\Entity\ClientRepository')
69
            ->disableOriginalConstructor()->getMock();
70
71
        return $repo;
72
    }
73
74
    /**
75
     * @return EventDispatcher|\PHPUnit_Framework_MockObject_MockObject
76
     */
77
    private function getDispatcher()
78
    {
79
        $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
80
81
        return $dispatcher;
82
    }
83
}
84