Skip to content

Commit 6a544a7

Browse files
authored
Fix test on Binary vector (#2853)
1 parent e43c2d1 commit 6a544a7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 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,16 @@ 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+
// @phpstan-ignore class.notFound (requires ext-mongodb 2.2+)
88+
if (enum_exists(VectorType::class)) {
89+
// @phpstan-ignore staticMethod.notFound (requires ext-mongodb 2.2+)
90+
$binaryVector = Binary::fromVector([1, 2, 3], VectorType::Int8);
91+
self::assertInstanceOf(Binary::class, $binaryVector);
92+
} else {
93+
$binaryVector = new Binary("\x03\x00\x01\x02\x03", 9);
94+
}
95+
8596
$stage->queryVector($binaryVector);
8697
self::assertSame(['$vectorSearch' => ['queryVector' => $binaryVector]], $stage->getExpression());
8798
}

0 commit comments

Comments
 (0)