Skip to content

Commit 864b6cf

Browse files
committed
Add Importer and Color unit tests
1 parent 1f6c9b8 commit 864b6cf

File tree

9 files changed

+295
-0
lines changed

9 files changed

+295
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
],
1717
"require": {
1818
"php": "^7.1"
19+
},
20+
"require-dev": {
21+
"phpunit/phpunit": "^7.2"
1922
}
2023
}

tests/ColorTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BrickLib\Test;
6+
7+
use BrickLib\Color;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ColorTest extends TestCase
11+
{
12+
/**
13+
* @dataProvider getLddColorData
14+
*/
15+
public function testCreateFromLddColor(int $lddColorNumber, int $expectedBrickLinkColor)
16+
{
17+
$color = Color::fromLddColor($lddColorNumber);
18+
$this->assertEquals($expectedBrickLinkColor, $color->toBrickLinkColor());
19+
}
20+
21+
/**
22+
* @dataProvider getLddCsvStringColorData
23+
*/
24+
public function testCreateFromLddCsvColor(string $lddColor, int $expectedBrickLinkColor)
25+
{
26+
$color = Color::fromLddCsvColor($lddColor);
27+
$this->assertEquals($expectedBrickLinkColor, $color->toBrickLinkColor());
28+
}
29+
30+
public function getLddColorData(): array
31+
{
32+
return [
33+
[1, Color::WHITE],
34+
[5, Color::TAN],
35+
[194, Color::LIGHT_BLUISH_GRAY],
36+
];
37+
}
38+
39+
public function getLddCsvStringColorData(): array
40+
{
41+
return [
42+
['154 - New Dark Red', Color::DARK_RED],
43+
['194 - Medium Stone Grey', Color::LIGHT_BLUISH_GRAY],
44+
['1 - White', Color::WHITE],
45+
['106 - Bright Orange', Color::ORANGE],
46+
];
47+
}
48+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace BrickLib\Test\Importer;
4+
5+
use BrickLib\Importer\LddCsvImporter;
6+
use BrickLib\Lot;
7+
use PHPUnit\Framework\TestCase;
8+
use SplFileInfo;
9+
10+
class LddCsvImporterTest extends TestCase
11+
{
12+
public function testReadRainbowFile()
13+
{
14+
$file = new SplFileInfo(__DIR__ . '/../data/rainbow.csv');
15+
$importer = new LddCsvImporter();
16+
17+
$collection = $importer->readFile($file);
18+
19+
$this->assertCount(16, $collection);
20+
21+
foreach ($collection as $lot) {
22+
/** @var Lot $lot */
23+
24+
// rainbow test file contains only of 16 different 2×4 bricks (3001) in different colors.
25+
$this->assertEquals(1, $lot->getQuantity());
26+
$this->assertEquals('3001', $lot->getBrick()->getDesign()->toBrickLinkDesign());
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace BrickLib\Test\Importer;
4+
5+
use BrickLib\Importer\LxfmlImporter;
6+
use BrickLib\Lot;
7+
use PHPUnit\Framework\TestCase;
8+
use SplFileInfo;
9+
10+
class LxfmlImporterTest extends TestCase
11+
{
12+
public function testReadRainbowFile()
13+
{
14+
$file = new SplFileInfo(__DIR__ . '/../data/rainbow.lxfml');
15+
$importer = new LxfmlImporter();
16+
17+
$collection = $importer->readFile($file);
18+
19+
$this->assertCount(16, $collection);
20+
21+
foreach ($collection as $lot) {
22+
/** @var Lot $lot */
23+
24+
// rainbow test file contains only of 16 different 2×4 bricks (3001) in different colors.
25+
$this->assertEquals(1, $lot->getQuantity());
26+
$this->assertEquals('3001', $lot->getBrick()->getDesign()->toBrickLinkDesign());
27+
}
28+
}
29+
}

tests/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';

tests/data/rainbow.csv

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Brick,Name,Picture,Part,Color code,Quantity
2+
300126,BRICK 2X4,,3001,26 - Black,1
3+
4211085,BRICK 2X4,,3001,199 - Dark Stone Grey,1
4+
4211385,BRICK 2X4,,3001,194 - Medium Stone Grey,1
5+
300101,BRICK 2X4,,3001,1 - White,1
6+
300140,BRICK 2X4,,3001,40 - Transparent,1
7+
4163803,BRICK 2X4,,3001,154 - New Dark Red,1
8+
300121,BRICK 2X4,,3001,21 - Bright Red,1
9+
3001106,BRICK 2X4,,3001,106 - Bright Orange,1
10+
300124,BRICK 2X4,,3001,24 - Bright Yellow,1
11+
300128,BRICK 2X4,,3001,28 - Dark Green,1
12+
300137,BRICK 2X4,,3001,37 - Bright Green,1
13+
4122453,BRICK 2X4,,3001,119 - Bright Yellowish Green,1
14+
4625629,BRICK 2X4,,3001,322 - Medium Azur,1
15+
300123,BRICK 2X4,,3001,23 - Bright Blue,1
16+
4225243,BRICK 2X4,,3001,268 - Medium Lilac,1
17+
4229355,BRICK 2X4,,3001,221 - Bright Purple,1
18+
Total:,,,,,16

tests/data/rainbow.lxf

4.32 KB
Binary file not shown.

tests/data/rainbow.lxfml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2+
<LXFML versionMajor="5" versionMinor="0" name="rainbow.lxf">
3+
<Meta>
4+
<Application name="LEGO Digital Designer" versionMajor="4" versionMinor="3"/>
5+
<Brand name="LDD"/>
6+
<BrickSet version="2670"/>
7+
</Meta>
8+
<Cameras>
9+
<Camera refID="0" fieldOfView="80" distance="62.037513732910156" transformation="0.74887257814407349,0,-0.66271400451660156,-0.45694121718406677,0.72428584098815918,-0.51634758710861206,0.47999432682991028,0.68949991464614868,0.54239773750305176,18.014585494995117,42.632808685302734,35.05120849609375"/>
10+
</Cameras>
11+
<Bricks cameraRef="0">
12+
<Brick refID="0" designID="3001" itemNos="300126">
13+
<Part refID="0" designID="3001" materials="26">
14+
<Bone refID="0" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,12.399999618530273">
15+
</Bone>
16+
</Part>
17+
</Brick>
18+
<Brick refID="1" designID="3001" itemNos="4211085">
19+
<Part refID="1" designID="3001" materials="199">
20+
<Bone refID="1" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,10.800000190734863">
21+
</Bone>
22+
</Part>
23+
</Brick>
24+
<Brick refID="2" designID="3001" itemNos="4211385">
25+
<Part refID="2" designID="3001" materials="194">
26+
<Bone refID="2" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,9.1999998092651367">
27+
</Bone>
28+
</Part>
29+
</Brick>
30+
<Brick refID="3" designID="3001" itemNos="300101">
31+
<Part refID="3" designID="3001" materials="1">
32+
<Bone refID="3" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,7.6000003814697266">
33+
</Bone>
34+
</Part>
35+
</Brick>
36+
<Brick refID="4" designID="3001" itemNos="300140">
37+
<Part refID="4" designID="3001" materials="40">
38+
<Bone refID="4" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,6">
39+
</Bone>
40+
</Part>
41+
</Brick>
42+
<Brick refID="5" designID="3001" itemNos="4163803">
43+
<Part refID="5" designID="3001" materials="154">
44+
<Bone refID="5" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,4.4000000953674316">
45+
</Bone>
46+
</Part>
47+
</Brick>
48+
<Brick refID="6" designID="3001" itemNos="300121">
49+
<Part refID="6" designID="3001" materials="21">
50+
<Bone refID="6" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,2.8000001907348633">
51+
</Bone>
52+
</Part>
53+
</Brick>
54+
<Brick refID="7" designID="3001" itemNos="3001106">
55+
<Part refID="7" designID="3001" materials="106">
56+
<Bone refID="7" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,1.2000000476837158">
57+
</Bone>
58+
</Part>
59+
</Brick>
60+
<Brick refID="8" designID="3001" itemNos="300124">
61+
<Part refID="8" designID="3001" materials="24">
62+
<Bone refID="8" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-0.40000000596046448">
63+
</Bone>
64+
</Part>
65+
</Brick>
66+
<Brick refID="9" designID="3001" itemNos="4122453">
67+
<Part refID="9" designID="3001" materials="119">
68+
<Bone refID="9" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-2">
69+
</Bone>
70+
</Part>
71+
</Brick>
72+
<Brick refID="10" designID="3001" itemNos="300137">
73+
<Part refID="10" designID="3001" materials="37">
74+
<Bone refID="10" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-5.1999998092651367">
75+
</Bone>
76+
</Part>
77+
</Brick>
78+
<Brick refID="11" designID="3001" itemNos="4625629">
79+
<Part refID="11" designID="3001" materials="322">
80+
<Bone refID="11" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-6.8000001907348633">
81+
</Bone>
82+
</Part>
83+
</Brick>
84+
<Brick refID="12" designID="3001" itemNos="300123">
85+
<Part refID="12" designID="3001" materials="23">
86+
<Bone refID="12" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-8.4000005722045898">
87+
</Bone>
88+
</Part>
89+
</Brick>
90+
<Brick refID="13" designID="3001" itemNos="4225243">
91+
<Part refID="13" designID="3001" materials="268">
92+
<Bone refID="13" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-10.000000953674316">
93+
</Bone>
94+
</Part>
95+
</Brick>
96+
<Brick refID="14" designID="3001" itemNos="300128">
97+
<Part refID="14" designID="3001" materials="28">
98+
<Bone refID="14" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-3.5999999046325684">
99+
</Bone>
100+
</Part>
101+
</Brick>
102+
<Brick refID="15" designID="3001" itemNos="4229355">
103+
<Part refID="15" designID="3001" materials="221">
104+
<Bone refID="15" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-11.600000381469727">
105+
</Bone>
106+
</Part>
107+
</Brick>
108+
</Bricks>
109+
<RigidSystems>
110+
<RigidSystem>
111+
<Rigid refID="0" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,12.399999618530273" boneRefs="0"/>
112+
</RigidSystem>
113+
<RigidSystem>
114+
<Rigid refID="1" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,10.800000190734863" boneRefs="1"/>
115+
</RigidSystem>
116+
<RigidSystem>
117+
<Rigid refID="2" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,9.1999998092651367" boneRefs="2"/>
118+
</RigidSystem>
119+
<RigidSystem>
120+
<Rigid refID="3" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,7.6000003814697266" boneRefs="3"/>
121+
</RigidSystem>
122+
<RigidSystem>
123+
<Rigid refID="4" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,6" boneRefs="4"/>
124+
</RigidSystem>
125+
<RigidSystem>
126+
<Rigid refID="5" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,4.4000000953674316" boneRefs="5"/>
127+
</RigidSystem>
128+
<RigidSystem>
129+
<Rigid refID="6" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,2.8000001907348633" boneRefs="6"/>
130+
</RigidSystem>
131+
<RigidSystem>
132+
<Rigid refID="7" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,1.2000000476837158" boneRefs="7"/>
133+
</RigidSystem>
134+
<RigidSystem>
135+
<Rigid refID="8" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-0.40000000596046448" boneRefs="8"/>
136+
</RigidSystem>
137+
<RigidSystem>
138+
<Rigid refID="9" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-2" boneRefs="9"/>
139+
</RigidSystem>
140+
<RigidSystem>
141+
<Rigid refID="10" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-5.1999998092651367" boneRefs="10"/>
142+
</RigidSystem>
143+
<RigidSystem>
144+
<Rigid refID="11" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-6.8000001907348633" boneRefs="11"/>
145+
</RigidSystem>
146+
<RigidSystem>
147+
<Rigid refID="12" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-8.4000005722045898" boneRefs="12"/>
148+
</RigidSystem>
149+
<RigidSystem>
150+
<Rigid refID="13" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-10.000000953674316" boneRefs="13"/>
151+
</RigidSystem>
152+
<RigidSystem>
153+
<Rigid refID="14" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-3.5999999046325684" boneRefs="14"/>
154+
</RigidSystem>
155+
<RigidSystem>
156+
<Rigid refID="15" transformation="1,0,0,0,1,0,0,0,1,-12.40000057220459,0,-11.600000381469727" boneRefs="15"/>
157+
</RigidSystem>
158+
</RigidSystems>
159+
<GroupSystems>
160+
<GroupSystem>
161+
</GroupSystem>
162+
</GroupSystems>
163+
<BuildingInstructions>
164+
</BuildingInstructions>
165+
</LXFML>

tests/data/rainbow.xlsx

54.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)