1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Plane\Shop\Tests; |
4
|
|
|
|
5
|
|
|
use Plane\Shop\Product; |
6
|
|
|
use Plane\Shop\PriceFormat\EnglishFormat as PriceFormat; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Product test suite |
10
|
|
|
* |
11
|
|
|
* @author Dariusz Korsak <[email protected]> |
12
|
|
|
* @package Plane\Shop |
13
|
|
|
*/ |
14
|
|
|
class ProductTest extends \PHPUnit\Framework\TestCase |
15
|
|
|
{ |
16
|
|
|
protected $productInput = [ |
17
|
|
|
'id' => '1', |
18
|
|
|
'name' => 'Test product', |
19
|
|
|
'price' => '10', |
20
|
|
|
'weight' => '5', |
21
|
|
|
'quantity' => '4', |
22
|
|
|
'imagePath' => '/path_to_file/file.jpg', |
23
|
|
|
'taxRate' => '0.22', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
protected $productOutput = [ |
27
|
|
|
'id' => '1', |
28
|
|
|
'name' => 'Test product', |
29
|
|
|
'imagePath' => '/path_to_file/file.jpg', |
30
|
|
|
'quantity' => 4, // converted to int |
31
|
|
|
'taxRate' => 0.22, // converted to double |
32
|
|
|
'tax' => 2.2, // converted to double |
33
|
|
|
'price' => 10.0, // converted to double |
34
|
|
|
'weight' => 5.0, // converted to double |
35
|
|
|
'priceWithTax' => 12.2, // converted to double |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
public function testCreateObject() |
39
|
|
|
{ |
40
|
|
|
$product = new Product($this->productInput); |
41
|
|
|
|
42
|
|
|
$this->assertSame($this->productOutput, [ |
43
|
|
|
'id' => $product->getId(), |
44
|
|
|
'name' => $product->getName(), |
45
|
|
|
'imagePath' => $product->getImagePath(), |
46
|
|
|
'quantity' => $product->getQuantity(), |
47
|
|
|
'taxRate' => $product->getTaxRate(), |
48
|
|
|
'tax' => $product->getTax(), |
49
|
|
|
'price' => $product->getPrice(), |
50
|
|
|
'weight' => $product->getWeight(), |
51
|
|
|
'priceWithTax' => $product->getPriceWithTax(), |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testSetPrice() |
56
|
|
|
{ |
57
|
|
|
$product = new Product($this->productInput); |
58
|
|
|
$product->setPrice(123); |
59
|
|
|
|
60
|
|
|
$this->assertSame(123.0, $product->getPrice()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testSetPriceFormat() |
64
|
|
|
{ |
65
|
|
|
$priceFormat = $this->getMockBuilder(PriceFormat::class) |
66
|
|
|
->getMock(); |
67
|
|
|
|
68
|
|
|
$priceFormat->expects($this->any()) |
69
|
|
|
->method('formatPrice') |
70
|
|
|
->willReturn(12.20); |
71
|
|
|
|
72
|
|
|
$product = new Product($this->productInput); |
73
|
|
|
$product->setPriceFormat($priceFormat); |
74
|
|
|
|
75
|
|
|
$this->assertSame(12.20, $product->getPriceWithTax()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testToArray() |
79
|
|
|
{ |
80
|
|
|
$product = new Product($this->productInput); |
81
|
|
|
|
82
|
|
|
$this->assertSame($product->toArray(), $this->productOutput); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|