Completed
Pull Request — master (#17)
by Oliver
10:51
created

testAddClientWithANonStringKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the MobileNotifBundle package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace LinkValue\MobileNotifBundle\Tests\Client;
11
12
use LinkValue\MobileNotif\Client\ClientInterface;
13
use LinkValue\MobileNotifBundle\Client\ClientCollection;
14
15
/**
16
 * Test ClientCollection class.
17
 *
18
 * @package MobileNotifBundle
19
 * @author Oliver Thebault <[email protected]>
20
 */
21
class ClientCollectionTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var ClientCollection
25
     */
26
    private $clientCollection;
27
28
    /**
29
     * @var ClientInterface
30
     */
31
    private $client;
32
33
    /**
34
     * @var ClientInterface
35
     */
36
    private $apnsClient;
37
38
    /**
39
     * @var ClientInterface
40
     */
41
    private $gcmClient;
42
43
    /**
44
     * Unit tests setUp.
45
     */
46
    protected function setUp()
47
    {
48
        $this->clientCollection = new ClientCollection();
49
        $this->client = $this->prophesize('LinkValue\MobileNotif\Client\ClientInterface')->reveal();
50
        $this->apnsClient = $this->prophesize('LinkValue\MobileNotifBundle\Client\ApnsClient')->reveal();
51
        $this->gcmClient = $this->prophesize('LinkValue\MobileNotifBundle\Client\GcmClient')->reveal();
52
    }
53
54
    /**
55
     * @test
56
     */
57
    public function testAddClientWithANonStringKey()
58
    {
59
        $this->setExpectedException('InvalidArgumentException');
60
61
        $this->clientCollection->addClient(5, $this->client);
62
    }
63
64
    /**
65
     * @test
66
     */
67
    public function testAddClientWithAlreadyRegisteredKey()
68
    {
69
        $this->setExpectedException('RuntimeException');
70
71
        $this->clientCollection
72
            ->addClient('something', $this->apnsClient)
73
            ->addClient('something', $this->gcmClient)
74
        ;
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function testAddClient()
81
    {
82
        $key = 'something';
83
84
        $this->clientCollection->addClient($key, $this->client);
85
86
        $this->assertEquals($this->client, $this->clientCollection->get($key));
87
    }
88
89
    /**
90
     * @test
91
     */
92 View Code Duplication
    public function testGetApnsClients()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        $apnsClient1 = clone $this->apnsClient;
95
        $apnsClient2 = clone $this->apnsClient;
96
97
        $this->clientCollection
98
            ->addClient('apns-client-1', $apnsClient1)
99
            ->addClient('apns-client-2', $apnsClient2)
100
            ->addClient('gcm-client', $this->gcmClient)
101
            ->addClient('random-client', $this->client)
102
        ;
103
104
        $expectedCollection = (new ClientCollection())
105
            ->addClient('apns-client-1', $apnsClient1)
106
            ->addClient('apns-client-2', $apnsClient2)
107
        ;
108
109
        $this->assertEquals($expectedCollection, $this->clientCollection->getApnsClients());
110
    }
111
112
    /**
113
     * @test
114
     */
115 View Code Duplication
    public function testGetGcmClients()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $gcmClient1 = clone $this->gcmClient;
118
        $gcmClient2 = clone $this->gcmClient;
119
120
        $this->clientCollection
121
            ->addClient('gcm-client-1', $gcmClient1)
122
            ->addClient('gcm-client-2', $gcmClient2)
123
            ->addClient('apns-client', $this->apnsClient)
124
            ->addClient('random-client', $this->client)
125
        ;
126
127
        $expectedCollection = (new ClientCollection())
128
            ->addClient('gcm-client-1', $gcmClient1)
129
            ->addClient('gcm-client-2', $gcmClient2)
130
        ;
131
132
        $this->assertEquals($expectedCollection, $this->clientCollection->getGcmClients());
133
    }
134
}
135