Skip to content

Commit c1e2dd8

Browse files
committedJun 7, 2025··
PHPUnit 10
2 parents e233fcb + 9291fc9 commit c1e2dd8

22 files changed

+3370
-991
lines changed
 

‎.github/workflows/lint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ jobs:
3939
coverage: "none"
4040
php-version: "${{ matrix.php-version }}"
4141

42+
- name: "Downgrade PHPUnit"
43+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
44+
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 --update-with-dependencies --ignore-platform-reqs"
45+
4246
- name: "Install dependencies"
4347
run: "composer install --no-interaction --no-progress"
4448

4549
- name: "Transform source code"
46-
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3' && matrix.php-version != '8.4'
50+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
4751
run: |
4852
composer install --no-interaction --no-progress --working-dir=compiler
4953
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}

‎.github/workflows/phar.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
- name: "Install dependencies"
4242
run: "composer install --no-interaction --no-progress"
4343

44+
# only sebastian/diff ^4 supports PHP 7.4 so we need that in the PHAR
45+
- name: "Downgrade PHPUnit"
46+
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 --update-with-dependencies --ignore-platform-reqs"
47+
4448
- name: "Install compiler dependencies"
4549
run: "composer install --no-interaction --no-progress --working-dir=compiler"
4650

‎.github/workflows/reflection-golden-test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
run: "composer install --no-interaction --no-progress"
101101

102102
- name: "Transform source code"
103-
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3' && matrix.php-version != '8.4'
103+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
104104
run: |
105105
composer install --no-interaction --no-progress --working-dir=compiler
106106
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}
@@ -118,11 +118,15 @@ jobs:
118118
- name: "Checkout"
119119
uses: actions/checkout@v4
120120

121+
- name: "Downgrade PHPUnit"
122+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
123+
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 --update-with-dependencies --ignore-platform-reqs"
124+
121125
- name: "Install dependencies"
122126
run: "composer install --no-interaction --no-progress"
123127

124128
- name: "Transform source code"
125-
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3' && matrix.php-version != '8.4'
129+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
126130
run: |
127131
composer install --no-interaction --no-progress --working-dir=compiler
128132
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}

‎.github/workflows/static-analysis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,22 @@ jobs:
4848
ini-file: development
4949
extensions: mbstring
5050

51+
- name: "Downgrade PHPUnit"
52+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
53+
shell: bash
54+
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 --update-with-dependencies --ignore-platform-reqs"
55+
5156
- name: "Install dependencies"
5257
run: "composer install --no-interaction --no-progress"
5358

5459
- name: "Transform source code"
55-
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3' && matrix.php-version != '8.4'
60+
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
5661
shell: bash
5762
run: |
5863
composer install --no-interaction --no-progress --working-dir=compiler
5964
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}
6065
composer dump
6166
62-
6367
- name: "PHPStan"
6468
run: "make phpstan"
6569

‎.github/workflows/tests.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ jobs:
3232
fail-fast: false
3333
matrix:
3434
php-version:
35-
- "7.4"
36-
- "8.0"
3735
- "8.1"
3836
- "8.2"
3937
- "8.3"
@@ -57,15 +55,6 @@ jobs:
5755
- name: "Install dependencies"
5856
run: "composer install --no-interaction --no-progress"
5957

60-
- name: "Transform source code"
61-
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3' && matrix.php-version != '8.4'
62-
shell: bash
63-
run: |
64-
composer install --no-interaction --no-progress --working-dir=compiler
65-
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}
66-
composer dump
67-
68-
6958
- name: "Tests"
7059
run: "make tests"
7160

@@ -118,8 +107,8 @@ jobs:
118107
ini-file: development
119108
ini-values: memory_limit=1G
120109

121-
- name: "Install PHPUnit 10.x"
122-
run: "composer remove --dev brianium/paratest && composer require --dev --with-all-dependencies phpunit/phpunit:^10 sebastian/diff:^5.0"
110+
- name: "Install dependencies"
111+
run: "composer install --no-interaction --no-progress"
123112

124113
- id: set-matrix
125114
run: echo "matrix=$(php .github/workflows/tests-levels-matrix.php)" >> $GITHUB_OUTPUT
@@ -158,3 +147,51 @@ jobs:
158147

