MoneyHydratorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testHydrateNew() 0 4 1
A testHydrateOld() 0 5 1
A checkValues() 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\vo;
12
13
use hiqdev\yii\DataMapper\tests\unit\BaseHydratorTest;
14
use Money\Currency;
15
use Money\Money;
16
use Zend\Hydrator\HydratorInterface;
17
18
/**
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class MoneyHydratorTest extends BaseHydratorTest
22
{
23
    const AMOUNT1 = '11111';
24
    const CURRENCY1 = 'USD';
25
26
    const AMOUNT2 = '22222';
27
    const CURRENCY2 = 'EUR';
28
29
    protected $data = [
30
        'amount'    => self::AMOUNT1,
31
        'currency'  => self::CURRENCY1,
32
    ];
33
34
    public function setUp()
35
    {
36
        $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...
37
    }
38
39
    public function testHydrateNew()
40
    {
41
        $obj = $this->hydrator->hydrate($this->data, Money::class);
42
        $this->checkValues($obj);
43
    }
44
45
    public function testHydrateOld()
46
    {
47
        $obj = new Money(self::AMOUNT2, new Currency(self::CURRENCY2));
48
        $obj = $this->hydrator->hydrate($this->data, $obj);
49
        $this->checkValues($obj);
50
    }
51
52
    public function checkValues($obj)
53
    {
54
        $this->assertInstanceOf(Money::class, $obj);
55
        $this->assertSame(self::AMOUNT1, $obj->getAmount());
56
        $this->assertSame(self::CURRENCY1, $obj->getCurrency()->getCode());
57
    }
58
}
59