MessageTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetValue() 0 8 1
A testClone() 0 14 1
A testStatuses() 0 16 1
A getBodyValues() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NotificationBundle\Tests\Entity;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\NotificationBundle\Model\MessageInterface;
18
19
class MessageTest extends TestCase
20
{
21
    /**
22
     * @dataProvider getBodyValues
23
     */
24
    public function testGetValue($body, $names, $expected, $default): void
25
    {
26
        $message = new Message();
27
28
        $message->setBody($body);
29
30
        $this->assertSame($expected, $message->getValue($names, $default));
31
    }
32
33
    public function testClone(): void
34
    {
35
        $message = new Message();
36
        $message->setId(42);
37
        $message->setState(Message::STATE_ERROR);
38
39
        $this->assertTrue($message->isError());
40
        $this->assertSame(42, $message->getId());
41
42
        $newMessage = clone $message;
43
44
        $this->assertTrue($newMessage->isOpen());
45
        $this->assertNull($newMessage->getId());
46
    }
47
48
    public function testStatuses(): void
49
    {
50
        $message = new Message();
51
52
        $message->setState(MessageInterface::STATE_IN_PROGRESS);
53
        $this->assertTrue($message->isRunning());
54
55
        $message->setState(MessageInterface::STATE_CANCELLED);
56
        $this->assertTrue($message->isCancelled());
57
58
        $message->setState(MessageInterface::STATE_ERROR);
59
        $this->assertTrue($message->isError());
60
61
        $message->setState(MessageInterface::STATE_OPEN);
62
        $this->assertTrue($message->isOpen());
63
    }
64
65
    public function getBodyValues(): array
66
    {
67
        return [
68
            [['name' => 'foobar'], ['name'], 'foobar', null],
69
            [['name' => 'foobar'], ['fake'], 'bar', 'bar'],
70
            [['name' => ['foo' => 'bar']], ['name', 'foo'], 'bar', null],
71
        ];
72
    }
73
}
74