Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ jobs:
path: /tmp/${{ env.IMAGE }}.tar

unit_test:
name: Unit Test
name: "Unit Test${{ matrix.query }}"
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
include:
- query: ""
env: ""
# utopia-php/query from the utopia extension, as Appwrite runs it.
- query: " (query extension)"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"

steps:
- name: checkout
Expand All @@ -61,10 +70,10 @@ jobs:
docker compose up -d --wait

- name: Run Unit Tests
run: docker compose exec -e XDEBUG_MODE=off tests vendor/bin/paratest --configuration phpunit.xml --functional --processes 4 /usr/src/code/tests/unit
run: docker compose exec -e XDEBUG_MODE=off ${{ matrix.env }} tests vendor/bin/paratest --configuration phpunit.xml --functional --processes 4 /usr/src/code/tests/unit

adapter_test:
name: "Adapter Tests (${{ matrix.adapter }})"
name: "Adapter Tests (${{ matrix.adapter }}${{ matrix.query }})"
runs-on: ubuntu-latest
needs: setup
strategy:
Expand Down Expand Up @@ -103,6 +112,40 @@ jobs:
profiles: ""
- adapter: Schemaless/MongoDB
profiles: "--profile mongo"
# The SQL adapters again with utopia-php/query from the utopia extension, as Appwrite
# runs it. The other adapters build no SQL.
- adapter: MariaDB
profiles: "--profile mariadb"
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: MySQL
profiles: "--profile mysql"
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: Postgres
profiles: "--profile postgres"
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: SQLite
profiles: ""
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: SharedTables/MariaDB
profiles: "--profile mariadb"
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: SharedTables/MySQL
profiles: "--profile mysql"
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: SharedTables/Postgres
profiles: "--profile postgres"
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"
- adapter: SharedTables/SQLite
profiles: ""
query: ", query extension"
env: "-e PHP_INI_SCAN_DIR=:/usr/local/etc/php/utopia"

steps:
- name: checkout
Expand All @@ -121,4 +164,4 @@ jobs:
docker compose ${{ matrix.profiles }} up -d --wait

- name: Run Tests
run: docker compose exec -T -e XDEBUG_MODE=off tests vendor/bin/paratest --configuration phpunit.xml --functional --processes 4 /usr/src/code/tests/e2e/Adapter/${{matrix.adapter}}Test.php
run: docker compose exec -T -e XDEBUG_MODE=off ${{ matrix.env }} tests vendor/bin/paratest --configuration phpunit.xml --functional --processes 4 /usr/src/code/tests/e2e/Adapter/${{matrix.adapter}}Test.php
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ RUN EXT_DIR=$(php-config --extension-dir) \
RUN echo extension=redis.so >> /usr/local/etc/php/conf.d/redis.ini
RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini
RUN echo extension=pcov.so >> /usr/local/etc/php/conf.d/pcov.ini

# The utopia extension: the Rust implementation of utopia-php/query that Appwrite runs. Installed
# but not loaded. The extension lane in .github/workflows/tests.yml loads it by adding
# /usr/local/etc/php/utopia to PHP_INI_SCAN_DIR. utopia.libraries limits it to the query classes;
# without it the extension would also replace utopia-php/validators.
COPY --from=appwrite/utopia-extension:main@sha256:75394352dcfdd67e5665e0ad732fb6619f2bde3d968a24b6da96b2492bfb56b0 /utopia.so /usr/local/lib/php/utopia.so
RUN apk add --no-cache libheif libstdc++ \
&& mkdir /usr/local/etc/php/utopia \
&& printf 'extension=/usr/local/lib/php/utopia.so\nutopia.libraries=query\n' > /usr/local/etc/php/utopia/utopia.ini
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN echo "opcache.enable_cli=1" >> $PHP_INI_DIR/php.ini
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"utopia-php/cache": "^8.0",
"utopia-php/pools": "^2.0",
"utopia-php/mongo": "^1.5.4",
"utopia-php/query": "^0.7.2",
"utopia-php/query": "^0.8.0",
"utopia-php/async": "^0.2"
},
"require-dev": {
Expand Down
20 changes: 12 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/unit/Adapter/SQLArrayWritesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PDO;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\TestCase;
use Utopia\Cache\Adapter\None as NoCache;
use Utopia\Cache\Cache;
Expand Down Expand Up @@ -52,6 +53,7 @@ protected function setUp(): void
));
}

#[IgnoreDeprecations]
public function testCreatedDocumentsKeepTheirArrays(): void
{
$this->database->createDocuments('items', [
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/Builder/SearchTermTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static function mySQLTerms(): array
'underscore stays inside a word' => ['foo_bar', 'foo_bar*'],
'mixed separators and spaces' => ['baz, foo/bar; qux', 'baz foo bar qux*'],
'non-operator punctuation is dropped' => ['!!!foo...###', 'foo*'],
'exact phrase keeps its quotes' => ['"foo/bar baz"', '"foo bar baz"'],
];
}

Expand Down Expand Up @@ -91,6 +90,20 @@ public function testMariaDBSearchesEachWordOfATerm(string $term, string $bound):
$this->assertSame([$bound], $this->bindings(new MariaDB(), Query::notSearch('title', $term)));
}

