Skip to content

Commit 57b64e1

Browse files
Poc
1 parent bfb9894 commit 57b64e1

File tree

6 files changed

+122
-8
lines changed

6 files changed

+122
-8
lines changed

Diff for: .github/workflows/test-platforms.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
name: "Test on platforms"
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- "1.3.x"
10+
11+
jobs:
12+
test-mysql:
13+
name: "Tests mysql"
14+
runs-on: "ubuntu-latest"
15+
16+
env:
17+
DATABASE_URL: mysql://[email protected]:3306/phpstan_doctrine
18+
19+
services:
20+
mysql:
21+
image: mysql:${{ matrix.mysql-version }}
22+
options: >-
23+
--health-cmd "mysqladmin ping --silent"
24+
--name=mysqlcontainer
25+
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes
26+
-e MYSQL_DATABASE=phpstan_doctrine
27+
ports:
28+
- 3306:3306
29+
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
php-version:
34+
- "8.2"
35+
mysql-version:
36+
- '5.7'
37+
- '8.0'
38+
39+
steps:
40+
- name: "Checkout"
41+
uses: actions/checkout@v3
42+
43+
- name: "Install PHP"
44+
uses: "shivammathur/setup-php@v2"
45+
with:
46+
coverage: "none"
47+
php-version: "${{ matrix.php-version }}"
48+
ini-file: development
49+
extensions: "mongodb"
50+
51+
- name: "Install dependencies"
52+
run: "composer update --no-interaction --no-progress"
53+
54+
- name: Change mysql sql_mode
55+
run: "docker exec mysqlcontainer mysql -u root -e \"SET GLOBAL sql_mode = '';\""
56+
57+
- name: "Tests"
58+
run: "vendor/bin/phpunit --group=mysql"

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ check: lint cs tests phpstan
33

44
.PHONY: tests
55
tests:
6-
php vendor/bin/phpunit
6+
php vendor/bin/phpunit --exclude-group=platform
77

88
.PHONY: lint
99
lint:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine\Query;
4+
5+
/**
6+
* @group platform
7+
* @group mysql
8+
*/
9+
class MysqlQueryResultTypeWalkerTest extends PDOQueryResultTypeWalkerTest
10+
{
11+
12+
protected static function getEntityManagerPath(): string
13+
{
14+
return __DIR__ . '/../data/QueryResult/entity-manager-mysql.php';
15+
}
16+
17+
}

Diff for: tests/Type/Doctrine/Query/PDOQueryResultTypeWalkerTest.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PHPStan\Type\NullType;
1616
use PHPStan\Type\ObjectType;
1717
use PHPStan\Type\StringType;
18-
use PHPStan\Type\Type;
1918
use PHPStan\Type\TypeCombinator;
2019
use QueryResult\Entities\Many;
2120
use QueryResult\Entities\ManyId;
@@ -29,17 +28,14 @@
2928
use function strpos;
3029
use const PHP_VERSION_ID;
3130

32-
final class PDOQueryResultTypeWalkerTest extends QueryResultTypeWalkerTestCase
31+
class PDOQueryResultTypeWalkerTest extends QueryResultTypeWalkerTestCase
3332
{
3433

3534
protected static function getEntityManagerPath(): string
3635
{
3736
return __DIR__ . '/../data/QueryResult/entity-manager.php';
3837
}
3938

40-
/**
41-
* @return iterable<string,array{Type,string,2?:string|null}>
42-
*/
4339
public function getTestData(): iterable
4440
{
4541
$ormVersion = InstalledVersions::getVersion('doctrine/orm');

Diff for: tests/Type/Doctrine/Query/QueryResultTypeWalkerTestCase.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848

4949
abstract class QueryResultTypeWalkerTestCase extends PHPStanTestCase
5050
{
51+
5152
/** @var EntityManagerInterface */
52-
private static $em;
53+
protected static $em;
5354

5455
/** @var DescriptorRegistry */
5556
private $descriptorRegistry;
@@ -182,7 +183,9 @@ public function setUp(): void
182183
$this->descriptorRegistry = self::getContainer()->getByType(DescriptorRegistry::class);
183184
}
184185

185-
/** @dataProvider getTestData */
186+
/**
187+
* @dataProvider getTestData
188+
*/
186189
public function test(Type $expectedType, string $dql, ?string $expectedExceptionMessage = null, ?string $expectedDeprecationMessage = null): void
187190
{
188191
$em = self::$em;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
use Cache\Adapter\PHPArray\ArrayCachePool;
4+
use Doctrine\Common\Annotations\AnnotationReader;
5+
use Doctrine\DBAL\DriverManager;
6+
use Doctrine\ORM\Configuration;
7+
use Doctrine\ORM\EntityManager;
8+
use Doctrine\ORM\Mapping\Column;
9+
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
10+
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
11+
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
12+
13+
$config = new Configuration();
14+
$config->setProxyDir(__DIR__);
15+
$config->setProxyNamespace('PHPstan\Doctrine\OrmProxies');
16+
$config->setMetadataCache(new ArrayCachePool());
17+
18+
$metadataDriver = new MappingDriverChain();
19+
20+
$metadataDriver->addDriver(new AnnotationDriver(
21+
new AnnotationReader(),
22+
[__DIR__ . '/Entities']
23+
), 'QueryResult\Entities\\');
24+
25+
if (property_exists(Column::class, 'enumType') && PHP_VERSION_ID >= 80100) {
26+
$metadataDriver->addDriver(new AnnotationDriver(
27+
new AnnotationReader(),
28+
[__DIR__ . '/EntitiesEnum']
29+
), 'QueryResult\EntitiesEnum\\');
30+
}
31+
32+
$config->setMetadataDriverImpl($metadataDriver);
33+
34+
return new EntityManager(
35+
DriverManager::getConnection([
36+
'driver' => 'mysql',
37+
'url' => 'mysql://[email protected]:3306/phpstan_doctrine',
38+
]),
39+
$config
40+
);

0 commit comments

Comments
 (0)