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

MessageTest::testStatuses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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