testGetMessageMetaForParticipantReturnsNullWhenNotFound()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
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\Model;
12
13
use Miliooo\Messaging\Model\Message;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
use Miliooo\Messaging\Model\MessageMeta;
16
17
/**
18
 * Test file for the message model
19
 *
20
 * @author Michiel Boeckaert <[email protected]>
21
 */
22
class MessageTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * The class under test
26
     *
27
     * @var Message
28
     */
29
    private $message;
30
31
    public function setUp()
32
    {
33
        $this->message = $this->getMockForAbstractClass('Miliooo\Messaging\Model\Message');
34
    }
35
36
    public function testInterface()
37
    {
38
        $this->assertInstanceOf('Miliooo\Messaging\Model\MessageInterface', $this->message);
39
    }
40
41
    public function testGetIdDefaultsToNull()
42
    {
43
        $this->assertNull($this->message->getId());
44
    }
45
46
    public function testCreatedAtWorks()
47
    {
48
        $date = new \DateTime('2012-10-03');
49
        $this->message->setCreatedAt($date);
50
        $this->assertSame($date, $this->message->getCreatedAt());
51
    }
52
53
    public function testBodyWorks()
54
    {
55
        $body = 'the body';
56
        $this->message->setBody($body);
57
        $this->assertSame($body, $this->message->getBody());
58
    }
59
60
    public function testSenderWorks()
61
    {
62
        $sender = new ParticipantTestHelper('sender');
63
        $this->message->setSender($sender);
64
        $this->assertSame($sender, $this->message->getSender());
65
    }
66
67
    public function testAddMessageMetaAddsItToTheArrayCollection()
68
    {
69
        $messageMetaMock = $this->getMock('Miliooo\Messaging\Model\MessageMetaInterface');
70
        $this->message->addMessageMeta($messageMetaMock);
71
        $this->assertTrue($this->message->getMessageMeta()->contains($messageMetaMock));
72
    }
73
74
    public function testAddMessageMetaSetsTheCurrentMessage()
75
    {
76
        $messageMetaMock = $this->getMock('Miliooo\Messaging\Model\MessageMetaInterface');
77
        $messageMetaMock->expects($this->once())->method('setMessage')->with($this->message);
78
        $this->message->addMessageMeta($messageMetaMock);
79
    }
80
81
    public function testGetMessageMetaForParticipant()
82
    {
83
        $participant1 = new ParticipantTestHelper(1);
84
        $participant2 = new ParticipantTestHelper(2);
85
86
        $messageMetaMock1 = $this->getNewMessageMeta();
87
        $messageMetaMock1->setParticipant($participant1);
88
89
        $this->message->addMessageMeta($messageMetaMock1);
90
        $messageMetaMock2 = $this->getNewMessageMeta();
91
        $messageMetaMock2->setParticipant($participant2);
92
        $this->message->addMessageMeta($messageMetaMock2);
93
        $this->assertEquals($messageMetaMock2, $this->message->getMessageMetaForParticipant($participant2));
94
    }
95
96
    public function testGetMessageMetaForParticipantReturnsNullWhenNotFound()
97
    {
98
        $participant = new ParticipantTestHelper(100);
99
        $messageMeta = $this->getNewMessageMeta();
100
        $messageMeta->setParticipant($participant);
101
102
        $this->message->addMessageMeta($messageMeta);
103
104
        $participant20 = new ParticipantTestHelper(20);
105
        $this->assertNull($this->message->getMessageMetaForParticipant($participant20));
106
    }
107
108
    public function testThreadWorks()
109
    {
110
        $thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface');
111
        $this->message->setThread($thread);
112
        $this->assertSame($thread, $this->message->getThread());
113
    }
114
115
    /**
116
     * Helper function
117
     *
118
     * @return MessageMeta
119
     */
120
    protected function getNewMessageMeta()
121
    {
122
        return $this->getMockForAbstractClass('Miliooo\Messaging\Model\MessageMeta');
123
    }
124
}
125