Code Duplication    Length = 38-38 lines in 2 locations

tests/unit/type/TypeHydratorTest.php 1 location

@@ 20-57 (lines=38) @@
17
/**
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class TypeHydratorTest extends \PHPUnit\Framework\TestCase
21
{
22
    const ID1 = 11111;
23
    const NAME1 = 'login11111';
24
25
    const ID2 = 22222;
26
    const NAME2 = 'login22222';
27
28
    protected $data = [
29
        'id'        => self::ID1,
30
        'name'      => self::NAME1,
31
    ];
32
33
    public function setUp()
34
    {
35
        $this->hydrator = Yii::$container->get(HydratorInterface::class);
36
    }
37
38
    public function testHydrateNew()
39
    {
40
        $obj = $this->hydrator->hydrate($this->data, Type::class);
41
        $this->checkValues($obj);
42
    }
43
44
    public function testHydrateOld()
45
    {
46
        $obj = new Type(self::ID2, self::NAME2);
47
        $this->hydrator->hydrate($this->data, $obj);
48
        $this->checkValues($obj);
49
    }
50
51
    public function checkValues($obj)
52
    {
53
        $this->assertInstanceOf(Type::class, $obj);
54
        $this->assertSame(self::ID1, $obj->getId());
55
        $this->assertSame(self::NAME1, $obj->getName());
56
    }
57
}
58

tests/unit/vo/MoneyHydratorTest.php 1 location

@@ 21-58 (lines=38) @@
18
/**
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class MoneyHydratorTest extends \PHPUnit\Framework\TestCase
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