Completed
Push — master ( cb4835...b23375 )
by Andrii
03:01
created

MoneyHydratorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\vo;
12
13
use Money\Currency;
14
use Money\Money;
15
use Yii;
16
use Zend\Hydrator\HydratorInterface;
17
18
/**
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21 View Code Duplication
class MoneyHydratorTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 = Yii::$container->get(HydratorInterface::class);
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