PluginProbe
Packeta / 2.0.3
Packeta v2.0.3
2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 All 55 releases
packeta / tests / Module / EntityFactory / SizeFactoryTest.php

SizeFactoryTest.php in Packeta 2.0.3, at tests/Module/EntityFactory/SizeFactoryTest.php

115 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Tests\Packetery\Module\EntityFactory;
6
7 use Packetery\Core\Entity\Order;
8 use Packetery\Core\Entity\Size;
9 use Packetery\Module\EntityFactory\SizeFactory;
10 use Packetery\Module\Options\OptionsProvider;
11 use PHPUnit\Framework\TestCase;
12
13 class SizeFactoryTest extends TestCase {
14 /**
15 * @dataProvider provideDataForCreateSizeInSetDimensionUnit
16 */
17 public function testCreateSizeInSetDimensionUnit(
18 ?float $length,
19 ?float $width,
20 ?float $height,
21 string $dimensionsUnit,
22 int $decimals,
23 array $expectedResult,
24 ): void {
25 $optionsProvider = $this->createMock( OptionsProvider::class );
26 $optionsProvider->method( 'getDimensionsUnit' )->willReturn( $dimensionsUnit );
27 $optionsProvider->method( 'getDimensionsNumberOfDecimals' )->willReturn( $decimals );
28
29 $sizeFactory = new SizeFactory( $optionsProvider );
30
31 $order = $this->createMock( Order::class );
32 $order->method( 'getLength' )->willReturn( $length );
33 $order->method( 'getWidth' )->willReturn( $width );
34 $order->method( 'getHeight' )->willReturn( $height );
35
36 $result = $sizeFactory->createSizeInSetDimensionUnit( $order );
37
38 $this->assertInstanceOf( Size::class, $result );
39 $this->assertSame( $expectedResult[0], $result->getLength() );
40 $this->assertSame( $expectedResult[1], $result->getWidth() );
41 $this->assertSame( $expectedResult[2], $result->getHeight() );
42 }
43
44 public static function provideDataForCreateSizeInSetDimensionUnit(): array {
45 return [
46 [
47 'width' => 100,
48 'height' => 200,
49 'length' => 300,
50 'unit' => OptionsProvider::DIMENSIONS_UNIT_CM,
51 'decimals' => 1,
52 'expected' => [ 10.0, 20.0, 30.0 ],
53 ],
54 [
55 'width' => 150,
56 'height' => null,
57 'length' => 375,
58 'unit' => OptionsProvider::DIMENSIONS_UNIT_CM,
59 'decimals' => 1,
60 'expected' => [ 15.0, null, 37.5 ],
61 ],
62 [
63 'width' => 100,
64 'height' => 200,
65 'length' => 300,
66 'unit' => OptionsProvider::DEFAULT_DIMENSIONS_UNIT_MM,
67 'decimals' => 0,
68 'expected' => [ 100.0, 200.0, 300.0 ],
69 ],
70 [
71 'width' => 125.5,
72 'height' => 250.7,
73 'length' => 375.9,
74 'unit' => OptionsProvider::DEFAULT_DIMENSIONS_UNIT_MM,
75 'decimals' => 0,
76 'expected' => [ 125.5, 250.7, 375.9 ],
77 ],
78 ];
79 }
80
81 /**
82 * @dataProvider provideDataForCreateDefaultSizeForNewOrder
83 */
84 public function testCreateDefaultSizeForNewOrder(
85 string $dimensionsUnit,
86 float $defaultLength,
87 float $defaultWidth,
88 float $defaultHeight,
89 array $expectedResult
90 ): void {
91 $optionsProvider = $this->createMock( OptionsProvider::class );
92 $optionsProvider->method( 'getDimensionsUnit' )->willReturn( $dimensionsUnit );
93 $optionsProvider->method( 'getDefaultLength' )->willReturn( $defaultLength );
94 $optionsProvider->method( 'getDefaultWidth' )->willReturn( $defaultWidth );
95 $optionsProvider->method( 'getDefaultHeight' )->willReturn( $defaultHeight );
96
97 $sizeFactory = new SizeFactory( $optionsProvider );
98
99 $result = $sizeFactory->createDefaultSizeForNewOrder();
100
101 $this->assertInstanceOf( Size::class, $result );
102 $this->assertSame( $expectedResult[0], $result->getLength() );
103 $this->assertSame( $expectedResult[1], $result->getWidth() );
104 $this->assertSame( $expectedResult[2], $result->getHeight() );
105 }
106
107 public static function provideDataForCreateDefaultSizeForNewOrder(): array {
108 return [
109 [ OptionsProvider::DIMENSIONS_UNIT_CM, 12.5, 25.0, 37.5, [ 125.0, 250.0, 375.0 ] ],
110 [ OptionsProvider::DEFAULT_DIMENSIONS_UNIT_MM, 100.0, 200.0, 300.0, [ 100.0, 200.0, 300.0 ] ],
111 [ OptionsProvider::DEFAULT_DIMENSIONS_UNIT_MM, 125.5, 250.7, 375.9, [ 125.5, 250.7, 375.9 ] ],
112 ];
113 }
114 }
115