testPagerFantaGetsRightMethodCalls()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 36
rs 8.8571
c 1
b 0
f 1
cc 1
eloc 24
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\Folder;
12
13
use Miliooo\Messaging\ThreadProvider\Folder\OutboxProviderPagerFanta;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
use Miliooo\Messaging\User\ParticipantInterface;
16
17
/**
18
 * Test file for outbox provider pagerfanta
19
 *
20
 * @author Michiel Boeckaert <[email protected]>
21
 */
22
class OutboxProviderPagerFantaTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * @var OutboxProviderPagerFanta
26
     */
27
    private $outboxProviderPf;
28
29
    /**
30
     * @var \PHPUnit_Framework_MockObject_MockObject
31
     */
32
    private $threadRepository;
33
34
    /**
35
     * @var ParticipantInterface
36
     */
37
    private $participant;
38
39
    /**
40
     * @var \PHPUnit_Framework_MockObject_MockObject
41
     */
42
    private $queryBuilderMock;
43
44
    public function setUp()
45
    {
46
        $this->participant = new ParticipantTestHelper(1);
47
        $this->threadRepository = $this->getMock('Miliooo\Messaging\Repository\ThreadRepositoryInterface');
48
        $this->outboxProviderPf = new OutboxProviderPagerFanta($this->threadRepository, 15);
49
        $this->queryBuilderMock =  $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
50
            ->disableOriginalConstructor()
51
            ->getMock();
52
    }
53
54
    public function testInterface()
55
    {
56
        $this->assertInstanceOf(
57
            'Miliooo\Messaging\ThreadProvider\Folder\OutboxProviderPagerFantaInterface',
58
            $this->outboxProviderPf
59
        );
60
    }
61
62
    public function testGetOutboxThreadsReturnsPagerFantaObject()
63
    {
64
        $this->threadRepository
65
            ->expects($this->once())
66
            ->method('getOutboxThreadsForParticipantQueryBuilder')
67
            ->will($this->returnValue($this->queryBuilderMock));
68
69
        $result = $this->outboxProviderPf->getOutboxThreadsPagerfanta($this->participant, 1);
70
        $this->assertInstanceOf('Pagerfanta\Pagerfanta', $result);
71
    }
72
73
    public function testPagerFantaGetsRightMethodCalls()
74
    {
75
        //mock the pagerfanta method
76
        $this->outboxProviderPf =
77
            $this->getMockBuilder('Miliooo\Messaging\ThreadProvider\Folder\OutboxProviderPagerFanta')
78
            ->enableOriginalConstructor()
79
            ->setConstructorArgs([$this->threadRepository, 15])
80
            ->setMethods(['getPagerFanta'])
81
            ->getMock();
82
83
        //thread repository expects querybuilder as return value
84
        $this->threadRepository
85
            ->expects($this->once())
86
            ->method('getOutboxThreadsForParticipantQueryBuilder')
87
            ->will($this->returnValue($this->queryBuilderMock));
88
89
        //mock pagerfanta instance
90
        $pagerfantaMock = $this->getMockBuilder('Pagerfanta\Pagerfanta')
91
            ->disableOriginalConstructor()
92
            ->getMock();
93
94
        //return pagerfanta instance
95
        $this->outboxProviderPf->expects($this->once())
96
            ->method('getPagerFanta')
97
            ->will($this->returnValue($pagerfantaMock));
98
99
        //expectations on pagerfanta
100
        $pagerfantaMock->expects($this->once())
101
            ->method('setMaxPerPage')
102
            ->with(15);
103
        $pagerfantaMock->expects($this->once())
104
            ->method('setCurrentPage')
105
            ->with(2);
106
107
        $this->outboxProviderPf->getOutboxThreadsPagerfanta($this->participant, 2);
108
    }
109
}
110