Skip to content

Commit

Permalink
Fix asserts, add Dockerfile for PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored and ondrejmirtes committed Sep 9, 2024
1 parent a103cfe commit 5169675
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/Type/Doctrine/Query/QueryResultTypeWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,11 @@ public function walkLiteral($literal): string
if (stripos($value, 'e') !== false) {
$type = new DqlConstantStringType((string) (float) $value, $literal->type);
} else {
// if ($this->phpVersion->getVersionId() >= 80400) {
// $type = new ConstantFloatType((float) $value);
// } else {
// $type = new DqlConstantStringType($value, $literal->type);
// }
$type = new DqlConstantStringType($value, $literal->type);
}

Expand Down
74 changes: 58 additions & 16 deletions tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2743,7 +2743,7 @@ public static function provideCases(): iterable
'pdoPgsqlResult' => 0.125,
'pgsqlResult' => 0.125,
'mssqlResult' => 0.125,
'stringify' => self::STRINGIFY_DEFAULT,
'stringify' => self::STRINGIFY_PG_FLOAT,
];

yield 'MAX(t.col_decimal)' => [
Expand Down Expand Up @@ -4170,6 +4170,38 @@ public static function provideCases(): iterable
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(0, 0)' => [
'data' => self::dataDefault(),
'select' => 'SELECT COALESCE(0, 0) FROM %s t',
'mysql' => self::int(),
'sqlite' => self::int(),
'pdo_pgsql' => self::int(),
'pgsql' => self::int(),
'mssql' => self::mixed(),
'mysqlResult' => 0,
'sqliteResult' => 0,
'pdoPgsqlResult' => 0,
'pgsqlResult' => 0,
'mssqlResult' => 0,
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(1.0, 1.0)' => [
'data' => self::dataDefault(),
'select' => 'SELECT COALESCE(1.0, 1.0) FROM %s t',
'mysql' => self::numericString(),
'sqlite' => self::float(),
'pdo_pgsql' => self::numericString(),
'pgsql' => self::numericString(),
'mssql' => self::mixed(),
'mysqlResult' => '1.0',
'sqliteResult' => 1.0,
'pdoPgsqlResult' => '1.0',
'pgsqlResult' => '1.0',
'mssqlResult' => '1.0',
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(1e0, 1.0)' => [
'data' => self::dataDefault(),
'select' => 'SELECT COALESCE(1e0, 1.0) FROM %s t',
Expand Down Expand Up @@ -4255,15 +4287,17 @@ public static function provideCases(): iterable
'select' => 'SELECT COALESCE(t.col_float_nullable, 0) FROM %s t',
'mysql' => self::float(),
'sqlite' => TypeCombinator::union(self::float(), self::int()),
'pdo_pgsql' => TypeCombinator::union(self::float(), self::int()),
'pdo_pgsql' => PHP_VERSION_ID < 80400
? TypeCombinator::union(self::numericString(), self::int())
: TypeCombinator::union(self::float(), self::int()),
'pgsql' => TypeCombinator::union(self::float(), self::int()),
'mssql' => self::mixed(),
'mysqlResult' => 0.0,
'sqliteResult' => 0,
'pdoPgsqlResult' => 0.0,
'pdoPgsqlResult' => PHP_VERSION_ID < 80400 ? '0' : 0.0,
'pgsqlResult' => 0.0,
'mssqlResult' => 0.0,
'stringify' => self::STRINGIFY_PG_FLOAT,
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(t.col_float_nullable, 0.0)' => [
Expand Down Expand Up @@ -4303,63 +4337,71 @@ public static function provideCases(): iterable
'select' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0) FROM %s t',
'mysql' => self::float(),
'sqlite' => TypeCombinator::union(self::float(), self::int()),
'pdo_pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pdo_pgsql' => PHP_VERSION_ID < 80400
? TypeCombinator::union(self::numericString(), self::int())
: TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'mssql' => self::mixed(),
'mysqlResult' => 0.0,
'sqliteResult' => 0,
'pdoPgsqlResult' => 0.0,
'pdoPgsqlResult' => PHP_VERSION_ID < 80400 ? '0' : 0.0,
'pgsqlResult' => 0.0,
'mssqlResult' => 0.0,
'stringify' => self::STRINGIFY_PG_FLOAT,
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0.0)' => [
'data' => self::dataDefault(),
'select' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0.0) FROM %s t',
'mysql' => self::float(),
'sqlite' => TypeCombinator::union(self::float(), self::int()),
'pdo_pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pdo_pgsql' => PHP_VERSION_ID < 80400
? TypeCombinator::union(self::numericString(), self::int())
: TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'mssql' => self::mixed(),
'mysqlResult' => 0.0,
'sqliteResult' => 0.0,
'pdoPgsqlResult' => 0.0,
'pdoPgsqlResult' => PHP_VERSION_ID < 80400 ? '0' : 0.0,
'pgsqlResult' => 0.0,
'mssqlResult' => 0.0,
'stringify' => self::STRINGIFY_PG_FLOAT,
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0e0)' => [
'data' => self::dataDefault(),
'select' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0e0) FROM %s t',
'mysql' => self::float(),
'sqlite' => TypeCombinator::union(self::float(), self::int()),
'pdo_pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pdo_pgsql' => PHP_VERSION_ID < 80400
? TypeCombinator::union(self::numericString(), self::int())
: TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'mssql' => self::mixed(),
'mysqlResult' => 0.0,
'sqliteResult' => 0.0,
'pdoPgsqlResult' => 0.0,
'pdoPgsqlResult' => PHP_VERSION_ID < 80400 ? '0' : 0.0,
'pgsqlResult' => 0.0,
'mssqlResult' => 0.0,
'stringify' => self::STRINGIFY_PG_FLOAT,
'stringify' => self::STRINGIFY_DEFAULT,
];

