Skip to content

Commit d861d30

Browse files
committed
Platform test: compare inferred types with real SQL engine results
1 parent f6081cf commit d861d30

File tree

13 files changed

+623
-2
lines changed

13 files changed

+623
-2
lines changed
Lines changed: 58 additions & 0 deletions
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: "Platform matrix test"
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- "1.4.x"
10+
11+
jobs:
12+
tests:
13+
name: "Platform matrix test"
14+
runs-on: "ubuntu-latest"
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
php-version:
20+
- "8.0"
21+
- "8.1"
22+
23+
steps:
24+
- name: "Checkout"
25+
uses: actions/checkout@v4
26+
27+
- name: "Install PHP"
28+
uses: "shivammathur/setup-php@v2"
29+
with:
30+
coverage: "none"
31+
php-version: "${{ matrix.php-version }}"
32+
ini-file: development
33+
extensions: pdo, mysqli, pgsql, pdo_mysql, pdo_pgsql, pdo_sqlite, mongodb
34+
35+
- name: "Install dependencies"
36+
run: "composer install --no-interaction --no-progress"
37+
38+
- name: "Run platform matrix test"
39+
run: vendor/bin/phpunit --group=platform
40+
41+
services:
42+
postgres:
43+
image: "postgres:latest"
44+
env:
45+
POSTGRES_PASSWORD: "secret"
46+
POSTGRES_USER: root
47+
POSTGRES_DB: foo
48+
ports:
49+
- "5432:5432"
50+
51+
mysql:
52+
image: "mysql:latest"
53+
env:
54+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
55+
MYSQL_ROOT_PASSWORD: secret
56+
MYSQL_DATABASE: foo
57+
ports:
58+
- "3306:3306"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/build-cs
33
/vendor
44
/composer.lock
5+
/.env
56
.phpunit.result.cache

Makefile

Lines changed: 1 addition & 1 deletion
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:

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ parameters:
4343
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\EntityManager'' and ''create'' will always evaluate to true\.$#'
4444
path: src/Doctrine/Mapping/ClassMetadataFactory.php
4545
reportUnmatched: false
46+
-
47+
message: '#^Call to function method_exists\(\) with Doctrine\\DBAL\\Connection and ''getNativeConnection'' will always evaluate to true\.$#'
48+
path: tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php
49+
reportUnmatched: false

src/Type/Doctrine/Descriptors/BooleanType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function getDatabaseInternalType(): Type
2828
{
2929
return TypeCombinator::union(
3030
new ConstantIntegerType(0),
31-
new ConstantIntegerType(1)
31+
new ConstantIntegerType(1),
32+
new \PHPStan\Type\BooleanType()
3233
);
3334
}
3435

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Platform\MatrixEntity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Table(name="test")
9+
* @ORM\Entity
10+
*/
11+
class TestEntity
12+
{
13+
14+
/**
15+
* @ORM\Id
16+
* @ORM\Column(type="string", name="col_string", nullable=false)
17+
* @var string
18+
*/
19+
public $col_string;
20+
21+
/**
22+
* @ORM\Id
23+
* @ORM\Column(type="boolean", name="col_bool", nullable=false)
24+
* @var bool
25+
*/
26+
public $col_bool;
27+
28+
/**
29+
* @ORM\Id
30+
* @ORM\Column(type="float", name="col_float", nullable=false)
31+
* @var float
32+
*/
33+
public $col_float;
34+
35+
/**
36+
* @ORM\Id
37+
* @ORM\Column(type="decimal", name="col_decimal", nullable=false, scale=1, precision=2)
38+
* @var string
39+
*/
40+
public $col_decimal;
41+
42+
/**
43+
* @ORM\Id
44+
* @ORM\Column(type="integer", name="col_int", nullable=false)
45+
* @var int
46+
*/
47+
public $col_int;
48+
49+
/**
50+
* @ORM\Id
51+
* @ORM\Column(type="bigint", name="col_bigint", nullable=false)
52+
* @var int
53+
*/
54+
public $col_bigint;
55+
56+
}

0 commit comments

Comments
 (0)