Skip to content

Commit

Permalink
no issue - PHPVER=8-3 and LOWEST=1 when running ./dev.sh in order to …
Browse files Browse the repository at this point in the history
…test locally
  • Loading branch information
pounard committed Apr 19, 2024
1 parent 3934dd3 commit ddbc885
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 16 deletions.
32 changes: 21 additions & 11 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

if [[ -z "${PHPVER}" ]]; then
PHPVER="8-1"
fi

PHPUNIT_CONTAINER="phpunit-${PHPVER}"

section_title() {
printf "${RED}\n-------------------------------- ${NC}"
printf "${RED}$1${NC}"
Expand All @@ -30,7 +36,11 @@ do_down() {

do_composer_install() {
echo 'composer install'
docker compose -p query_builder_test exec phpunit composer install
if [[ -z "${LOWEST}" ]]; then
docker compose -p query_builder_test exec $PHPUNIT_CONTAINER composer update
else
docker compose -p query_builder_test exec $PHPUNIT_CONTAINER composer update --prefer-lowest
fi
}

# Launch composer checks (for Static analysis & Code style fixer)
Expand All @@ -40,13 +50,13 @@ do_checks() {
do_composer_install

echo 'composer checks'
docker compose -p query_builder_test exec phpunit composer checks
docker compose -p query_builder_test exec $PHPUNIT_CONTAINER composer checks
}

# Launch PHPUnit tests without any database vendor
do_unittest() {
section_title "PHPUnit unit tests"
docker compose -p query_builder_test exec phpunit vendor/bin/phpunit
docker compose -p query_builder_test exec $PHPUNIT_CONTAINER vendor/bin/phpunit
}

do_test_mysql57() {
Expand All @@ -61,7 +71,7 @@ do_test_mysql57() {
-e DBAL_ROOT_USER="root" \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql57:3306/test_db?serverVersion=5.7 \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_mysql80() {
Expand All @@ -76,7 +86,7 @@ do_test_mysql80() {
-e DBAL_ROOT_USER=root \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mysql80:3306/test_db?serverVersion=8 \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_mariadb11() {
Expand All @@ -91,7 +101,7 @@ do_test_mariadb11() {
-e DBAL_ROOT_USER="root" \
-e DBAL_USER=root \
-e DATABASE_URL=mysql://root:password@mariadb11:3306/test_db?serverVersion=11.1.3-MariaDB \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_mysql() {
Expand All @@ -112,7 +122,7 @@ do_test_postgresql10() {
-e DBAL_ROOT_USER=postgres \
-e DBAL_USER=postgres \
-e DATABASE_URL="postgresql://postgres:password@postgresql10:5432/test_db?serverVersion=10&charset=utf8" \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_postgresql16() {
Expand All @@ -127,7 +137,7 @@ do_test_postgresql16() {
-e DBAL_ROOT_USER=postgres \
-e DBAL_USER=postgres \
-e DATABASE_URL="postgresql://postgres:password@postgresql16:5432/test_db?serverVersion=16&charset=utf8" \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_postgresql() {
Expand All @@ -147,7 +157,7 @@ do_test_sqlsrv2019() {
-e DBAL_ROOT_USER=sa \
-e DBAL_USER=sa \
-e DATABASE_URL="pdo-sqlsrv://sa:P%40ssword123@sqlsrv2019:1433/test_db?serverVersion=2019&charset=utf8&driverOptions[TrustServerCertificate]=true" \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_sqlsrv2022() {
Expand All @@ -162,7 +172,7 @@ do_test_sqlsrv2022() {
-e DBAL_ROOT_USER=sa \
-e DBAL_USER=sa \
-e DATABASE_URL="pdo-sqlsrv://sa:P%40ssword123@sqlsrv2022:1433/test_db?serverVersion=2022&charset=utf8&driverOptions[TrustServerCertificate]=true" \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

do_test_sqlsrv() {
Expand All @@ -179,7 +189,7 @@ do_test_sqlite() {
-e DBAL_DBNAME=test_db \
-e DBAL_HOST=:memory: \
-e DATABASE_URL="pdo-sqlite:///:memory:" \
phpunit vendor/bin/phpunit "$@"
$PHPUNIT_CONTAINER vendor/bin/phpunit "$@"
}

# Run PHPunit tests for all database vendors
Expand Down
16 changes: 14 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
version: '3.8'
services:
phpunit:
build: ./docker/php
phpunit-8-1:
build: ./docker/php-8.1
networks:
- query-builder-test
volumes:
- ./:/var/www
environment:
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG:-serverName=docker}
XDEBUG_CONFIG: "client_host=host.docker.internal client_port=9000 log=/tmp/xdebug/xdebug.log output_dir=/tmp/xdebug start_with_request=trigger"
XDEBUG_MODE: "${XDEBUG_MODE:-debug}"
extra_hosts:
- "host.docker.internal:host-gateway"
phpunit-8-3:
build: ./docker/php-8.3
networks:
- query-builder-test
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker/php/Dockerfile → docker/php-8.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv

# Install Xdebug
RUN pecl install xdebug-3.3.1 && docker-php-ext-enable xdebug
RUN pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug

# Cleanup.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Expand Down
36 changes: 36 additions & 0 deletions docker/php-8.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM php:8.3-fpm-bookworm

# Basic requirements
RUN apt-get update
RUN apt-get install -yqq --no-install-recommends default-mysql-client acl iproute2 zip zlib1g-dev libzip-dev \
libxml2-dev libpng-dev libghc-curl-dev libldb-dev libldap2-dev gnupg2 libpq-dev

# Instaling postgresql-client-16
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc| gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg && \
sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
apt-get update && apt-get install -y postgresql-16

# PHP required extensions
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql
RUN docker-php-ext-install -j$(nproc) pgsql pdo_pgsql pdo mysqli pdo_mysql zip xml gd curl bcmath
RUN docker-php-ext-enable pdo_pgsql pdo_mysql sodium

# SQL Server support
ENV ACCEPT_EULA=Y
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN apt-get -y --no-install-recommends install msodbcsql18 unixodbc-dev
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv

# Install Xdebug
RUN pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug

# Cleanup.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY --from=composer /usr/bin/composer /usr/bin/composer

WORKDIR /var/www
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/DoctrineQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ protected function lookupServerVersion(): ?string

// doctrine/dbal:^3.17 only.
$driver = $this->connection->getDriver();
if ((\interface_exists(ServerInfoAwareConnection::class) && $driver instanceof ServerInfoAwareConnection) || \method_exists($driver, 'getServerVersion')) {
if ($driver && \method_exists($driver, 'getServerVersion')) {

Check failure on line 69 in src/Bridge/Doctrine/DoctrineQueryBuilder.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.2)

Left side of && is always true.
// @phpstan-ignore-next-line
return $this->doctrineServerVersion = $driver->getServerVersion();

Check failure on line 71 in src/Bridge/Doctrine/DoctrineQueryBuilder.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.2)

No error to ignore is reported on line 71.
}
if (\method_exists($this->connection, 'getWrappedConnection')) {
$driverConnection = $this->connection->getWrappedConnection();
if ((\interface_exists(ServerInfoAwareConnection::class) && $driverConnection instanceof ServerInfoAwareConnection) || \method_exists($driverConnection, 'getServerVersion')) {
if ($driverConnection && \method_exists($driverConnection, 'getServerVersion')) {
return $this->doctrineServerVersion = $driverConnection->getServerVersion();
}
}
Expand Down

0 comments on commit ddbc885

Please sign in to comment.