Skip to content

Commit 74982d6

Browse files
committed
Run tests and PHPStan on PHP 8.5
1 parent 0f0ba0a commit 74982d6

File tree

8 files changed

+311
-6
lines changed

8 files changed

+311
-6
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- "8.2"
2626
- "8.3"
2727
- "8.4"
28+
- "8.5"
2829
operating-system:
2930
- "ubuntu-latest"
3031
- "windows-latest"
@@ -69,6 +70,7 @@ jobs:
6970
- "8.2"
7071
- "8.3"
7172
- "8.4"
73+
- "8.5"
7274
operating-system:
7375
- "ubuntu-latest"
7476

@@ -110,6 +112,8 @@ jobs:
110112
- "locked"
111113
php-version:
112114
- "8.4"
115+
# Psalm currently fails
116+
# - "8.5"
113117
operating-system:
114118
- "ubuntu-latest"
115119

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Better Reflection - an improved code reflection API",
44
"license": "MIT",
55
"require": {
6-
"php": "~8.2.0 || ~8.3.2 || ~8.4.1",
6+
"php": "~8.2.0 || ~8.3.2 || ~8.4.1 || ~8.5.0",
77
"ext-json": "*",
88
"jetbrains/phpstorm-stubs": "2024.3",
99
"nikic/php-parser": "^5.6.0"

composer.lock

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

src/Reflection/Adapter/ReflectionProperty.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ReflectionException as CoreReflectionException;
1111
use ReflectionMethod as CoreReflectionMethod;
1212
use ReflectionProperty as CoreReflectionProperty;
13+
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
1314
use Roave\BetterReflection\Reflection\Exception\NoObjectProvided;
1415
use Roave\BetterReflection\Reflection\Exception\NotAnObject;
1516
use Roave\BetterReflection\Reflection\ReflectionAttribute as BetterReflectionAttribute;
@@ -355,4 +356,9 @@ public function __get(string $name): mixed
355356

356357
throw new OutOfBoundsException(sprintf('Property %s::$%s does not exist.', self::class, $name));
357358
}
359+
360+
public function getMangledName(): string
361+
{
362+
throw new NotImplemented('Not implemented');
363+
}
358364
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
namespace Roave\BetterReflectionTest\Fixture;
4+
5+
use JsonSerializable;
6+
use Serializable;
7+
8+
class ParentClassForSourceStubber
9+
{
10+
public function methodFromParentClass()
11+
{
12+
}
13+
}
14+
15+
interface ImplementedInterfaceForSourceStubber extends JsonSerializable
16+
{
17+
public function methodFromInterface();
18+
}
19+
20+
trait UsedParentTraitForSourceStubber
21+
{
22+
public $propertyFromParentTrait;
23+
24+
public function methodFromParentTrait()
25+
{
26+
}
27+
}
28+
29+
trait UsedTraitForSourceStubber
30+
{
31+
use UsedParentTraitForSourceStubber;
32+
33+
protected $propertyFromTrait;
34+
35+
public function methodFromTrait()
36+
{
37+
}
38+
}
39+
40+
trait UsedTraitToAliasForSourceStubber
41+
{
42+
public function methodFromTraitToAlias()
43+
{
44+
}
45+
}
46+
47+
/**
48+
* Class comment
49+
*/
50+
abstract class PHP85ClassForSourceStubber extends ParentClassForSourceStubber implements ImplementedInterfaceForSourceStubber, Serializable
51+
{
52+
use UsedTraitForSourceStubber;
53+
use UsedTraitToAliasForSourceStubber {
54+
UsedTraitToAliasForSourceStubber::methodFromTraitToAlias as aliasMethodFromTrait;
55+
}
56+
57+
/**
58+
* Constant comment
59+
*/
60+
const CONSTANT_WITHOUT_VISIBILITY = 1;
61+
public const PUBLIC_CONSTANT = 0.0;
62+
protected const PROTECTED_CONSTANT = 'string';
63+
private const PRIVATE_CONSTANT = [1, 2, 3];
64+
65+
var $propertyWithoutVisibility = 0;
66+
67+
/**
68+
* @var int|float|\stdClass
69+
*/
70+
private $privateProperty = 1.1;
71+
72+
/**
73+
* @var bool|bool[]|bool[][]
74+
*/
75+
protected $protectedProperty = false;
76+
77+
/**
78+
* @var string
79+
*/
80+
public $publicProperty = 'string';
81+
82+
public static $publicStaticProperty;
83+
84+
public int $propertyWithTypeHint;
85+
86+
function methodWithoutVisibility() : ?\stdClass
87+
{
88+
}
89+
90+
/**
91+
* Method comment
92+
*/
93+
public function publicMethod() : bool
94+
{
95+
}
96+
97+
public function protectedMethod() : int
98+
{
99+
}
100+
101+
public function privateMethod() : ?string
102+
{
103+
}
104+
105+
public static function publicStaticMethod() : void
106+
{
107+
}
108+
109+
abstract public function publicAbstractMethod();
110+
111+
final public function publicFinalMethod() : float
112+
{
113+
}
114+
115+
public function methodWithParameters($string, $int, $float, $bool, $iterable, $callable) : void
116+
{
117+
}
118+
119+
public function methodWithParametersWithTypes(string $string, int $int, float $float, bool $bool, iterable $iterable, callable $callable) : void
120+
{
121+
}
122+
123+
public function methodWithParametersWithNullableTypes(?string $string, ?int $int, ?float $float, ?bool $bool, ?iterable $iterable, ?callable $callable) : void
124+
{
125+
}
126+
127+
public function methodWithOptionalParameters(string $string = 'string', int $int = 123, float $float = 0.0, bool $bool = true, iterable $iterable = [], ?callable $callable = null) : void
128+
{
129+
}
130+
131+
public function methodWithSelfAndParentParameters(self $self, parent $parent) : void
132+
{
133+
}
134+
135+
public function methodWithVariadicParameter(string ...$variadic) : void
136+
{
137+
}
138+
139+
public function methodWithParameterPassedByReference(bool &$bool) : void
140+
{
141+
}
142+
143+
public function &methodReturnsReference() : array
144+
{
145+
}
146+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Roave\BetterReflectionTest\Fixture;
4+
5+
/**
6+
* Class comment
7+
*/
8+
abstract class PHP85ClassForSourceStubber extends \Roave\BetterReflectionTest\Fixture\ParentClassForSourceStubber implements \Roave\BetterReflectionTest\Fixture\ImplementedInterfaceForSourceStubber, \Serializable
9+
{
10+
use \Roave\BetterReflectionTest\Fixture\UsedTraitForSourceStubber;
11+
use \Roave\BetterReflectionTest\Fixture\UsedTraitToAliasForSourceStubber {
12+
\Roave\BetterReflectionTest\Fixture\UsedTraitToAliasForSourceStubber::methodFromTraitToAlias as aliasMethodFromTrait;
13+
}
14+
/**
15+
* Constant comment
16+
*/
17+
public const CONSTANT_WITHOUT_VISIBILITY = 1;
18+
public const PUBLIC_CONSTANT = 0.0;
19+
protected const PROTECTED_CONSTANT = 'string';
20+
private const PRIVATE_CONSTANT = [1, 2, 3];
21+
public $propertyWithoutVisibility = 0;
22+
/**
23+
* @var int|float|\stdClass
24+
*/
25+
private $privateProperty = 1.1;
26+
/**
27+
* @var bool|bool[]|bool[][]
28+
*/
29+
protected $protectedProperty = false;
30+
/**
31+
* @var string
32+
*/
33+
public $publicProperty = 'string';
34+
public static $publicStaticProperty = null;
35+
public int $propertyWithTypeHint;
36+
public function methodWithoutVisibility(): ?\stdClass
37+
{
38+
}
39+
/**
40+
* Method comment
41+
*/
42+
public function publicMethod(): bool
43+
{
44+
}
45+
public function protectedMethod(): int
46+
{
47+
}
48+
public function privateMethod(): ?string
49+
{
50+
}
51+
public static function publicStaticMethod(): void
52+
{
53+
}
54+
abstract public function publicAbstractMethod();
55+
final public function publicFinalMethod(): float
56+
{
57+
}
58+
public function methodWithParameters($string, $int, $float, $bool, $iterable, $callable): void
59+
{
60+
}
61+
public function methodWithParametersWithTypes(string $string, int $int, float $float, bool $bool, iterable $iterable, callable $callable): void
62+
{
63+
}
64+
public function methodWithParametersWithNullableTypes(?string $string, ?int $int, ?float $float, ?bool $bool, ?iterable $iterable, ?callable $callable): void
65+
{
66+
}
67+
public function methodWithOptionalParameters(string $string = 'string', int $int = 123, float $float = 0.0, bool $bool = true, iterable $iterable = [], ?callable $callable = null): void
68+
{
69+
}
70+
public function methodWithSelfAndParentParameters(\Roave\BetterReflectionTest\Fixture\PHP85ClassForSourceStubber $self, \Roave\BetterReflectionTest\Fixture\ParentClassForSourceStubber $parent): void
71+
{
72+
}
73+
public function methodWithVariadicParameter(string ...$variadic): void
74+
{
75+
}
76+
public function methodWithParameterPassedByReference(bool &$bool): void
77+
{
78+
}
79+
public function &methodReturnsReference(): array
80+
{
81+
}
82+
}

test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ static function (string $className): bool {
133133
return false;
134134
}
135135

136+
// Missing in JetBrains/phpstorm-stubs
137+
/** @var list<class-string> $missingClasses */
138+
$missingClasses = ['NoDiscard'];
139+
if (
140+
PHP_VERSION_ID >= 80500
141+
&& in_array($className, $missingClasses, true)
142+
) {
143+
return false;
144+
}
145+
136146
// Check only always enabled extensions
137147
return in_array($reflection->getExtensionName(), self::EXTENSIONS, true);
138148
},
@@ -188,8 +198,17 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
188198
$this->assertSameInterfaces($original, $stubbed);
189199

