|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Test\Pagantis\OrdersApiClient\Model\Order\ShoppingCart; |
|
4
|
|
|
|
|
5
|
|
|
use Faker\Factory; |
|
6
|
|
|
use Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details; |
|
7
|
|
|
use Test\Pagantis\OrdersApiClient\AbstractTest; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Details |
|
11
|
|
|
* @package Test\Pagantis\OrdersApiClient\Model\Order\ShoppingCart |
|
12
|
|
|
*/ |
|
13
|
|
|
class DetailsTest extends AbstractTest |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* testConstructor |
|
17
|
|
|
*/ |
|
18
|
|
|
public function testConstructor() |
|
19
|
|
|
{ |
|
20
|
|
|
$details = new Details(); |
|
21
|
|
|
$this->assertTrue(is_array($details->getProducts())); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* testAddProduct |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testAddProduct() |
|
28
|
|
|
{ |
|
29
|
|
|
$details = new Details(); |
|
30
|
|
|
$product = $this->getMock( |
|
31
|
|
|
'Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product' |
|
32
|
|
|
); |
|
33
|
|
|
$details->addProduct($product); |
|
34
|
|
|
$products = $details->getProducts(); |
|
35
|
|
|
$this->assertTrue(is_array($products)); |
|
36
|
|
|
if (count($products) !== 1) { |
|
37
|
|
|
$exception = new \Exception('Product should have 1 element'); |
|
38
|
|
|
$this->throwException($exception); |
|
39
|
|
|
} |
|
40
|
|
|
$products = $details->getProducts(); |
|
41
|
|
|
$productFromDetails = array_pop($products); |
|
42
|
|
|
$this->assertSame($productFromDetails, $product); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* testShippingCost |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testShippingCost() |
|
49
|
|
|
{ |
|
50
|
|
|
$faker = Factory::create(); |
|
51
|
|
|
$number = $faker->randomDigitNotNull; |
|
52
|
|
|
$details = new Details(); |
|
53
|
|
|
$details->setShippingCost($number); |
|
54
|
|
|
$this->assertEquals($details->getShippingCost(), $number); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* test Import |
|
59
|
|
|
* @throws \Exception |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testImport() |
|
62
|
|
|
{ |
|
63
|
|
|
$orderJson = file_get_contents($this->resourcePath.'Order.json'); |
|
64
|
|
|
$object = json_decode($orderJson); |
|
65
|
|
|
$object = $object->shopping_cart->details; |
|
66
|
|
|
$details = new Details(); |
|
67
|
|
|
$details->import($object); |
|
68
|
|
|
$products = $details->getProducts(); |
|
69
|
|
|
$this->assertSame($object->shipping_cost, $details->getShippingCost()); |
|
70
|
|
|
$this->assertSame(count($object->products), count($details->getProducts())); |
|
71
|
|
|
|
|
72
|
|
|
foreach ($object->products as $key => $product) { |
|
73
|
|
|
/** @var Details\Product $detailsProduct */ |
|
74
|
|
|
$detailsProduct = $products[$key]; |
|
75
|
|
|
$this->assertSame($product->amount, $detailsProduct->getAmount()); |
|
76
|
|
|
$this->assertSame($product->description, $detailsProduct->getDescription()); |
|
77
|
|
|
$this->assertSame($product->quantity, $detailsProduct->getQuantity()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
//Finally test that the result of the export == the import |
|
81
|
|
|
$this->assertEquals($object, json_decode(json_encode($details->export()))); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|