Completed
Push — master ( a7adc8...500d1e )
by dan
02:35
created

PusherChannelVoterTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace IrishDan\NotificationBundle\Test\Security;
4
5
use IrishDan\NotificationBundle\PusherChannel;
6
use IrishDan\NotificationBundle\Security\PusherChannelVoter;
7
use IrishDan\NotificationBundle\Test\NotificationTestCase;
8
9
class PusherChannelVoterTest extends NotificationTestCase
10
{
11
    protected $voter;
12
    protected $pusherChannel;
13
14
    public function setUp()
15
    {
16
        $config = $this->getNotificationChannelConfiguration('pusher');
17
18
        $this->voter = new PusherChannelVoter(true, $config);
19
        $this->pusherChannel = new PusherChannel('pusher_test_1', '1234567');
20
    }
21
22
    public function testVote()
23
    {
24
        $user = $this->getTestUser();
25
        $token = $this->getToken();
26
        $token->expects($this->any())
27
            ->method('getUser')
28
            ->will($this->returnValue($user));
29
30
        // Vote should pass
31
        $vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']);
32
        $this->assertEquals(1, $vote);
33
34
        // Unsupported action
35
        // Vote should not pass
36
        $vote = $this->voter->vote($token, $this->pusherChannel, ['sizzle']);
37
        $this->assertEquals(-1, $vote);
38
39
        // Unsupported entity
40
        // Vote should not vote
41
        $vote = $this->voter->vote($token, $user, ['subscribe']);
42
        $this->assertEquals(0, $vote);
43
44
        // Vote should not pass
45
        $user->setSubscribedChannels([]);
46
        $vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']);
47
        $this->assertEquals(-1, $vote);
48
    }
49
}