Completed
Push — master ( 02c633...4b996c )
by Andrii
01:55
created

CustomerHydratorTest::testHydrateNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\tests\unit\customer;
12
13
use hiqdev\php\billing\customer\Customer;
14
use Yii;
15
use Zend\Hydrator\HydratorInterface;
16
17
/**
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class CustomerHydratorTest extends \PHPUnit\Framework\TestCase
21
{
22
    const ID1 = 11111;
23
    const LOGIN1 = 'login11111';
24
25
    const ID2 = 22222;
26
    const LOGIN2 = 'login22222';
27
28
    protected $data = [
29
        'id'        => self::ID1,
30
        'login'     => self::LOGIN1,
31
        'seller'    => [
32
            'id'        => self::ID2,
33
            'login'     => self::LOGIN2,
34
        ],
35
    ];
36
37
    public function setUp()
38
    {
39
        $this->hydrator = Yii::$container->get(HydratorInterface::class);
40
    }
41
42
    public function testHydrateNew()
43
    {
44
        $obj = $this->hydrator->hydrate($this->data, Customer::class);
45
        $this->checkValues($obj);
46
    }
47
48
    public function testHydrateOld()
49
    {
50
        $obj = new Customer(self::ID2, self::LOGIN2);
51
        $this->hydrator->hydrate($this->data, $obj);
52
        $this->checkValues($obj);
53
    }
54
55
    public function checkValues($obj)
56
    {
57
        $this->assertInstanceOf(Customer::class, $obj);
58
        $this->assertSame(self::ID1, $obj->getId());
59
        $this->assertSame(self::LOGIN1, $obj->getLogin());
60
61
        $seller = $obj->getSeller();
62
        $this->assertInstanceOf(Customer::class, $seller);
63
        $this->assertSame(self::ID2, $seller->getId());
64
        $this->assertSame(self::LOGIN2, $seller->getLogin());
65
    }
66
}
67