Completed
Branch 2.x (c99d86)
by Julián
08:01
created

NotificationTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 54
rs 10
c 1
b 1
f 0
1
<?php
2
3
/*
4
 * Unified push notification services abstraction (http://github.com/juliangut/tify).
5
 *
6
 * @license BSD-3-Clause
7
 * @link https://github.com/juliangut/tify
8
 * @author Julián Gutiérrez <[email protected]>
9
 */
10
11
namespace Jgut\Tify\Tests\Notification;
12
13
use Jgut\Tify\Message;
14
use Jgut\Tify\Notification;
15
use Jgut\Tify\Receiver\AbstractReceiver;
16
17
/**
18
 * Notification tests.
19
 */
20
class NotificationTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var Message
24
     */
25
    protected $message;
26
27
    /**
28
     * @var Notification
29
     */
30
    protected $notification;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function setUp()
36
    {
37
        $this->message = $this->getMockBuilder(Message::class)
38
            ->disableOriginalConstructor()
39
            ->getMock();
40
        $receiver = $this->getMockForAbstractClass(AbstractReceiver::class, [], '', false);
41
42
        $this->notification = $this->getMockForAbstractClass(
43
            Notification::class,
44
            [$this->message, $receiver]
45
        );
46
    }
47
48
    public function testDefaults()
49
    {
50
        self::assertEquals($this->message, $this->notification->getMessage());
51
        self::assertCount(1, $this->notification->getReceivers());
52
    }
53
54
    /**
55
     * @expectedException \InvalidArgumentException
56
     */
57
    public function testInvalidParameter()
58
    {
59
        $this->notification->setParameter('made-up-parameter', true);
60
    }
61
62
    public function testMessage()
63
    {
64
        /* @var Message $message */
65
        $message = $this->getMockBuilder(Message::class)
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
        $this->notification->setMessage($message);
69
        self::assertEquals($message, $this->notification->getMessage());
70
    }
71
72
    public function testReceivers()
73
    {
74
        $receiver = $this->getMockForAbstractClass(AbstractReceiver::class, [], '', false);
75
        $this->notification->addReceiver($receiver);
76
        self::assertCount(2, $this->notification->getReceivers());
77
78
        $this->notification->clearReceivers();
79
        self::assertCount(0, $this->notification->getReceivers());
80
    }
81
}
82