TypeHydratorTest::testHydrateNew()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\tests\unit\type;
12
13
use hiqdev\php\billing\type\Type;
14
use hiqdev\yii\DataMapper\tests\unit\BaseHydratorTest;
15
use Zend\Hydrator\HydratorInterface;
16
17
/**
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class TypeHydratorTest extends BaseHydratorTest
21
{
22
    const ID1 = 11111;
23
    const NAME1 = 'login11111';
24
25
    const ID2 = 22222;
26
    const NAME2 = 'login22222';
27
28
    protected $data = [
29
        'id'        => self::ID1,
30
        'name'      => self::NAME1,
31
    ];
32
33
    public function setUp()
34
    {
35
        $this->hydrator = $this->getHydrator();
0 ignored issues
show
Bug Best Practice introduced by
The property hydrator does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
36
    }
37
38
    public function testHydrateNew()
39
    {
40
        $obj = $this->hydrator->hydrate($this->data, Type::class);
41
        $this->checkValues($obj);
42
    }
43
44
    public function testHydrateOld()
45
    {
46
        $obj = new Type(self::ID2, self::NAME2);
47
        $this->hydrator->hydrate($this->data, $obj);
48
        $this->checkValues($obj);
49
    }
50
51
    public function checkValues($obj)
52
    {
53
        $this->assertInstanceOf(Type::class, $obj);
54
        $this->assertSame(self::ID1, $obj->getId());
55
        $this->assertSame(self::NAME1, $obj->getName());
56
    }
57
}
58