diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c1def465f..286a2ecd7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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: @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index 0a7e3fae0..199c00b9e 100755 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/composer.json b/composer.json index 5d1ed0a78..285a7ba66 100755 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 075ab4fd0..378c30e9e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5658aeb8a6bdb6a8e2b42214def072d1", + "content-hash": "121989fd6e347225ad343753e56ee860", "packages": [ { "name": "brick/math", @@ -2292,16 +2292,16 @@ }, { "name": "utopia-php/query", - "version": "0.7.2", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/utopia-php/query.git", - "reference": "945ef1c9f1c863b0e6e8bbac4c81c1b667dbfc9c" + "reference": "aa6ea0415beae93abac10c36c3c644a9402e0c02" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/query/zipball/945ef1c9f1c863b0e6e8bbac4c81c1b667dbfc9c", - "reference": "945ef1c9f1c863b0e6e8bbac4c81c1b667dbfc9c", + "url": "https://api.github.com/repos/utopia-php/query/zipball/aa6ea0415beae93abac10c36c3c644a9402e0c02", + "reference": "aa6ea0415beae93abac10c36c3c644a9402e0c02", "shasum": "" }, "require": { @@ -2312,6 +2312,9 @@ }, "type": "library", "autoload": { + "files": [ + "src/extension.php" + ], "psr-4": { "Utopia\\Query\\": "src/" } @@ -2330,9 +2333,10 @@ ], "support": { "issues": "https://github.com/utopia-php/query/issues", - "source": "https://github.com/utopia-php/query/tree/0.7.2" + "source": "https://github.com/utopia-php/query/tree/0.8.0" }, - "time": "2026-10-16T10:52:31+00:00" + "time": "2026-11-24T16:14:05+00:00", + "published-time": "2026-11-24T16:17:02+00:00" }, { "name": "utopia-php/telemetry", @@ -5239,5 +5243,5 @@ "ext-redis": "*" }, "platform-dev": {}, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.11.0" } diff --git a/tests/unit/Adapter/SQLArrayWritesTest.php b/tests/unit/Adapter/SQLArrayWritesTest.php index 605dcce39..add61e601 100644 --- a/tests/unit/Adapter/SQLArrayWritesTest.php +++ b/tests/unit/Adapter/SQLArrayWritesTest.php @@ -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; @@ -52,6 +53,7 @@ protected function setUp(): void )); } + #[IgnoreDeprecations] public function testCreatedDocumentsKeepTheirArrays(): void { $this->database->createDocuments('items', [ diff --git a/tests/unit/Builder/SearchTermTest.php b/tests/unit/Builder/SearchTermTest.php index 3c6ab33f5..05bfb57a8 100644 --- a/tests/unit/Builder/SearchTermTest.php +++ b/tests/unit/Builder/SearchTermTest.php @@ -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"'], ]; } @@ -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 { diff --git a/tests/unit/MongoContainsFilterTest.php b/tests/unit/MongoContainsFilterTest.php index 55bdc7c77..dc8d58c29 100644 --- a/tests/unit/MongoContainsFilterTest.php +++ b/tests/unit/MongoContainsFilterTest.php @@ -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; @@ -22,6 +23,7 @@ final class MongoContainsFilterTest extends TestCase */ private array $filters = []; + #[IgnoreDeprecations] public function testContainsOnAnArrayMatchesAnyValue(): void { $contains = Query::contains('genres', ['comics', 'kids']); @@ -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) { diff --git a/tests/unit/PostgresQueryBehaviorTest.php b/tests/unit/PostgresQueryBehaviorTest.php index 382426b78..479f77176 100644 --- a/tests/unit/PostgresQueryBehaviorTest.php +++ b/tests/unit/PostgresQueryBehaviorTest.php @@ -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], @@ -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); @@ -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); diff --git a/tests/unit/Validator/Query/FilterMalformedValuesTest.php b/tests/unit/Validator/Query/FilterMalformedValuesTest.php index 52090d5fd..785a2b052 100644 --- a/tests/unit/Validator/Query/FilterMalformedValuesTest.php +++ b/tests/unit/Validator/Query/FilterMalformedValuesTest.php @@ -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; @@ -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(); diff --git a/tests/unit/Validator/QueryValidationTest.php b/tests/unit/Validator/QueryValidationTest.php index 88f45e5f2..13ccaa608 100644 --- a/tests/unit/Validator/QueryValidationTest.php +++ b/tests/unit/Validator/QueryValidationTest.php @@ -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; @@ -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 ([