159148
- name: "Tests"
160149
run: "${{ matrix.script }}"
150+
151+
tests-with-old-phpunit:
152+
name: "Tests with old PHPUnit"
153+
runs-on: ${{ matrix.operating-system }}
154+
timeout-minutes: 60
155+
156+
strategy:
157+
fail-fast: false
158+
matrix:
159+
php-version:
160+
- "7.4"
161+
- "8.0"
162+
operating-system: [ ubuntu-latest, windows-latest ]
163+
164+
steps:
165+
- name: "Checkout"
166+
uses: actions/checkout@v4
167+
168+
- name: "Install PHP"
169+
uses: "shivammathur/setup-php@v2"
170+
with:
171+
coverage: "none"
172+
php-version: "${{ matrix.php-version }}"
173+
tools: pecl
174+
extensions: ds,mbstring
175+
ini-file: development
176+
ini-values: memory_limit=2G
177+
178+
- name: "Downgrade PHPUnit"
179+
shell: bash
180+
run: "composer require --dev phpunit/phpunit:^9.6 sebastian/diff:^4.0 --update-with-dependencies --ignore-platform-reqs"
181+
182+
- name: "Install dependencies"
183+
run: "composer install --no-interaction --no-progress"
184+
185+
- name: "Downgrade PHPUnit with Paratest"
186+
shell: bash
187+
run: "composer require --dev phpunit/phpunit:^9.6 brianium/paratest:^6.5 symfony/console:^5.4 symfony/process:^5.4 --update-with-dependencies --ignore-platform-reqs --working-dir=tests"
188+
189+
- name: "Transform source code"
190+
shell: bash
191+
run: |
192+
composer install --no-interaction --no-progress --working-dir=compiler
193+
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ matrix.php-version }}
194+
composer dump
195+
196+
- name: "Tests"
197+
run: "make tests"

‎Makefile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
build: cs tests phpstan
44

5-
tests:
6-
XDEBUG_MODE=off php vendor/bin/paratest --runner WrapperRunner --no-coverage
5+
tests: install-paratest
6+
XDEBUG_MODE=off php tests/vendor/bin/paratest --runner WrapperRunner --no-coverage
77

8-
tests-integration:
9-
php vendor/bin/paratest --runner WrapperRunner --no-coverage --group exec
10-
11-
tests-levels:
12-
php vendor/bin/paratest --runner WrapperRunner --no-coverage --group levels
13-
14-
tests-coverage:
15-
php vendor/bin/paratest --runner WrapperRunner
8+
tests-integration: install-paratest
9+
php tests/vendor/bin/paratest --runner WrapperRunner --no-coverage --group exec
1610

1711
tests-golden-reflection:
18-
php vendor/bin/paratest --runner WrapperRunner --no-coverage tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php
12+
php vendor/bin/phpunit tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php
1913

2014
lint:
2115
XDEBUG_MODE=off php vendor/bin/parallel-lint --colors \
@@ -113,6 +107,9 @@ lint:
113107
--exclude tests/PHPStan/Rules/Playground/data/promote-missing-override.php \
114108
src tests
115109

110+
install-paratest:
111+
composer install --working-dir tests
112+
116113
cs:
117114
composer install --working-dir build-cs && XDEBUG_MODE=off php build-cs/vendor/bin/phpcs
118115

‎build/ignore-by-php-version.neon.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
$includes[] = __DIR__ . '/deprecated-8.4.neon';
3434
}
3535

36+
if (PHP_VERSION_ID < 80100) {
37+
$includes[] = __DIR__ . '/old-phpunit.neon';
38+
} else {
39+
$includes[] = __DIR__ . '/new-phpunit.neon';
40+
}
3641
$config = [];
3742
$config['includes'] = $includes;
3843

‎build/new-phpunit.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Call to an undefined static method PHPUnit\\Framework\\TestCase\:\:assertFileNotExists\(\)\.$#'
5+
identifier: staticMethod.notFound
6+
count: 1
7+
path: ../src/Testing/LevelsTestCase.php

‎build/old-phpunit.neon

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Instanceof references internal interface PHPUnit\\Exception\.$#'
5+
identifier: instanceof.internalInterface
6+
count: 1
7+
path: ../tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php
8+
9+
-
10+
message: '''
11+
#^Call to deprecated method assertFileNotExists\(\) of class PHPUnit\\Framework\\Assert\:
12+
https\://github\.com/sebastianbergmann/phpunit/issues/4077$#
13+
'''
14+
identifier: staticMethod.deprecated
15+
count: 1
16+
path: ../src/Testing/LevelsTestCase.php

