expectsThreadFound()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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\ThreadProvider;
12
13
use Miliooo\Messaging\ThreadProvider\ThreadProviderSpecificationAware;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
use Miliooo\Messaging\User\ParticipantInterface;
16
17
/**
18
 * Test file for ThreadProviderSpecificationAware
19
 *
20
 * @author Michiel Boeckaert <[email protected]>
21
 */
22
class ThreadProviderSpecificationAwareTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * The class under test
26
     * @var ThreadProviderSpecificationAware
27
     */
28
    private $secureProvider;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    private $canSeeThread;
34
35
    /**
36
     * @var \PHPUnit_Framework_MockObject_MockObject
37
     */
38
    private $threadProvider;
39
40
    /**
41
     * @var \PHPUnit_Framework_MockObject_MockObject
42
     */
43
    private $thread;
44
45
    /**
46
     * @var ParticipantInterface
47
     */
48
    private $participant;
49
50
    public function setUp()
51
    {
52
        $this->canSeeThread = $this->getMockBuilder('Miliooo\Messaging\Specifications\CanSeeThreadSpecification')
53
            ->disableOriginalConstructor()->getMock();
54
        $this->threadProvider = $this->getMock('Miliooo\Messaging\ThreadProvider\ThreadProviderInterface');
55
        $this->secureProvider = new ThreadProviderSpecificationAware($this->threadProvider, $this->canSeeThread);
56
        $this->thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface');
57
        $this->participant = new ParticipantTestHelper(1);
58
    }
59
60
    public function testFindThreadReturnsNullWhenNoSuchThread()
61
    {
62
        $this->threadProvider->expects($this->once())
63
            ->method('findThreadForParticipant')->with(1, $this->participant)
64
            ->will($this->returnValue(null));
65
66
        $this->canSeeThread->expects($this->never())
67
            ->method('isSatisfiedBy');
68
69
        $this->assertNull($this->secureProvider->findThreadForParticipant($this->participant, 1));
70
    }
71
72
    public function testFindThreadSpecReturnsTrue()
73
    {
74
        $this->expectsThreadFound();
75
        $this->canSeeThread->expects($this->once())
76
            ->method('isSatisfiedBy')
77
            ->with($this->participant, $this->thread)
78
            ->will($this->returnValue(true));
79
80
        $this->assertSame($this->thread, $this->secureProvider->findThreadForParticipant($this->participant, 1));
81
    }
82
83
    /**
84
     * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
85
     * @expectedExceptionMessage Not allowed to see this thread
86
     */
87
    public function testFindThreadSpecReturnsFalseThrowsError()
88
    {
89
        $this->expectsThreadFound();
90
        $this->canSeeThread->expects($this->once())
91
            ->method('isSatisfiedBy')
92
            ->with($this->participant, $this->thread)
93
            ->will($this->returnValue(false));
94
95
        $this->secureProvider->findThreadForParticipant($this->participant, 1);
96
    }
97
98
    protected function expectsThreadFound()
99
    {
100
        $this->threadProvider->expects($this->once())
101
            ->method('findThreadForParticipant')->with(1, $this->participant)
102
            ->will($this->returnValue($this->thread));
103
    }
104
}
105