Skip to content

Commit

Permalink
chore: Add tests for the PHPMongoQuery class
Browse files Browse the repository at this point in the history
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 <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jun 3, 2024
1 parent 8820e7d commit 7c37986
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions apps/webhooks/tests/Service/PHPMongoQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Webhooks\Tests\Db;

use OCA\Webhooks\Service\PHPMongoQuery;
use OCP\Files\Events\Node\NodeWrittenEvent;
use Test\TestCase;

class PHPMongoQueryTest extends TestCase {
private function dataExecuteQuery() {
$event = [
'event' => [
'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));
}
}

0 comments on commit 7c37986

Please sign in to comment.