Skip to content

Commit cda9f1f

Browse files
committed
pointsStruct and pointStruct test improvements
1 parent d29b714 commit cda9f1f

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

tests/Unit/Models/PointStructTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,23 @@ public function testPointStructWithArray(): void
5858
public function testPointStructWithMissingFields(): void
5959
{
6060
$this->expectException(InvalidArgumentException::class);
61+
$this->expectExceptionMessage('Missing point keys');
6162
$points = PointStruct::createFromArray([
6263
'id' => 1,
6364
]);
6465
}
66+
67+
public function testPointStructWithWrongObject(): void
68+
{
69+
$class = new class {
70+
public int $id = 1;
71+
public array $vector = [1, 2, 3];
72+
};
73+
$this->expectException(InvalidArgumentException::class);
74+
$this->expectExceptionMessage('Invalid vector type');
75+
$points = PointStruct::createFromArray([
76+
'id' => 1,
77+
'vector' => $class
78+
]);
79+
}
6580
}

tests/Unit/Models/PointsStructTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,37 @@ public function testPointsStructWithUUid(): void
5555
);
5656
}
5757

58+
public function testAddPointsMethodOfPointsStruct(): void
59+
{
60+
$points = new PointsStruct();
61+
$points->addPoints(
62+
[
63+
new PointStruct(
64+
'550e8400-e29b-41d4-a716-446655440000',
65+
new VectorStruct([1, 2, 3])
66+
),
67+
new PointStruct(
68+
'550e8400-e29b-41d4-a716-446655440001',
69+
new VectorStruct([1, 2, 4])
70+
)
71+
]
72+
);
73+
74+
$this->assertEquals(
75+
[
76+
[
77+
'id' => '550e8400-e29b-41d4-a716-446655440000',
78+
'vector' => [1, 2, 3]
79+
],
80+
[
81+
'id' => '550e8400-e29b-41d4-a716-446655440001',
82+
'vector' => [1, 2, 4]
83+
]
84+
],
85+
$points->toArray()
86+
);
87+
}
88+
5889
public function testPointsStructWithArray(): void
5990
{
6091
$points = PointsStruct::createFromArray([
@@ -109,5 +140,7 @@ public function testPointsStructWithNamedVectors(): void
109140
],
110141
$points->toArray()
111142
);
143+
144+
$this->assertEquals(2, $points->count());
112145
}
113146
}

0 commit comments

Comments
 (0)