MessageTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 120
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 5 1
A withPriority() 0 6 1
A getPriority() 0 5 1
A withEarliestGet() 0 6 1
A getPayload() 0 5 1
A getEarliestGet() 0 5 1
A withPayload() 0 6 1
A withNaNPriority() 0 5 1
A constructWithNaNPriority() 0 5 1
1
<?php
2
namespace TraderInteractiveTest\Mongo;
3
4
use MongoDB\BSON\ObjectId;
5
use MongoDB\BSON\UTCDateTime;
6
use PHPUnit\Framework\TestCase;
7
use TraderInteractive\Mongo\Message;
8
9
/**
10
 * @coversDefaultClass TraderInteractive\Mongo\Message
11
 * @covers ::__construct
12
 * @covers ::<private>
13
 */
14
class MessageTest extends TestCase
15
{
16
    /**
17
     * @test
18
     * @covers ::getId
19
     *
20
     * @return void
21
     */
22
    public function getId()
23
    {
24
        $id = new ObjectId();
25
        $message = new Message($id);
26
        $this->assertSame($id, $message->getId());
27
    }
28
29
    /**
30
     * @test
31
     * @covers ::getPayload
32
     *
33
     * @return void
34
     */
35
    public function getPayload()
36
    {
37
        $payload = ['key' => 'value'];
38
        $message = new Message(null, $payload);
39
        $this->assertSame($payload, $message->getPayload());
40
    }
41
42
    /**
43
     * @test
44
     * @covers ::withPayload
45
     *
46
     * @return void
47
     */
48
    public function withPayload()
49
    {
50
        $payload = ['key' => 'value'];
51
        $message = new Message();
52
        $this->assertNotSame($payload, $message->getPayload());
53
        $this->assertSame($payload, $message->withPayload($payload)->getPayload());
54
    }
55
56
    /**
57
     * @test
58
     * @covers ::getEarliestGet
59
     *
60
     * @return void
61
     */
62
    public function getEarliestGet()
63
    {
64
        $earliestGet = new UTCDateTime();
65
        $message = new Message(null, [], $earliestGet);
66
        $this->assertSame($earliestGet, $message->getEarliestGet());
67
    }
68
69
    /**
70
     * @test
71
     * @covers ::withEarliestGet
72
     *
73
     * @return void
74
     */
75
    public function withEarliestGet()
76
    {
77
        $earliestGet = new UTCDateTime();
78
        $message = new Message();
79
        $this->assertNotSame($earliestGet, $message->getEarliestGet());
80
        $this->assertSame($earliestGet, $message->withEarliestGet($earliestGet)->getEarliestGet());
81
    }
82
83
    /**
84
     * @test
85
     * @covers ::getPriority
86
     *
87
     * @return void
88
     */
89
    public function getPriority()
90
    {
91
        $priority = 1.0;
92
        $message = new Message(null, [], null, $priority);
93
        $this->assertSame($priority, $message->getPriority());
94
    }
95
96
    /**
97
     * @test
98
     * @covers ::withPriority
99
     *
100
     * @return void
101
     */
102
    public function withPriority()
103
    {
104
        $priority = 1.0;
105
        $message = new Message();
106
        $this->assertNotSame($priority, $message->getPriority());
107
        $this->assertSame($priority, $message->withPriority($priority)->getPriority());
108
    }
109
110
    /**
111
     * @test
112
     * @covers ::__construct
113
     *
114
     * @return void
115
     */
116
    public function constructWithNaNPriority()
117
    {
118
        $this->expectException(\InvalidArgumentException::class);
119
        $this->expectExceptionMessage('$priority was NaN');
120
        new Message(null, [], null, NAN);
121
    }
122
123
    /**
124
     * @test
125
     * @covers ::withPriority
126
     *
127
     * @return void
128
     */
129
    public function withNaNPriority()
130
    {
131
        $this->expectException(\InvalidArgumentException::class);
132
        $this->expectExceptionMessage('$priority was NaN');
133
        (new Message())->withPriority(NAN);
134
    }
135
}
136