190200
foreach ($original->getMethods() as $method) {
201+
$methodName = $original->getName() . '#' . $method->getName();
202+
203+
// Needs fixes in JetBrains/phpstorm-stubs
204+
if (
205+
in_array($methodName, ['Closure#getCurrent'], true)
206+
) {
207+
continue;
208+
}
209+
191210
$stubbedMethod = $stubbed->getMethod($method->getName());
192-
self::assertNotNull($stubbedMethod);
211+
self::assertNotNull($stubbedMethod, $methodName);
193212

194213
$this->assertSameMethodAttributes($method, $stubbedMethod);
195214
}
@@ -204,10 +223,19 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
204223
$originalConstantName = $originalConstant->getName();
205224
assert($originalConstantName !== '');
206225

226+
$constantName = $original->getName() . '::' . $originalConstant->getName();
227+
228+
// Needs fixes in JetBrains/phpstorm-stubs
229+
if (
230+
in_array($constantName, ['Attribute::TARGET_CONSTANT'], true)
231+
) {
232+
continue;
233+
}
234+
207235
$stubbedConstant = $stubbed->getConstant($originalConstantName);
208236

209-
self::assertNotNull($stubbedConstant);
210-
self::assertSame($originalConstant->getValue(), $stubbedConstant->getValue());
237+
self::assertNotNull($stubbedConstant, $constantName);
238+
self::assertSame($originalConstant->getValue(), $stubbedConstant->getValue(), $constantName);
211239
}
212240
}
213241

