ItemTest::testToArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
namespace Wonnova\SDK\Test\Model;
3
4
use PHPUnit_Framework_TestCase as TestCase;
5
use Wonnova\SDK\Model\Item;
6
7
/**
8
 * Class ItemTest
9
 * @author Wonnova
10
 * @link http://www.wonnova.com
11
 */
12
class ItemTest extends TestCase
13
{
14
    /**
15
     * @var Item
16
     */
17
    private $item;
18
19
    public function setUp()
20
    {
21
        $this->item = new Item();
22
    }
23
24
    public function testItemId()
25
    {
26
        $expected = 'item123';
27
        $this->assertNull($this->item->getItemId());
28
        $this->assertSame($this->item, $this->item->setItemId($expected));
29
        $this->assertEquals($expected, $this->item->getItemId());
30
    }
31
32
    public function testTitle()
33
    {
34
        $expected = 'The Item';
35
        $this->assertNull($this->item->getTitle());
36
        $this->assertSame($this->item, $this->item->setTitle($expected));
37
        $this->assertEquals($expected, $this->item->getTitle());
38
    }
39
40 View Code Duplication
    public function testDescription()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $expected = 'The Item\'s description';
43
        $this->assertNull($this->item->getDescription());
44
        $this->assertSame($this->item, $this->item->setDescription($expected));
45
        $this->assertEquals($expected, $this->item->getDescription());
46
    }
47
48
    public function testAuthor()
49
    {
50
        $expected = 'john.doe';
51
        $this->assertNull($this->item->getAuthor());
52
        $this->assertSame($this->item, $this->item->setAuthor($expected));
53
        $this->assertEquals($expected, $this->item->getAuthor());
54
    }
55
56
    public function testScore()
57
    {
58
        $expected = 25;
59
        $this->assertNull($this->item->getScore());
60
        $this->assertSame($this->item, $this->item->setScore($expected));
61
        $this->assertEquals($expected, $this->item->getScore());
62
    }
63
64 View Code Duplication
    public function testDateCreated()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $expected = new \DateTime();
67
        $this->assertNull($this->item->getDateCreated());
68
        $this->assertSame($this->item, $this->item->setDateCreated($expected));
69
        $this->assertSame($expected, $this->item->getDateCreated());
70
71
        $this->item->setDateCreated('2010-01-01 00:00:00');
72
        $this->assertInstanceOf('DateTime', $this->item->getDateCreated());
73
    }
74
75
    public function testToArray()
76
    {
77
        $data = [
78
            'id' => 'item123',
79
            'title' => 'The Item',
80
            'description' => 'The Item\'s description',
81
            'author' => 'john.doe',
82
            'dateCreated' => '2010-01-01 00:00:00'
83
        ];
84
        $this->item->fromArray($data);
85
        $itemArray = $this->item->toArray();
86
87
        $this->assertCount(4, $itemArray);
88
        unset($data['dateCreated']);
89
        $this->assertEquals($data, $itemArray);
90
    }
91
}
92