ThreadProviderTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testInterface() 0 4 1
A testFindThreadByIdWithExistingThreadReturnsThread() 0 11 1
A testFindThreadByIdWithNonExistingThreadReturnsNull() 0 10 1
A testFindThreadForParticipantNoThreadFound() 0 12 1
A testFindThreadForParticipantThreadFound() 0 13 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\ThreadProvider;
12
13
use Miliooo\Messaging\ThreadProvider\ThreadProvider;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
16
/**
17
 * Test file for Miliooo\Messaging\ThreadProvider\ThreadProvider
18
 *
19
 * @author Michiel Boeckaert <[email protected]>
20
 */
21
class ThreadProviderTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * The class under test
25
     *
26
     * @var ThreadProvider
27
     */
28
    protected $provider;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    protected $threadRepository;
34
35
    public function setUp()
36
    {
37
        $this->threadRepository = $this->getMock('Miliooo\Messaging\Repository\ThreadRepositoryInterface');
38
        $this->provider = new ThreadProvider($this->threadRepository);
39
    }
40
41
    public function testInterface()
42
    {
43
        $this->assertInstanceOf('Miliooo\Messaging\ThreadProvider\ThreadProviderInterface', $this->provider);
44
    }
45
46
    public function testFindThreadByIdWithExistingThreadReturnsThread()
47
    {
48
        $threadMock = $this->getMock('Miliooo\Messaging\Model\ThreadInterface');
49
        $this->threadRepository
50
            ->expects($this->once())
51
            ->method('findThread')
52
            ->with(1)
53
            ->will($this->returnValue($threadMock));
54
55
        $this->assertSame($threadMock, $this->provider->findThreadById(1));
56
    }
57
58
    public function testFindThreadByIdWithNonExistingThreadReturnsNull()
59
    {
60
        $this->threadRepository
61
            ->expects($this->once())
62
            ->method('findThread')
63
            ->with(1)
64
            ->will($this->returnValue(null));
65
66
        $this->assertNull($this->provider->findThreadById(1));
67
    }
68
69
    public function testFindThreadForParticipantNoThreadFound()
70
    {
71
        $participant = new ParticipantTestHelper('1');
72
73
        $this->threadRepository
74
            ->expects($this->once())
75
            ->method('findThreadForParticipant')
76
            ->with(1, $participant)
77
            ->will($this->returnValue(null));
78
79
        $this->assertNull($this->provider->findThreadForParticipant(1, $participant));
80
    }
81
82
    public function testFindThreadForParticipantThreadFound()
83
    {
84
        $participant = new ParticipantTestHelper('1');
85
        $threadMock = $this->getMock('Miliooo\Messaging\Model\ThreadInterface');
86
87
        $this->threadRepository
88
            ->expects($this->once())
89
            ->method('findThreadForParticipant')
90
            ->with(1, $participant)
91
            ->will($this->returnValue($threadMock));
92
93
        $this->assertSame($threadMock, $this->provider->findThreadForParticipant(1, $participant));
94
    }
95
}
96