@@ -301,6 +329,20 @@ public static function internalFunctionsProvider(): array
301329
static function (string $functionName): bool {
302330
$reflection = new CoreReflectionFunction($functionName);
303331

332+
// Missing in JetBrains/phpstorm-stubs
333+
if (
334+
PHP_VERSION_ID >= 80500
335+
&& in_array($functionName, [
336+
'array_first',
337+
'array_last',
338+
'clone',
339+
'get_error_handler',
340+
'get_exception_handler',
341+
], true)
342+
) {
343+
return false;
344+
}
345+
304346
// Check only always enabled extensions
305347
return in_array($reflection->getExtensionName(), self::EXTENSIONS, true);
306348
},
@@ -361,6 +403,18 @@ public static function internalConstantsProvider(): array
361403
}
362404

363405
foreach ($extensionConstants as $constantName => $constantValue) {
406+
// Missing in JetBrains/phpstorm-stubs
407+
if (
408+
PHP_VERSION_ID >= 80500
409+
&& in_array($constantName, [
410+
'IMAGETYPE_SVG',
411+
'IMAGETYPE_HEIF',
412+
'PHP_BUILD_DATE',
413+
], true)
414+
) {
415+
continue;
416+
}
417+
364418
$provider[] = [$constantName, $constantValue, $extensionName];
365419
}
366420
}

0 commit comments

Comments
 (0)