Skip to content

Commit 9d5c6a3

Browse files
committed
Fix test on Binary vector
1 parent 0529a48 commit 9d5c6a3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/VectorSearchTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Documents\User;
1212
use Documents\VectorEmbedding;
1313
use MongoDB\BSON\Binary;
14+
use MongoDB\BSON\VectorType;
15+
16+
use function enum_exists;
1417

1518
class VectorSearchTest extends BaseTestCase
1619
{
@@ -80,8 +83,15 @@ public function testQueryVector(): void
8083

8184
public function testQueryVectorAcceptsBinary(): void
8285
{
83-
[$stage] = $this->createVectorSearchStage();
84-
$binaryVector = new Binary("\x01\x02\x03", 9);
86+
[$stage] = $this->createVectorSearchStage();
87+
if (enum_exists(VectorType::class)) {
88+
// @phpstan-ignore staticMethod.notFound (requires ext-mongodb 2.2+)
89+
$binaryVector = Binary::fromVector([1, 2, 3], VectorType::Int8);
90+
self::assertInstanceOf(Binary::class, $binaryVector);
91+
} else {
92+
$binaryVector = new Binary("\x03\x00\x01\x02\x03", 9);
93+
}
94+
8595
$stage->queryVector($binaryVector);
8696
self::assertSame(['$vectorSearch' => ['queryVector' => $binaryVector]], $stage->getExpression());
8797
}

0 commit comments

Comments
 (0)