DeleteThreadManagerSpecificationAwareTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testInterface() 0 7 1
A testDeleteThreadSpecificationReturnsTrue() 0 11 1
A testDeleteThreadSpecificationReturnsFalse() 0 11 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\Manager;
12
13
use Miliooo\Messaging\Manager\DeleteThreadManagerSpecificationAware;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
use Miliooo\Messaging\User\ParticipantInterface;
16
17
/**
18
 * Test file for deleteThreadManagerSpecificationAware
19
 *
20
 * @author Michiel Boeckaert <[email protected]>
21
 */
22
class DeleteThreadManagerSpecificationAwareTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * Class under test.
26
     *
27
     * @var DeleteThreadManagerSpecificationAware
28
     */
29
    private $deleteThreadManagerSpecAware;
30
31
    /**
32
     * @var \PHPUnit_Framework_MockObject_MockObject
33
     */
34
    private $deleteThreadManager;
35
36
    /**
37
     * @var ParticipantInterface
38
     */
39
    private $participant;
40
41
    /**
42
     * @var \PHPUnit_Framework_MockObject_MockObject
43
     */
44
    private $thread;
45
46
    /**
47
     * @var \PHPUnit_Framework_MockObject_MockObject
48
     */
49
    private $canDeleteThread;
50
51
    public function setUp()
52
    {
53
        $this->deleteThreadManager = $this->getMock('Miliooo\Messaging\Manager\DeleteThreadManagerInterface');
54
        $this->canDeleteThread = $this->getMockBuilder('Miliooo\Messaging\Specifications\CanDeleteThreadSpecification')
55
            ->disableOriginalConstructor()->getMock();
56
57
        $this->deleteThreadManagerSpecAware = new DeleteThreadManagerSpecificationAware(
58
            $this->deleteThreadManager,
59
            $this->canDeleteThread
60
        );
61
62
        $this->participant = new ParticipantTestHelper(1);
63
        $this->thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface');
64
    }
65
66
    public function testInterface()
67
    {
68
        $this->assertInstanceOf(
69
            'Miliooo\Messaging\Manager\DeleteThreadManagerSecureInterface',
70
            $this->deleteThreadManagerSpecAware
71
        );
72
    }
73
74
    public function testDeleteThreadSpecificationReturnsTrue()
75
    {
76
        $this->canDeleteThread->expects($this->once())->method('isSatisfiedBy')
77
            ->with($this->participant, $this->thread)
78
            ->will($this->returnValue(true));
79
80
        $this->deleteThreadManager->expects($this->once())
81
            ->method('deleteThread')->with($this->thread);
82
83
        $this->deleteThreadManagerSpecAware->deleteThread($this->participant, $this->thread);
84
    }
85
86
    /**
87
     * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
88
     * @expectedExceptionMessage not authorised to delete this thread
89
     */
90
    public function testDeleteThreadSpecificationReturnsFalse()
91
    {
92
        $this->canDeleteThread->expects($this->once())->method('isSatisfiedBy')
93
            ->with($this->participant, $this->thread)
94
            ->will($this->returnValue(false));
95
96
        $this->deleteThreadManager->expects($this->never())
97
            ->method('deleteThread');
98
99
        $this->deleteThreadManagerSpecAware->deleteThread($this->participant, $this->thread);
100
    }
101
}
102