From 75b2ed4c79f187114d66a299f11266b325f6baa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 3 Jun 2024 15:32:26 +0200 Subject: [PATCH] chore: Add tests for the PHPMongoQuery class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It appears that it does not match Mongo current documentation exactly so we should look into adapting it. Having equality autodetect regex is a bit weird. Signed-off-by: Côme Chilliet --- .../tests/Service/PHPMongoQueryTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 apps/webhooks/tests/Service/PHPMongoQueryTest.php diff --git a/apps/webhooks/tests/Service/PHPMongoQueryTest.php b/apps/webhooks/tests/Service/PHPMongoQueryTest.php new file mode 100644 index 00000000000..06658b718f0 --- /dev/null +++ b/apps/webhooks/tests/Service/PHPMongoQueryTest.php @@ -0,0 +1,47 @@ + [ + 'class' => NodeWrittenEvent::class, + 'node' => [ + 'id' => 23, + 'path' => '/tmp/file.txt', + ], + ], + 'user' => [ + 'uid' => 'bob', + ], + ]; + return [ + [[], [], true], + [[], $event, true], + [['event.class' => NodeWrittenEvent::class], $event, true], + [['event.class' => NodeWrittenEvent::class, 'user.uid' => 'bob'], $event, true], + [['event.node.path' => '/.txt$/'], $event, true], + [['event.node.id' => ['$gte' => 22]], $event, true], + [['event.class' => 'SomethingElse'], $event, false], + ]; + } + + /** + * @dataProvider dataExecuteQuery + */ + public function testExecuteQuery(array $query, array $document, bool $matches) { + $this->assertEquals($matches, PHPMongoQuery::executeQuery($query, $document)); + } +}