|
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
|
|
|
public function testCreateObject() |
|
27
|
|
|
{ |
|
28
|
|
|
$product = new Product($this->productInput); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertSame('1', $product->getId()); |
|
31
|
|
|
$this->assertSame('Test product', $product->getName()); |
|
32
|
|
|
$this->assertSame(10.0, $product->getPrice()); |
|
33
|
|
|
$this->assertSame(5.0, $product->getWeight()); |
|
34
|
|
|
$this->assertSame(4, $product->getQuantity()); |
|
35
|
|
|
$this->assertSame('/path_to_file/file.jpg', $product->getImagePath()); |
|
36
|
|
|
$this->assertSame(0.22, $product->getTaxRate()); |
|
37
|
|
|
$this->assertSame(2.2, $product->getTax()); |
|
38
|
|
|
|
|
39
|
|
|
// due to imprecision of php floats |
|
40
|
|
|
$this->assertEquals(12.2, $product->getPriceWithTax()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testSetPrice() |
|
44
|
|
|
{ |
|
45
|
|
|
$product = new Product($this->productInput); |
|
46
|
|
|
$product->setPrice(123); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertSame(123.0, $product->getPrice()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testSetPriceFormat() |
|
52
|
|
|
{ |
|
53
|
|
|
$priceFormat = $this->getMockBuilder(PriceFormat::class) |
|
54
|
|
|
->getMock(); |
|
55
|
|
|
|
|
56
|
|
|
$priceFormat->expects($this->any()) |
|
57
|
|
|
->method('formatPrice') |
|
58
|
|
|
->willReturn(12.20); |
|
59
|
|
|
|
|
60
|
|
|
$product = new Product($this->productInput); |
|
61
|
|
|
$product->setPriceFormat($priceFormat); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertSame(12.20, $product->getPriceWithTax()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|