ParticipantProviderSecurityTokenTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testInterface() 0 4 1
A testGetAuthenticatedParticipantTokenReturnsString() 0 5 1
A testGetAuthenticatedParticpantReturnsObjectNotInstanceParticipantInterface() 0 6 1
A testGetAuthenticatedParticipantReturnsParticipant() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\Messaging\Tests\User;
12
13
use Miliooo\Messaging\User\ParticipantProviderSecurityToken;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
16
/**
17
 * Test file for Miliooo\Messaging\User\ParticipantProviderSecurityToken
18
 *
19
 * @author Michiel Boeckaert <[email protected]>
20
 */
21
class ParticipantProviderSecurityTokenTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * The class under test
25
     *
26
     * @var ParticipantProviderSecurityToken
27
     */
28
    private $participantProvider;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    private $securityToken;
34
35
    public function setUp()
36
    {
37
        $this->securityToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
38
        $this->participantProvider = new ParticipantProviderSecurityToken($this->securityToken);
39
    }
40
41
    public function testInterface()
42
    {
43
        $this->assertInstanceOf('Miliooo\Messaging\User\ParticipantProviderInterface', $this->participantProvider);
44
    }
45
46
    /**
47
     * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
48
     * @expectedExceptionMessage You must be logged in with a participant interface
49
     */
50
    public function testGetAuthenticatedParticipantTokenReturnsString()
51
    {
52
        $this->securityToken->expects($this->once())->method('getUser')->will($this->returnValue('anon'));
53
        $this->participantProvider->getAuthenticatedParticipant();
54
    }
55
56
     /**
57
     * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
58
     * @expectedExceptionMessage You must be logged in with a participant interface
59
     */
60
    public function testGetAuthenticatedParticpantReturnsObjectNotInstanceParticipantInterface()
61
    {
62
        $obj = new \stdClass;
63
        $this->securityToken->expects($this->once())->method('getUser')->will($this->returnValue($obj));
64
        $this->participantProvider->getAuthenticatedParticipant();
65
    }
66
67
    public function testGetAuthenticatedParticipantReturnsParticipant()
68
    {
69
        $loggedInUser = new ParticipantTestHelper('user');
70
        $this->securityToken->expects($this->once())->method('getUser')
71
            ->will($this->returnValue($loggedInUser));
72
        $this->assertEquals($loggedInUser, $this->participantProvider->getAuthenticatedParticipant());
73
    }
74
}
75