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

PusherChannelVoterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
B testVote() 0 27 1
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
}