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
|
|
|
|