diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 15853dbe0..153c5300c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,20 +1,30 @@ name: "Linter" on: [ pull_request ] + jobs: lint: - name: Linter + name: Run Linter on PHP ${{ matrix.php }} runs-on: ubuntu-latest + strategy: + matrix: + php: ['8.1', '8.2'] + steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 - - run: git checkout HEAD^2 + - name: Install dependencies + run: composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist - - name: Run Linter - run: | - docker run --rm -v $PWD:/app composer sh -c \ - "composer install --profile --ignore-platform-reqs && composer lint" + - run: composer lint diff --git a/.github/workflows/tests.yml b/.github/workflows/test80.yml similarity index 71% rename from .github/workflows/tests.yml rename to .github/workflows/test80.yml index 970fc22de..22d1a4353 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/test80.yml @@ -2,8 +2,8 @@ name: "Tests" on: [pull_request] jobs: - tests: - name: Unit & E2E + test: + name: Unit & E2E (PHP 8.0) runs-on: ubuntu-latest steps: @@ -22,8 +22,9 @@ jobs: uses: docker/build-push-action@v3 with: context: . + file: ./Dockerfile-8.0 push: false - tags: database-dev + tags: database-80 load: true cache-from: type=gha cache-to: type=gha,mode=max @@ -34,7 +35,4 @@ jobs: sleep 10 - name: Run Tests - run: docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml - - - name: Check Coverage - run: docker compose exec -T tests vendor/bin/coverage-check tmp/clover.xml 90 \ No newline at end of file + run: docker compose exec -T tests80 vendor/bin/phpunit --configuration phpunit.xml \ No newline at end of file diff --git a/.github/workflows/test81.yml b/.github/workflows/test81.yml new file mode 100644 index 000000000..527ddd2d0 --- /dev/null +++ b/.github/workflows/test81.yml @@ -0,0 +1,38 @@ +name: "Tests" + +on: [pull_request] +jobs: + test: + name: Unit & E2E (PHP 8.1) + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + submodules: recursive + + - run: git checkout HEAD^2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build image + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile-8.1 + push: false + tags: database-81 + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Start Databases + run: | + docker compose up -d + sleep 10 + + - name: Run Tests + run: docker compose exec -T tests81 vendor/bin/phpunit --configuration phpunit.xml \ No newline at end of file diff --git a/.github/workflows/test82.yml b/.github/workflows/test82.yml new file mode 100644 index 000000000..a19baf58a --- /dev/null +++ b/.github/workflows/test82.yml @@ -0,0 +1,38 @@ +name: "Tests" + +on: [pull_request] +jobs: + test: + name: Unit & E2E (PHP 8.2) + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + submodules: recursive + + - run: git checkout HEAD^2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build image + uses: docker/build-push-action@v3 + with: + context: . + file: ./Dockerfile-8.2 + push: false + tags: database-82 + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Start Databases + run: | + docker compose up -d + sleep 10 + + - name: Run Tests + run: docker compose exec -T tests82 vendor/bin/phpunit --configuration phpunit.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile-8.0 similarity index 100% rename from Dockerfile rename to Dockerfile-8.0 diff --git a/Dockerfile-8.1 b/Dockerfile-8.1 new file mode 100755 index 000000000..688d66326 --- /dev/null +++ b/Dockerfile-8.1 @@ -0,0 +1,93 @@ +FROM composer:2.0 as composer + +ARG TESTING=false +ENV TESTING=$TESTING + +WORKDIR /usr/local/src/ + +COPY composer.lock /usr/local/src/ +COPY composer.json /usr/local/src/ + +RUN composer install --ignore-platform-reqs --optimize-autoloader \ + --no-plugins --no-scripts --prefer-dist + +FROM php:8.1-cli-alpine as compile + +ENV PHP_REDIS_VERSION=5.3.4 \ + PHP_SWOOLE_VERSION=v4.8.0 \ + PHP_MONGO_VERSION=1.11.1 + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN \ + apk update \ + && apk add --no-cache postgresql-libs postgresql-dev make automake autoconf gcc g++ git brotli-dev \ + && docker-php-ext-install opcache pgsql pdo_mysql pdo_pgsql \ + && apk del postgresql-dev \ + && rm -rf /var/cache/apk/* + +# Redis Extension +FROM compile AS redis +RUN \ + git clone --depth 1 --branch $PHP_REDIS_VERSION https://github.com/phpredis/phpredis.git \ + && cd phpredis \ + && phpize \ + && ./configure \ + && make && make install + +## Swoole Extension +FROM compile AS swoole +RUN \ + git clone --depth 1 --branch $PHP_SWOOLE_VERSION https://github.com/swoole/swoole-src.git \ + && cd swoole-src \ + && phpize \ + && ./configure --enable-http2 \ + && make && make install + +## MongoDB Extension +FROM compile AS mongodb +RUN \ + git clone --depth 1 --branch $PHP_MONGO_VERSION https://github.com/mongodb/mongo-php-driver.git \ + && cd mongo-php-driver \ + && git submodule update --init \ + && phpize \ + && ./configure \ + && make && make install + +## PCOV Extension +FROM compile AS pcov +RUN \ + git clone https://github.com/krakjoe/pcov.git \ + && cd pcov \ + && phpize \ + && ./configure --enable-pcov \ + && make && make install + +FROM compile as final + +LABEL maintainer="team@appwrite.io" + +WORKDIR /usr/src/code + +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=mongodb.so >> /usr/local/etc/php/conf.d/mongodb.ini +RUN echo extension=pcov.so >> /usr/local/etc/php/conf.d/pcov.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 + +RUN echo "memory_limit=1024M" >> $PHP_INI_DIR/php.ini + +COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor +COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20210902/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=redis /usr/local/lib/php/extensions/no-debug-non-zts-20210902/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20210902/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=pcov /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pcov.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ + +# Add Source Code +COPY ./bin /usr/src/code/bin +COPY ./src /usr/src/code/src + +CMD [ "tail", "-f", "/dev/null" ] diff --git a/Dockerfile-8.2 b/Dockerfile-8.2 new file mode 100755 index 000000000..1b3e4b30f --- /dev/null +++ b/Dockerfile-8.2 @@ -0,0 +1,94 @@ +FROM composer:2.0 as composer + +ARG TESTING=false +ENV TESTING=$TESTING + +WORKDIR /usr/local/src/ + +COPY composer.lock /usr/local/src/ +COPY composer.json /usr/local/src/ + +RUN composer install --ignore-platform-reqs --optimize-autoloader \ + --no-plugins --no-scripts --prefer-dist + +FROM php:8.2-cli-alpine3.18 as compile + +ENV PHP_REDIS_VERSION=5.3.4 \ + PHP_SWOOLE_VERSION=v4.8.0 \ + PHP_MONGO_VERSION=1.11.1 + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN \ + apk update \ + linux-headers \ + && apk add --no-cache postgresql-libs postgresql-dev make automake autoconf gcc g++ git brotli-dev \ + && docker-php-ext-install opcache pgsql pdo_mysql pdo_pgsql \ + && apk del postgresql-dev \ + && rm -rf /var/cache/apk/* + +# Redis Extension +FROM compile AS redis +RUN \ + git clone --depth 1 --branch $PHP_REDIS_VERSION https://github.com/phpredis/phpredis.git \ + && cd phpredis \ + && phpize \ + && ./configure \ + && make && make install + +## Swoole Extension +FROM compile AS swoole +RUN \ + git clone --depth 1 --branch $PHP_SWOOLE_VERSION https://github.com/swoole/swoole-src.git \ + && cd swoole-src \ + && phpize \ + && ./configure --enable-http2 \ + && make && make install + +## MongoDB Extension +FROM compile AS mongodb +RUN \ + git clone --depth 1 --branch $PHP_MONGO_VERSION https://github.com/mongodb/mongo-php-driver.git \ + && cd mongo-php-driver \ + && git submodule update --init \ + && phpize \ + && ./configure \ + && make && make install + +## PCOV Extension +FROM compile AS pcov +RUN \ + git clone https://github.com/krakjoe/pcov.git \ + && cd pcov \ + && phpize \ + && ./configure --enable-pcov \ + && make && make install + +FROM compile as final + +LABEL maintainer="team@appwrite.io" + +WORKDIR /usr/src/code + +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=mongodb.so >> /usr/local/etc/php/conf.d/mongodb.ini +RUN echo extension=pcov.so >> /usr/local/etc/php/conf.d/pcov.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 + +RUN echo "memory_limit=1024M" >> $PHP_INI_DIR/php.ini + +COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor +COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20220829/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/ +COPY --from=redis /usr/local/lib/php/extensions/no-debug-non-zts-20220829/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/ +COPY --from=mongodb /usr/local/lib/php/extensions/no-debug-non-zts-20220829/mongodb.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/ +COPY --from=pcov /usr/local/lib/php/extensions/no-debug-non-zts-20220829/pcov.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/ + +# Add Source Code +COPY ./bin /usr/src/code/bin +COPY ./src /usr/src/code/src + +CMD [ "tail", "-f", "/dev/null" ] diff --git a/docker-compose.yml b/docker-compose.yml index 296cd6095..b8ca091f5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,44 @@ version: '3.1' services: - tests: - container_name: tests - image: database-dev + tests80: + container_name: tests80 + image: database-80 build: context: . + dockerfile: Dockerfile-8.0 + networks: + - database + volumes: + - ./bin:/usr/src/code/bin + - ./src:/usr/src/code/src + - ./tests:/usr/src/code/tests + - ./phpunit.xml:/usr/src/code/phpunit.xml + ports: + - "8708:8708" + + tests81: + container_name: tests81 + image: database-81 + build: + context: . + dockerfile: Dockerfile-8.1 + networks: + - database + volumes: + - ./bin:/usr/src/code/bin + - ./src:/usr/src/code/src + - ./tests:/usr/src/code/tests + - ./phpunit.xml:/usr/src/code/phpunit.xml + ports: + - "8708:8708" + + tests82: + container_name: tests82 + image: database-82 + build: + context: . + dockerfile: Dockerfile-8.2 networks: - database volumes: diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 05d66ef60..583a68d5b 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1439,7 +1439,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, $orderType = $orderType === Database::ORDER_ASC ? Database::ORDER_DESC : Database::ORDER_ASC; } - $orders[] = "`${attribute}` ${orderType}"; + $orders[] = "`{$attribute}` {$orderType}"; } // Allow after pagination without any order diff --git a/src/Database/Query.php b/src/Database/Query.php index f2ed42416..38c6f96af 100644 --- a/src/Database/Query.php +++ b/src/Database/Query.php @@ -822,7 +822,7 @@ public static function parseQueries(array $queries): array try { $parsed[] = Query::parse($query); } catch (\Throwable $th) { - throw new QueryException("Invalid query: ${query}", previous: $th); + throw new QueryException("Invalid query: {$query}", previous: $th); } } diff --git a/tests/Database/Base.php b/tests/Database/Base.php index 31b0dc9df..4718297b0 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -4515,7 +4515,7 @@ public function testKeywords(): void $this->assertEquals('reservedKeyDocument', $documents[0]->getId()); $this->assertEquals('Reserved:' . $keyword, $documents[0]->getAttribute($keyword)); - $documents = $database->find($collectionName, [Query::equal($keyword, ["Reserved:${keyword}"])]); + $documents = $database->find($collectionName, [Query::equal($keyword, ["Reserved:{$keyword}"])]); $this->assertCount(1, $documents); $this->assertEquals('reservedKeyDocument', $documents[0]->getId());