Completed
Push — 2.x-dev-kit ( 8d77e1 )
by
unknown
28:22 queued 25:50
created

MessageTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

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