Completed
Push — master ( a2fd0b...cb4835 )
by Andrii
02:30
created

TargetHydratorTest::testHydrateOld()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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\target;
12
13
use hiqdev\php\billing\target\Target;
14
use Yii;
15
use Zend\Hydrator\HydratorInterface;
16
17
/**
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class TargetHydratorTest extends \PHPUnit\Framework\TestCase
21
{
22
    const ID1 = 11111;
23
    const TYPE1 = 'type-11111';
24
    const NAME1 = 'name-11111';
25
26
    const ID2 = 22222;
27
    const TYPE2 = 'type-22222';
28
    const NAME2 = 'name-22222';
29
30
    protected $data = [
31
        'id'        => self::ID1,
32
        'type'      => self::TYPE1,
33
        'name'      => self::NAME1,
34
    ];
35
36
    public function setUp()
37
    {
38
        $this->hydrator = Yii::$container->get(HydratorInterface::class);
39
    }
40
41
    public function testHydrateNew()
42
    {
43
        $obj = $this->hydrator->hydrate($this->data, Target::class);
44
        $this->checkValues($obj);
45
    }
46
47
    public function testHydrateOld()
48
    {
49
        $obj = new Target(self::ID2, self::TYPE2, self::NAME2);
50
        $this->hydrator->hydrate($this->data, $obj);
51
        $this->checkValues($obj);
52
    }
53
54
    public function checkValues($obj)
55
    {
56
        $this->assertInstanceOf(Target::class, $obj);
57
        $this->assertSame(self::ID1, $obj->getId());
58
        $this->assertSame(self::TYPE1, $obj->getType());
59
        $this->assertSame(self::NAME1, $obj->getName());
60
    }
61
}
62