CustomerHydratorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 24
c 1
b 0
f 1
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testHydrateNew() 0 4 1
A setUp() 0 3 1
A checkValues() 0 10 1
A testHydrateOld() 0 5 1
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\customer;
12
13
use hiqdev\php\billing\customer\Customer;
14
use hiqdev\yii\DataMapper\tests\unit\BaseHydratorTest;
15
use Zend\Hydrator\HydratorInterface;
16
17
/**
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class CustomerHydratorTest extends BaseHydratorTest
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 = $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...
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