/**
* utopia-php/query 0.8 no longer hands MySQL a quoted phrase, which InnoDB can only match with
* phrase positions in the index. It requires every word and checks their order with a pattern.
*/
public function testMySQLAndMariaDBMatchAnExactPhraseByItsWordsInOrder(): void
{
$bound = ['+foo +bar +baz', '(^|[^[:alnum:]_])foo[^[:alnum:]_]+bar[^[:alnum:]_]+baz([^[:alnum:]_]|$)'];

foreach ([new MySQL(), new MariaDB()] as $builder) {
$this->assertSame($bound, $this->bindings($builder, Query::search('title', '"foo/bar baz"')), $builder::class);
$this->assertSame($bound, $this->bindings($builder, Query::notSearch('title', '"foo/bar baz"')), $builder::class);
}
}

#[DataProvider('termsWithoutWords')]
public function testATermWithoutWordsBindsNothing(string $term): void
{
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/MongoContainsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use MongoDB\BSON\Regex;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCase;
use stdClass;
Expand All @@ -22,6 +23,7 @@ final class MongoContainsFilterTest extends TestCase
*/
private array $filters = [];

#[IgnoreDeprecations]
public function testContainsOnAnArrayMatchesAnyValue(): void
{
$contains = Query::contains('genres', ['comics', 'kids']);
Expand Down Expand Up @@ -55,6 +57,7 @@ public function testSchemalessUnparsableDateStaysAString(): void
}

#[RequiresPhpExtension('mongodb')]
#[IgnoreDeprecations]
public function testContainsOnAStringMatchesAnyOfSeveralSubstrings(): void
{
foreach ([Query::contains('name', ['Captain', 'Work']), Query::containsAny('name', ['Captain', 'Work'])] as $query) {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/PostgresQueryBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testVectorDistanceIsProjectedHydratedAndOrderedBeforeTieBreaker(
$this->assertCount(1, $documents);
$this->assertSame(0.25, $documents[0]->getAttribute(Document::DISTANCE));
$this->assertMatchesRegularExpression('/SELECT \*, .*::text AS "'.Storage::DISTANCE.'"/', $sql);
$this->assertStringContainsString('WHERE "table_main"."embedding" IS NOT NULL', $sql);
$this->assertStringContainsString('WHERE ("table_main"."embedding" IS NOT NULL)', $sql);
$this->assertMatchesRegularExpression('/ORDER BY .*<=>.*\), "'.Storage::SEQUENCE.'" ASC/', $sql);
$this->assertSame([
[1, '[1,0,0]', \PDO::PARAM_STR],
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testVectorCursorComparesDistanceBeforeSequenceTieBreaker(): void
);

$this->assertStringContainsString(
'"table_main"."embedding" IS NOT NULL AND ((("table_main"."embedding" <=> ?::vector)) > ? OR ((("table_main"."embedding" <=> ?::vector)) = ? AND "table_main"."'.Storage::SEQUENCE.'" > ?))',
'("table_main"."embedding" IS NOT NULL) AND (((("table_main"."embedding" <=> ?::vector)) > ? OR ((("table_main"."embedding" <=> ?::vector)) = ? AND "table_main"."'.Storage::SEQUENCE.'" > ?)))',
$sql,
);
$this->assertMatchesRegularExpression('/ORDER BY .*<=>.*\), "'.Storage::SEQUENCE.'" ASC/', $sql);
Expand Down Expand Up @@ -234,7 +234,7 @@ public function testVectorCursorBeforeBindsRoundTripDistance(): void
);

$this->assertStringContainsString(
'"table_main"."embedding" IS NOT NULL AND ((("table_main"."embedding" <=> ?::vector)) < ? OR ((("table_main"."embedding" <=> ?::vector)) = ? AND "table_main"."'.Storage::SEQUENCE.'" < ?))',
'("table_main"."embedding" IS NOT NULL) AND (((("table_main"."embedding" <=> ?::vector)) < ? OR ((("table_main"."embedding" <=> ?::vector)) = ? AND "table_main"."'.Storage::SEQUENCE.'" < ?)))',
$sql,
);
$this->assertMatchesRegularExpression('/ORDER BY .*<=>.*\) DESC, "'.Storage::SEQUENCE.'" DESC/', $sql);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Validator/Query/FilterMalformedValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Unit\Validator\Query;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\TestCase;
use Utopia\Database\Document;
use Utopia\Database\Query;
Expand Down Expand Up @@ -91,6 +92,7 @@ public function testAVectorQueryOnAnUndeclaredAttributeIsRefusedWithoutAWarning(
$this->assertSame('Vector queries can only be used on vector attributes', $validator->getDescription());
}

#[IgnoreDeprecations]
public function testListValuesAreStillValid(): void
{
$validator = $this->validator();
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Validator/QueryValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use PDO;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\TestCase;
use Tests\Unit\Support\Profiles;
use Utopia\Cache\Adapter\None as NoCache;
Expand Down Expand Up @@ -191,6 +192,7 @@ public function testAJoinOnListAcceptsOnlyConditionsAndPlainFilters(Query $condi
$this->assertInvalidQuery($message, fn (): mixed => $this->database->getDocument('owners', 'ann', $queries), 'getDocument()');
}

#[IgnoreDeprecations]
public function testAJoinOnListRunsItsPlainFilters(): void
{
foreach ([
Expand Down
Loading