1 | <?php |
||
29 | class PriceHydratorTest extends \PHPUnit\Framework\TestCase |
||
30 | { |
||
31 | const ID1 = '11111'; |
||
32 | const CUR1 = 'USD'; |
||
33 | const NAME1 = 'name-11111'; |
||
34 | const TYPE1 = 'server'; |
||
35 | const UNIT1 = 'MB'; |
||
36 | |||
37 | const ID2 = '22222'; |
||
38 | const CUR2 = 'EUR'; |
||
39 | const NAME2 = 'certificate_purchase'; |
||
40 | const TYPE2 = 'certificate'; |
||
41 | const UNIT2 = 'GB'; |
||
42 | |||
43 | protected $dataSinglePrice = [ |
||
44 | 'id' => self::ID1, |
||
45 | 'type' => [ |
||
46 | 'id' => self::ID1, |
||
47 | 'name' => self::NAME1, |
||
48 | ], |
||
49 | 'target' => [ |
||
50 | 'id' => self::ID1, |
||
51 | 'type' => self::TYPE1, |
||
52 | 'name' => self::NAME1, |
||
53 | ], |
||
54 | 'prepaid' => [ |
||
55 | 'quantity' => self::ID1, |
||
56 | 'unit' => self::UNIT1, |
||
57 | ], |
||
58 | 'price' => [ |
||
59 | 'amount' => self::ID1, |
||
60 | 'currency' => self::CUR1, |
||
61 | ], |
||
62 | ]; |
||
63 | |||
64 | protected $dataEnumPrice = [ |
||
65 | 'id' => self::ID2, |
||
66 | 'type' => [ |
||
67 | 'id' => self::ID2, |
||
68 | 'name' => self::NAME2, |
||
69 | ], |
||
70 | 'target' => [ |
||
71 | 'id' => self::ID2, |
||
72 | 'type' => self::TYPE2, |
||
73 | 'name' => self::NAME2, |
||
74 | ], |
||
75 | 'prepaid' => [ |
||
76 | 'unit' => self::UNIT2, |
||
77 | ], |
||
78 | 'price' => [ |
||
79 | 'currency' => self::CUR2, |
||
80 | ], |
||
81 | ]; |
||
82 | |||
83 | protected $sums = [ |
||
84 | 1 => self::ID1, |
||
85 | 2 => self::ID2, |
||
86 | ]; |
||
87 | |||
88 | public function setUp() |
||
89 | { |
||
90 | $this->hydrator = Yii::$container->get(HydratorInterface::class); |
||
91 | $this->dataEnumPrice['data'] = Json::encode(['sums' => $this->sums]); |
||
92 | } |
||
93 | |||
94 | public function testHydrateNewSinglePrice() |
||
99 | |||
100 | public function testHydrateExistingSinglePrice() |
||
101 | { |
||
102 | $type = new Type(self::ID2, self::NAME2); |
||
103 | $target = new Target(self::ID2, self::TYPE2, self::NAME2); |
||
104 | $price = new Money(self::ID2, new Currency(self::CUR2)); |
||
105 | $prepaid = Quantity::create(self::ID2, Unit::create(self::UNIT2)); |
||
106 | $obj = new SinglePrice(self::ID2, $type, $target, null, $prepaid, $price); |
||
107 | $this->hydrator->hydrate($this->dataSinglePrice, $obj); |
||
108 | $this->checkSinglePrice($obj); |
||
109 | } |
||
110 | |||
111 | public function checkSinglePrice($obj) |
||
137 | |||
138 | public function testHydrateNewEnumPrice() |
||
143 | |||
144 | public function testHydrateExistingEnumPrice() |
||
145 | { |
||
146 | $type = new Type(self::ID2, self::NAME2); |
||
147 | $target = new Target(self::ID2, self::TYPE2, self::NAME2); |
||
148 | $currency = new Currency(self::CUR2); |
||
149 | $unit = Unit::create(self::UNIT2); |
||
150 | $sums = array_reverse($this->sums); |
||
151 | $obj = new EnumPrice(self::ID2, $type, $target, null, $unit, $currency, $sums); |
||
152 | $this->hydrator->hydrate($this->dataEnumPrice, $obj); |
||
153 | $this->checkEnumPrice($obj); |
||
154 | } |
||
155 | |||
156 | public function checkEnumPrice($obj) |
||
181 | } |
||
182 |