Skip to content

Commit eeaf8d3

Browse files
committed
test: update ltree type test cases to accept string values and improve assertions
1 parent 4501cb9 commit eeaf8d3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/Integration/MartinGeorgiev/Doctrine/DBAL/Types/DBALTypesTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,17 @@ public function test_ltree_type(string $typeName, string $columnType, mixed $tes
138138
}
139139

140140
/**
141-
* @return array<string, array{string, string, ?LtreeValueObject}>
141+
* @return array<string, array{string, string, LtreeValueObject|string|null}>
142142
*/
143143
public static function provideLtreeTypeTestCases(): array
144144
{
145145
return [
146146
'ltree simple string' => ['ltree', 'LTREE', new LtreeValueObject(['foo', 'bar', 'baz'])],
147+
'ltree from string' => ['ltree', 'LTREE', 'foo.bar.baz'],
147148
'ltree simple numeric' => ['ltree', 'LTREE', new LtreeValueObject(['1', '2', '3'])],
148149
'ltree single numeric' => ['ltree', 'LTREE', new LtreeValueObject(['1'])],
149150
'ltree empty' => ['ltree', 'LTREE', new LtreeValueObject([])],
151+
'ltree null' => ['ltree', 'LTREE', null],
150152
];
151153
}
152154

@@ -224,6 +226,7 @@ private function assertDatabaseRoundtripEquals(mixed $expected, mixed $actual, s
224226
$expected instanceof PointValueObject => $this->assertPointEquals($expected, $actual, $typeName),
225227
$expected instanceof RangeValueObject => $this->assertRangeEquals($expected, $actual, $typeName),
226228
$expected instanceof LtreeValueObject => $this->assertLtreeEquals($expected, $actual, $typeName),
229+
$typeName === 'ltree' && \is_string($expected) => $this->assertLtreeEquals($expected, $actual, $typeName),
227230
\is_array($expected) => $this->assertEquals($expected, $actual, 'Failed asserting that array values are equal for type '.$typeName),
228231
default => $this->assertSame($expected, $actual, 'Failed asserting that values are identical for type '.$typeName)
229232
};
@@ -246,10 +249,10 @@ private function assertRangeEquals(RangeValueObject $rangeValueObject, mixed $ac
246249
$this->assertEquals($rangeValueObject->isEmpty(), $actual->isEmpty(), 'Failed asserting that range empty states are equal for type '.$typeName);
247250
}
248251

249-
private function assertLtreeEquals(LtreeValueObject $ltreeValueObject, mixed $actual, string $typeName): void
252+
private function assertLtreeEquals(LtreeValueObject|string $ltreeValueObject, mixed $actual, string $typeName): void
250253
{
251254
$this->assertInstanceOf(LtreeValueObject::class, $actual, 'Failed asserting that value is a Ltree object for type '.$typeName);
252-
$this->assertTrue($ltreeValueObject->equals($actual), 'Failed asserting that values are equal for type '.$typeName);
255+
$this->assertSame((string) $ltreeValueObject, (string) $actual, 'Failed asserting that ltree string representations are identical for type '.$typeName);
253256
}
254257

255258
private function createLtreeExtension(): void

0 commit comments

Comments
 (0)