Skip to content

Commit

Permalink
Add new test case for equal boolean field (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Nov 12, 2023
1 parent ac0c4f2 commit 0bb8832
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/seal/src/Testing/AbstractSearcherTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,50 @@ public function testEqualCondition(): void
}
}

public function testEqualConditionWithBoolean(): void
{
$documents = TestingHelper::createComplexFixtures();

$schema = self::getSchema();

foreach ($documents as $document) {
self::$taskHelper->tasks[] = self::$indexer->save(
$schema->indexes[TestingHelper::INDEX_COMPLEX],
$document,
['return_slow_promise_result' => true],
);
}
self::$taskHelper->waitForAll();

$search = new SearchBuilder($schema, self::$searcher);
$search->addIndex(TestingHelper::INDEX_COMPLEX);
$search->addFilter(new Condition\EqualCondition('isSpecial', true));

$expectedDocumentsVariantA = [
$documents[0],
];
$expectedDocumentsVariantB = [
$documents[0],
];

$loadedDocuments = [...$search->getResult()];
$this->assertCount(1, $loadedDocuments);

$this->assertTrue(
$expectedDocumentsVariantA === $loadedDocuments
|| $expectedDocumentsVariantB === $loadedDocuments,
'Not correct documents where found.',
);

foreach ($documents as $document) {
self::$taskHelper->tasks[] = self::$indexer->delete(
$schema->indexes[TestingHelper::INDEX_COMPLEX],
$document['uuid'],
['return_slow_promise_result' => true],
);
}
}

public function testMultiEqualCondition(): void
{
$documents = TestingHelper::createComplexFixtures();
Expand Down
3 changes: 3 additions & 0 deletions packages/seal/src/Testing/TestingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static function createSchema(): Schema
'created' => new Field\DateTimeField('created', filterable: true, sortable: true),
'commentsCount' => new Field\IntegerField('commentsCount', filterable: true, sortable: true),
'rating' => new Field\FloatField('rating', filterable: true, sortable: true),
'isSpecial' => new Field\BooleanField('isSpecial', filterable: true),
'comments' => new Field\ObjectField('comments', [
'email' => new Field\TextField('email', searchable: false),
'text' => new Field\TextField('text'),
Expand Down Expand Up @@ -144,6 +145,7 @@ public static function createComplexFixtures(): array
'created' => '2022-01-24T12:00:00+01:00',
'commentsCount' => 2,
'rating' => 3.5,
'isSpecial' => true,
'comments' => [
[
'email' => 'admin.nonesearchablefield@localhost',
Expand Down Expand Up @@ -171,6 +173,7 @@ public static function createComplexFixtures(): array
'created' => '2022-12-26T12:00:00+01:00',
'commentsCount' => 0,
'rating' => 2.5,
'isSpecial' => false,
'comments' => [],
'tags' => ['UI', 'UX'],
'categoryIds' => [2, 3],
Expand Down
3 changes: 3 additions & 0 deletions packages/seal/tests/Marshaller/FlattenMarshallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static function provideData(): \Generator
'created' => '2022-01-24T12:00:00+01:00',
'commentsCount' => 2,
'rating' => 3.5,
'isSpecial' => true,
'comments' => [
[
'email' => 'admin.nonesearchablefield@localhost',
Expand Down Expand Up @@ -126,6 +127,7 @@ public static function provideData(): \Generator
'created' => '2022-01-24T12:00:00+01:00',
'commentsCount' => 2,
'rating' => 3.5,
'isSpecial' => true,
'comments.email' => ['admin.nonesearchablefield@localhost', 'example.nonesearchablefield@localhost'],
'comments.text' => ['Awesome blog!', 'Like this blog!'],
'tags' => ['Tech', 'UI'],
Expand Down Expand Up @@ -161,6 +163,7 @@ public static function provideData(): \Generator
'created' => new Field\DateTimeField('created', filterable: true, sortable: true),
'commentsCount' => new Field\IntegerField('commentsCount', searchable: false, filterable: true, sortable: true),
'rating' => new Field\FloatField('rating', searchable: false, filterable: true, sortable: true),
'isSpecial' => new Field\BooleanField('rating', searchable: false, filterable: true),
'comments' => new Field\ObjectField('comments', [
'email' => new Field\TextField('email', searchable: false),
'text' => new Field\TextField('text'),
Expand Down
1 change: 1 addition & 0 deletions packages/seal/tests/Marshaller/MarshallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private function getRawDocument(bool $dateAsInteger = false): array
'created' => $dateAsInteger ? 1_643_022_000 : '2022-01-24T12:00:00+01:00',
'commentsCount' => 2,
'rating' => 3.5,
'isSpecial' => true,
'comments' => [
[
'email' => 'admin.nonesearchablefield@localhost',
Expand Down

0 comments on commit 0bb8832

Please sign in to comment.