Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform test: test more php versions, orm3 and dbal4 #577

Merged
merged 2 commits into from
Jun 25, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Platform matrix test"
name: "Platform test"

on:
pull_request:
Expand All @@ -10,18 +10,31 @@ on:

jobs:
tests:
name: "Platform matrix test"
name: "Platform test"
runs-on: "ubuntu-latest"
env:
MYSQL_HOST: '127.0.0.1'
PGSQL_HOST: '127.0.0.1'
MSSQL_HOST: '127.0.0.1'

strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
update-packages:
- ""
include:
- php-version: "8.1"
update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3
- php-version: "8.2"
update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3
- php-version: "8.3"
update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3

steps:
- name: "Checkout"
Expand All @@ -38,6 +51,10 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Update packages"
if: ${{ matrix.update-packages != '' }}
run: composer require --dev ${{ matrix.update-packages }} -W

- name: "Run platform matrix test"
run: vendor/bin/phpunit --group=platform

Expand All @@ -59,3 +76,12 @@ jobs:
MYSQL_DATABASE: foo
ports:
- "3306:3306"

mssql:
image: mcr.microsoft.com/mssql/server:latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: 'Secret.123'
MSSQL_PID: Developer
ports:
- 1433:1433
Original file line number Diff line number Diff line change
@@ -1,56 +1,67 @@
<?php declare(strict_types = 1);

namespace PHPStan\Platform\MatrixEntity;
namespace PHPStan\Platform\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="test")
* @ORM\Entity
*/
class TestEntity
#[ORM\Table(name: 'test')]
#[ORM\Entity]
class PlatformEntity
{

/**
* @ORM\Id
* @ORM\Column(type="string",nullable=false)
* @var string
*/
#[ORM\Id]
#[ORM\Column(type: 'string', nullable: false)]
public $id;

/**
* @ORM\Column(type="string", name="col_string", nullable=false)
* @var string
*/
#[ORM\Column(type: 'string', name: 'col_string', nullable: false)]
public $col_string;

/**
* @ORM\Id
* @ORM\Column(type="boolean", name="col_bool", nullable=false)
* @var bool
*/
#[ORM\Column(type: 'boolean', name: 'col_bool', nullable: false)]
public $col_bool;

/**
* @ORM\Id
* @ORM\Column(type="float", name="col_float", nullable=false)
* @var float
*/
#[ORM\Column(type: 'float', name: 'col_float', nullable: false)]
public $col_float;

/**
* @ORM\Id
* @ORM\Column(type="decimal", name="col_decimal", nullable=false, scale=1, precision=2)
* @var string
*/
#[ORM\Column(type: 'decimal', name: 'col_decimal', nullable: false, scale: 1, precision: 2)]
public $col_decimal;

/**
* @ORM\Id
* @ORM\Column(type="integer", name="col_int", nullable=false)
* @var int
*/
#[ORM\Column(type: 'integer', name: 'col_int', nullable: false)]
public $col_int;

/**
* @ORM\Id
* @ORM\Column(type="bigint", name="col_bigint", nullable=false)
* @var string
* @var int|string
*/
#[ORM\Column(type: 'bigint', name: 'col_bigint', nullable: false)]
public $col_bigint;

}
31 changes: 26 additions & 5 deletions tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
namespace PHPStan\Platform;

use Cache\Adapter\PHPArray\ArrayCachePool;
use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception as DbalException;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Tools\SchemaTool;
use LogicException;
use mysqli;
use PDO;
use PHPStan\Platform\MatrixEntity\TestEntity;
use PHPStan\Platform\Entity\PlatformEntity;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\ConstantTypeHelper;
use PHPStan\Type\Doctrine\DescriptorRegistry;
Expand All @@ -25,7 +28,9 @@
use SQLite3;
use function array_column;
use function array_combine;
use function array_fill;
use function array_keys;
use function class_exists;
use function function_exists;
use function get_debug_type;
use function getenv;
Expand Down Expand Up @@ -89,7 +94,13 @@ public function testFetchedTypes(
$config->setAutoGenerateProxyClasses(false);
$config->setSecondLevelCacheEnabled(false);
$config->setMetadataCache(new ArrayCachePool());
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/MatrixEntity']));

if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/orm', '3.*')) {
$config->setMetadataDriverImpl(new AttributeDriver([__DIR__ . '/Entity']));
} else {
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/Entity']));
}

$entityManager = new EntityManager($connection, $config);

} catch (DbalException $e) {
Expand All @@ -104,7 +115,8 @@ public function testFetchedTypes(
$schemaTool->dropSchema($classes);
$schemaTool->createSchema($classes);

$entity = new TestEntity();
$entity = new PlatformEntity();
$entity->id = '1';
$entity->col_bool = true;
$entity->col_float = 0.125;
$entity->col_decimal = '0.1';
Expand All @@ -125,7 +137,7 @@ public function testFetchedTypes(
if ($expectedType === null) {
continue; // e.g. no such function
}
$dql = sprintf($columnsQueryTemplate, $select, TestEntity::class);
$dql = sprintf($columnsQueryTemplate, $select, PlatformEntity::class);

$query = $entityManager->createQuery($dql);
$result = $query->getSingleResult();
Expand Down Expand Up @@ -214,7 +226,7 @@ public function provideCases(): iterable
'1' => ['int', 'int', 'int', 'int', 'string', 'string'],
'2147483648' => ['int', 'int', 'int', 'int', 'string', 'string'],
't.col_int' => ['int', 'int', 'int', 'int', 'int', 'int'],
't.col_bigint' => ['string', 'string', 'string', 'string', 'string', 'string'],
't.col_bigint' => self::hasDbal4() ? array_fill(0, 6, 'int') : array_fill(0, 6, 'string'),
'SUM(t.col_int)' => ['string', 'int', 'int', 'int', 'string', 'string'],
'SUM(t.col_bigint)' => ['string', 'int', 'string', 'string', 'string', 'string'],
"LENGTH('')" => ['int', 'int', 'int', 'int', 'int', 'int'],
Expand Down Expand Up @@ -408,4 +420,13 @@ private function getNativeConnection(Connection $connection)
throw new LogicException('Unable to get native connection');
}

private static function hasDbal4(): bool
{
if (!class_exists(InstalledVersions::class)) {
return false;
}

return InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '4.*');
}

}