‎build/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ parameters:
2626
excludePaths:
2727
- ../tests/*/data/*
2828
- ../tests/tmp/*
29+
- ../tests/vendor/*
2930
- ../tests/PHPStan/Analyser/nsrt/*
3031
- ../tests/PHPStan/Analyser/traits/*
3132
- ../tests/notAutoloaded/*

‎composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"react/promise": "^3.2",
3939
"react/socket": "^1.3",
4040
"react/stream": "^1.1",
41-
"sebastian/diff": "^4.0",
41+
"sebastian/diff": "^5.0",
4242
"symfony/console": "^5.4.3",
4343
"symfony/finder": "^5.4.3",
4444
"symfony/polyfill-intl-grapheme": "^1.23",
@@ -55,14 +55,13 @@
5555
"symfony/polyfill-php73": "*"
5656
},
5757
"require-dev": {
58-
"brianium/paratest": "^6.5",
5958
"cweagans/composer-patches": "^1.7.3",
6059
"php-parallel-lint/php-parallel-lint": "^1.2.0",
6160
"phpstan/phpstan-deprecation-rules": "^2.0.2",
6261
"phpstan/phpstan-nette": "^2.0",
63-
"phpstan/phpstan-phpunit": "^2.0",
62+
"phpstan/phpstan-phpunit": "^2.0.7",
6463
"phpstan/phpstan-strict-rules": "^2.0",
65-
"phpunit/phpunit": "^9.6",
64+
"phpunit/phpunit": "10.5.31",
6665
"shipmonk/composer-dependency-analyser": "^1.5",
6766
"shipmonk/dead-code-detector": "^0.12.0",
6867
"shipmonk/name-collision-detector": "^2.0"

‎composer.lock

Lines changed: 244 additions & 519 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
<exclude-pattern>compiler/tests/*/data/</exclude-pattern>
209209
<exclude-pattern>tests/*/Fixture/</exclude-pattern>
210210
<exclude-pattern>tests/*/cache/</exclude-pattern>
211+
<exclude-pattern>tests/vendor/*</exclude-pattern>
211212
<exclude-pattern>tests/*/data/</exclude-pattern>
212213
<exclude-pattern>tests/*/traits/</exclude-pattern>
213214
<exclude-pattern>tests/PHPStan/Analyser/nsrt/</exclude-pattern>

‎phpstan-baseline.neon

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -747,15 +747,6 @@ parameters:
747747
count: 1
748748
path: src/Rules/RuleLevelHelper.php
749749

750-
-
751-
message: '''
752-
#^Call to deprecated method assertFileNotExists\(\) of class PHPUnit\\Framework\\Assert\:
753-
https\://github\.com/sebastianbergmann/phpunit/issues/4077$#
754-
'''
755-
identifier: staticMethod.deprecated
756-
count: 1
757-
path: src/Testing/LevelsTestCase.php
758-
759750
-
760751
message: '#^Call to function method_exists\(\) with ''PHPUnit\\\\Framework\\\\TestCase'' and ''assertFileDoesNotEx…'' will always evaluate to true\.$#'
761752
identifier: function.alreadyNarrowedType
@@ -2010,24 +2001,12 @@ parameters:
20102001
count: 1
20112002
path: tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php
20122003

2013-
-
2014-
message: '#^Instanceof references internal interface PHPUnit\\Exception\.$#'
2015-
identifier: instanceof.internalInterface
2016-
count: 1
2017-
path: tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php
2018-
20192004
-
20202005
message: '#^Creating new PHPStan\\Php8StubsMap is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
20212006
identifier: phpstanApi.constructor
20222007
count: 1
20232008
path: tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php
20242009

2025-
-
2026-
message: '#^Catching internal class PHPUnit\\Framework\\AssertionFailedError\.$#'
2027-
identifier: catch.internalClass
2028-
count: 1
2029-
path: tests/PHPStan/Rules/WarningEmittingRuleTest.php
2030-
20312010
-
20322011
message: '#^Call to method getComparisonFailure\(\) of internal class PHPUnit\\Framework\\ExpectationFailedException from outside its root namespace PHPUnit\.$#'
20332012
identifier: method.internalClass

‎phpunit.xml

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="tests/bootstrap.php"
5-
cacheResult="false"
6-
colors="true"
7-
executionOrder="random"
8-
failOnRisky="true"
9-
failOnWarning="true"
10-
failOnEmptyTestSuite="true"
11-
beStrictAboutChangesToGlobalState="true"
12-
beStrictAboutCoversAnnotation="true"
13-
beStrictAboutOutputDuringTests="true"
14-
beStrictAboutTodoAnnotatedTests="true"
15-
verbose="false"
16-
convertDeprecationsToExceptions="true">
17-
<testsuites>
18-
<testsuite name="PHPStan">
19-
<directory suffix="Test.php">tests/PHPStan</directory>
20-
<exclude>tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php</exclude>
21-
</testsuite>
22-
</testsuites>
23-
24-
<groups>
25-
<exclude>
26-
<group>exec</group>
27-
<group>levels</group>
28-
</exclude>
29-
</groups>
30-
<logging/>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true" executionOrder="random" failOnRisky="true" failOnWarning="true" failOnEmptyTestSuite="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" beStrictAboutCoverageMetadata="true">
3+
<testsuites>
4+
<testsuite name="PHPStan">
5+
<directory suffix="Test.php">tests/PHPStan</directory>
6+
<exclude>tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php</exclude>
7+
</testsuite>
8+
</testsuites>
9+
<groups>
10+
<exclude>
11+
<group>exec</group>
12+
<group>levels</group>
13+
</exclude>
14+
</groups>
15+
<logging/>
3116
</phpunit>

‎tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

‎tests/PHPStan/Command/IgnoredRegexValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class IgnoredRegexValidatorTest extends PHPStanTestCase
1111
{
1212

13-
public function dataValidate(): array
13+
public static function dataValidate(): array
1414
{
1515
return [
1616
[
Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Reflection;
4+
5+
use PHPStan\Testing\PHPStanTestCase;
6+
use PHPStan\Type\Generic\GenericObjectType;
7+
use PHPStan\Type\IntegerType;
8+
use PHPStan\Type\VerbosityLevel;
9+
use function count;
10+
use const PHP_VERSION_ID;
11+
12+
class ClassReflectionPropertyHooksTest extends PHPStanTestCase
13+
{
14+
15+
protected function setUp(): void
16+
{
17+
if (PHP_VERSION_ID >= 80400) {
18+
return;
19+
}
20+
21+
self::markTestSkipped('Test requires PHP 8.4');
22+
}
23+
24+
public static function dataPropertyHooks(): iterable
25+
{
26+
if (PHP_VERSION_ID < 80100) {
27+
return [];
28+
}
29+
30+
$reflectionProvider = self::createReflectionProvider();
31+
32+
yield [
33+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
34+
'i',
35+
'set',
36+
['int'],
37+
'void',
38+
true,
39+
];
40+
41+
yield [
42+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
43+
'i',
44+
'get',
45+
[],
46+
'int',
47+
true,
48+
];
49+
50+
yield [
51+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
52+
'l',
53+
'get',
54+
[],
55+
'array<string>',
56+
true,
57+
];
58+
59+
yield [
60+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
61+
'n',
62+
'set',
63+
['array<string>|int'],
64+
'void',
65+
true,
66+
];
67+
68+
yield [
69+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
70+
'i',
71+
'set',
72+
['int'],
73+
'void',
74+
false,
75+
];
76+
77+
yield [
78+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
79+
'k',
80+
'set',
81+
['int|string'],
82+
'void',
83+
false,
84+
];
85+
86+
yield [
87+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
88+
'l',
89+
'set',
90+
['array<string>'],
91+
'void',
92+
false,
93+
];
94+
95+
yield [
96+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
97+
'm',
98+
'set',
99+
['array<string>'],
100+
'void',
101+
false,
102+
];
103+
104+
yield [
105+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
106+
'n',
107+
'set',
108+
['array<string>|int'],
109+
'void',
110+
false,
111+
];
112+
113+
yield [
114+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
115+
'i',
116+
'set',
117+
['int'],
118+
'void',
119+
true,
120+
];
121+
122+
yield [
123+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
124+
'j',
125+
'set',
126+
['int'],
127+
'void',
128+
true,
129+
];
130+
131+
yield [
132+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
133+
'k',
134+
'set',
135+
['int|string'],
136+
'void',
137+
true,
138+
];
139+
140+
yield [
141+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
142+
'l',
143+
'set',
144+
['array<string>'],
145+
'void',
146+
true,
147+
];
148+
149+
yield [
150+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
151+
'l',
152+
'get',
153+
[],
154+
'array<string>',
155+
true,
156+
];
157+
158+
yield [
159+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
160+
'm',
161+
'set',
162+
['array<string>'],
163+
'void',
164+
true,
165+
];
166+
167+
yield [
168+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
169+
'n',
170+
'set',
171+
['array<string>|int'],
172+
'void',
173+
true,
174+
];
175+
176+
yield [
177+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
178+
'l',
179+
'set',
180+
['array<string>'],
181+
'void',
182+
true,
183+
];
184+
185+
yield [
186+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
187+
'l',
188+
'get',
189+
[],
190+
'array<string>',
191+
true,
192+
];
193+
194+
yield [
195+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
196+
'm',
197+
'set',
198+
['array<string>'],
199+
'void',
200+
true,
201+
];
202+
203+
yield [
204+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
205+
'm',
206+
'set',
207+
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>'],
208+
'void',
209+
true,
210+
];
211+
212+
yield [
213+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
214+
'n',
215+
'set',
216+
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>|int'],
217+
'void',
218+
true,
219+
];
220+
221+
yield [
222+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
223+
'm',
224+
'get',
225+
[],
226+
'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>',
227+
true,
228+
];
229+
230+
yield [
231+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
232+
'n',
233+
'get',
234+
[],
235+
'int',
236+
true,
237+
];
238+
239+
$specificFooGenerics = (new GenericObjectType('PropertyHooksTypes\\FooGenerics', [new IntegerType()]))->getClassReflection();
240+
241+
yield [
242+
$specificFooGenerics,
243+
'n',
244+
'set',
245+
['array<int>|int'],
246+
'void',
247+
true,
248+
];
249+
250+
yield [
251+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
252+
'n',
253+
'get',
254+
[],
255+
'int',
256+
true,
257+
];
258+
259+
yield [
260+
$specificFooGenerics,
261+
'm',
262+
'set',
263+
['array<int>'],
264+
'void',
265+
true,
266+
];
267+
268+
yield [
269+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
270+
'm',
271+
'get',
272+
[],
273+
'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>',
274+
true,
275+
];
276+
277+
yield [
278+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
279+
'l',
280+
'set',
281+
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
282+
'void',
283+
true,
284+
];
285+
286+
yield [
287+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
288+
'm',
289+
'set',
290+
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
291+
'void',
292+
true,
293+
];
294+
295+
yield [
296+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
297+
'n',
298+
'set',
299+
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>|int'],
300+
'void',
301+
true,
302+
];
303+
304+
$specificFooGenericsConstructor = (new GenericObjectType('PropertyHooksTypes\\FooGenericsConstructor', [new IntegerType()]))->getClassReflection();
305+
306+
yield [
307+
$specificFooGenericsConstructor,
308+
'n',
309+
'set',
310+
['array<int>|int'],
311+
'void',
312+
true,
313+
];
314+
315+
yield [
316+
$specificFooGenericsConstructor,
317+
'm',
318+
'set',
319+
['array<int>'],
320+
'void',
321+
true,
322+
];
323+
324+
yield [
325+
$specificFooGenericsConstructor,
326+
'm',
327+
'get',
328+
[],
329+
'array<int>',
330+
true,
331+
];
332+
}
333+
334+
/**
335+
* @dataProvider dataPropertyHooks
336+
* @param ExtendedPropertyReflection::HOOK_* $hookName
337+
* @param string[] $parameterTypes
338+
*/
339+
public function testPropertyHooks(
340+
ClassReflection $classReflection,
341+
string $propertyName,
342+
string $hookName,
343+
array $parameterTypes,
344+
string $returnType,
345+
bool $isVirtual,
346+
): void
347+
{
348+
$propertyReflection = $classReflection->getNativeProperty($propertyName);
349+
$this->assertSame($isVirtual, $propertyReflection->isVirtual()->yes());
350+
351+
$hookReflection = $propertyReflection->getHook($hookName);
352+
$hookVariant = $hookReflection->getOnlyVariant();
353+
$this->assertSame($returnType, $hookVariant->getReturnType()->describe(VerbosityLevel::precise()));
354+
$this->assertCount(count($parameterTypes), $hookVariant->getParameters());
355+
356+
foreach ($hookVariant->getParameters() as $i => $parameter) {
357+
$this->assertSame($parameterTypes[$i], $parameter->getType()->describe(VerbosityLevel::precise()));
358+
}
359+
}
360+
361+
}