yield "COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, '0')" => [
'data' => self::dataDefault(),
'select' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, \'0\') FROM %s t',
'mysql' => self::numericString(),
'sqlite' => TypeCombinator::union(self::float(), self::int(), self::numericString()),
'pdo_pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pdo_pgsql' => PHP_VERSION_ID < 80400
? TypeCombinator::union(self::numericString(), self::int())
: TypeCombinator::union(self::numericString(), self::int(), self::float()),
'pgsql' => TypeCombinator::union(self::numericString(), self::int(), self::float()),
'mssql' => self::mixed(),
'mysqlResult' => '0',
'sqliteResult' => '0',
'pdoPgsqlResult' => 0.0,
'pdoPgsqlResult' => PHP_VERSION_ID < 80400 ? '0' : 0.0,
'pgsqlResult' => 0.0,
'mssqlResult' => 0.0,
'stringify' => self::STRINGIFY_PG_FLOAT,
'stringify' => self::STRINGIFY_DEFAULT,
];

yield 'COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, t.col_string)' => [
Expand Down
10 changes: 7 additions & 3 deletions tests/Platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ Set current working directory to project root.
- `printf "UID=$(id -u)\nGID=$(id -g)" > .env`
- `docker-compose -f tests/Platform/docker/docker-compose.yml up -d`

# Test behaviour with old stringification
# Test behaviour for PHP 8.0 (old stringification)
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php80 composer update`
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php80 php -d memory_limit=1G vendor/bin/phpunit --group=platform`

# Test behaviour with new stringification
# Test behaviour for PHP 8.1 (adjusted stringification)
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php81 composer update`
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php81 php -d memory_limit=1G vendor/bin/phpunit --group=platform`

# Test behaviour for PHP 8.4 (pdo_pgsql float stringification fix)
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php84 composer update`
- `docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php84 php -d memory_limit=1G vendor/bin/phpunit --group=platform`
```

You can also run utilize those containers for PHPStorm PHPUnit configuration.

Since the dataset is huge and takes few minutes to run, you can filter only functions you are interested in:
```sh
docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php81 php -d memory_limit=1G vendor/bin/phpunit --group=platform --filter "AVG"
docker-compose -f tests/Platform/docker/docker-compose.yml run --rm php84 php -d memory_limit=1G vendor/bin/phpunit --group=platform --filter "AVG"
```
24 changes: 24 additions & 0 deletions tests/Platform/docker/Dockerfile84
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM php:8.4.0beta4-cli

# MSSQL
RUN apt update \
&& apt install -y gnupg2 \
&& apt install -y unixodbc-dev unixodbc \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/mssql-tools.list \
&& apt update \
&& ACCEPT_EULA=Y apt install -y msodbcsql17 \
&& pecl install sqlsrv \
&& pecl install pdo_sqlsrv \
&& docker-php-ext-enable sqlsrv pdo_sqlsrv

RUN set -ex \
&& apt update \
&& apt install -y bash zip libpq-dev libsqlite3-dev \
&& pecl install xdebug-3.4 mongodb \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo mysqli pgsql pdo_mysql pdo_pgsql pdo_sqlite \
&& docker-php-ext-enable mongodb # TODO xdebug not yet supported here

COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer

14 changes: 14 additions & 0 deletions tests/Platform/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@ services:
user: ${UID:-1000}:${GID:-1000}
volumes:
- ../../../:/app

php84:
depends_on: [mysql, pgsql]
build:
context: .
dockerfile: ./Dockerfile84
environment:
MYSQL_HOST: mysql
PGSQL_HOST: pgsql
MSSQL_HOST: mssql
working_dir: /app
user: ${UID:-1000}:${GID:-1000}
volumes:
- ../../../:/app

0 comments on commit 5169675

Please sign in to comment.