‎tests/PHPStan/Reflection/ClassReflectionTest.php

Lines changed: 0 additions & 340 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@
2929
use NestedTraits\NoTrait;
3030
use PHPStan\Testing\PHPStanTestCase;
3131
use PHPStan\Testing\RuleTestCase;
32-
use PHPStan\Type\Generic\GenericObjectType;
3332
use PHPStan\Type\IntegerType;
34-
use PHPStan\Type\VerbosityLevel;
3533
use PHPUnit\Framework\TestCase;
3634
use ReflectionClass;
3735
use WrongClassConstantFile\SecuredRouter;
3836
use function array_map;
3937
use function array_values;
40-
use function count;
4138
use const PHP_VERSION_ID;
4239

4340
class ClassReflectionTest extends PHPStanTestCase
@@ -325,341 +322,4 @@ public function testIs(): void
325322
$this->assertFalse($classReflection->is(RuleTestCase::class));
326323
}
327324

328-
public static function dataPropertyHooks(): iterable
329-
{
330-
if (PHP_VERSION_ID < 80400) {
331-
return;
332-
}
333-
334-
$reflectionProvider = self::createReflectionProvider();
335-
336-
yield [
337-
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
338-
'i',
339-
'set',
340-
['int'],
341-
'void',
342-
true,
343-
];
344-
345-
yield [
346-
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
347-
'i',
348-
'get',
349-
[],
350-
'int',
351-
true,
352-
];
353-
354-
yield [
355-
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
356-
'l',
357-
'get',
358-
[],
359-
'array<string>',
360-
true,
361-
];
362-
363-
yield [
364-
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
365-
'n',
366-
'set',
367-
['array<string>|int'],
368-
'void',
369-
true,
370-
];
371-
372-
yield [
373-
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
374-
'i',
375-
'set',
376-
['int'],
377-
'void',
378-
false,
379-
];
380-
381-
yield [
382-
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
383-
'k',
384-
'set',
385-
['int|string'],
386-
'void',
387-
false,
388-
];
389-
390-
yield [
391-
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
392-
'l',
393-
'set',
394-
['array<string>'],
395-
'void',
396-
false,
397-
];
398-
399-
yield [
400-
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
401-
'm',
402-
'set',
403-
['array<string>'],
404-
'void',
405-
false,
406-
];
407-
408-
yield [
409-
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
410-
'n',
411-
'set',
412-
['array<string>|int'],
413-
'void',
414-
false,
415-
];
416-
417-
yield [
418-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
419-
'i',
420-
'set',
421-
['int'],
422-
'void',
423-
true,
424-
];
425-
426-
yield [
427-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
428-
'j',
429-
'set',
430-
['int'],
431-
'void',
432-
true,
433-
];
434-
435-
yield [
436-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
437-
'k',
438-
'set',
439-
['int|string'],
440-
'void',
441-
true,
442-
];
443-
444-
yield [
445-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
446-
'l',
447-
'set',
448-
['array<string>'],
449-
'void',
450-
true,
451-
];
452-
453-
yield [
454-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
455-
'l',
456-
'get',
457-
[],
458-
'array<string>',
459-
true,
460-
];
461-
462-
yield [
463-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
464-
'm',
465-
'set',
466-
['array<string>'],
467-
'void',
468-
true,
469-
];
470-
471-
yield [
472-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
473-
'n',
474-
'set',
475-
['array<string>|int'],
476-
'void',
477-
true,
478-
];
479-
480-
yield [
481-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
482-
'l',
483-
'set',
484-
['array<string>'],
485-
'void',
486-
true,
487-
];
488-
489-
yield [
490-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
491-
'l',
492-
'get',
493-
[],
494-
'array<string>',
495-
true,
496-
];
497-
498-
yield [
499-
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
500-
'm',
501-
'set',
502-
['array<string>'],
503-
'void',
504-
true,
505-
];
506-
507-
yield [
508-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
509-
'm',
510-
'set',
511-
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>'],
512-
'void',
513-
true,
514-
];
515-
516-
yield [
517-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
518-
'n',
519-
'set',
520-
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>|int'],
521-
'void',
522-
true,
523-
];
524-
525-
yield [
526-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
527-
'm',
528-
'get',
529-
[],
530-
'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>',
531-
true,
532-
];
533-
534-
yield [
535-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
536-
'n',
537-
'get',
538-
[],
539-
'int',
540-
true,
541-
];
542-
543-
$specificFooGenerics = (new GenericObjectType('PropertyHooksTypes\\FooGenerics', [new IntegerType()]))->getClassReflection();
544-
545-
yield [
546-
$specificFooGenerics,
547-
'n',
548-
'set',
549-
['array<int>|int'],
550-
'void',
551-
true,
552-
];
553-
554-
yield [
555-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
556-
'n',
557-
'get',
558-
[],
559-
'int',
560-
true,
561-
];
562-
563-
yield [
564-
$specificFooGenerics,
565-
'm',
566-
'set',
567-
['array<int>'],
568-
'void',
569-
true,
570-
];
571-
572-
yield [
573-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
574-
'm',
575-
'get',
576-
[],
577-
'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>',
578-
true,
579-
];
580-
581-
yield [
582-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
583-
'l',
584-
'set',
585-
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
586-
'void',
587-
true,
588-
];
589-
590-
yield [
591-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
592-
'm',
593-
'set',
594-
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
595-
'void',
596-
true,
597-
];
598-
599-
yield [
600-
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
601-
'n',
602-
'set',
603-
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>|int'],
604-
'void',
605-
true,
606-
];
607-
608-
$specificFooGenericsConstructor = (new GenericObjectType('PropertyHooksTypes\\FooGenericsConstructor', [new IntegerType()]))->getClassReflection();
609-
610-
yield [
611-
$specificFooGenericsConstructor,
612-
'n',
613-
'set',
614-
['array<int>|int'],
615-
'void',
616-
true,
617-
];
618-
619-
yield [
620-
$specificFooGenericsConstructor,
621-
'm',
622-
'set',
623-
['array<int>'],
624-
'void',
625-
true,
626-
];
627-
628-
yield [
629-
$specificFooGenericsConstructor,
630-
'm',
631-
'get',
632-
[],
633-
'array<int>',
634-
true,
635-
];
636-
}
637-
638-
/**
639-
* @dataProvider dataPropertyHooks
640-
* @param ExtendedPropertyReflection::HOOK_* $hookName
641-
* @param string[] $parameterTypes
642-
*/
643-
public function testPropertyHooks(
644-
ClassReflection $classReflection,
645-
string $propertyName,
646-
string $hookName,
647-
array $parameterTypes,
648-
string $returnType,
649-
bool $isVirtual,
650-
): void
651-
{
652-
$propertyReflection = $classReflection->getNativeProperty($propertyName);
653-
$this->assertSame($isVirtual, $propertyReflection->isVirtual()->yes());
654-
655-
$hookReflection = $propertyReflection->getHook($hookName);
656-
$hookVariant = $hookReflection->getOnlyVariant();
657-
$this->assertSame($returnType, $hookVariant->getReturnType()->describe(VerbosityLevel::precise()));
658-
$this->assertCount(count($parameterTypes), $hookVariant->getParameters());
659-
660-
foreach ($hookVariant->getParameters() as $i => $parameter) {
661-
$this->assertSame($parameterTypes[$i], $parameter->getType()->describe(VerbosityLevel::precise()));
662-
}
663-
}
664-
665325
}

‎tests/PHPStan/Rules/WarningEmittingRuleTest.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎tests/composer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "phpstan/phpstan-src-tests",
3+
"require-dev": {
4+
"phpunit/phpunit": "10.5.31",
5+
"brianium/paratest": "~7.3.0"
6+
},
7+
"config": {
8+
"platform": {
9+
"php": "8.1.99"
10+
}
11+
}
12+
}

‎tests/composer.lock

Lines changed: 2625 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.