Skip to content

Commit 53dd017

Browse files
authored
Merge pull request #1515 from kukulich/php85
Run tests and PHPStan on PHP 8.5
2 parents 0f0ba0a + 8e337a7 commit 53dd017

File tree

8 files changed

+110
-6
lines changed

8 files changed

+110
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Roave\BetterReflectionTest\Fixture;
4+
5+
class ParentClassForSourceStubber
6+
{
7+
}
8+
9+
abstract class PHP85ClassForSourceStubber extends ParentClassForSourceStubber
10+
{
11+
public function methodWithSelfAndParentParameters(self $self, parent $parent) : void
12+
{
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Roave\BetterReflectionTest\Fixture;
4+
5+
abstract class PHP85ClassForSourceStubber extends \Roave\BetterReflectionTest\Fixture\ParentClassForSourceStubber
6+
{
7+
public function methodWithSelfAndParentParameters(\Roave\BetterReflectionTest\Fixture\PHP85ClassForSourceStubber $self, \Roave\BetterReflectionTest\Fixture\ParentClassForSourceStubber $parent): void
8+
{
9+
}
10+
}

test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php

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

136+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
137+
/** @var list<class-string> $missingClasses */
138+
$missingClasses = [
139+
'NoDiscard',
140+
'DelayedTargetValidation',
141+
];
142+
if (
143+
PHP_VERSION_ID >= 80500
144+
&& in_array($className, $missingClasses, true)
145+
) {
146+
return false;
147+
}
148+
136149
// Check only always enabled extensions
137150
return in_array($reflection->getExtensionName(), self::EXTENSIONS, true);
138151
},
@@ -188,8 +201,17 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
188201
$this->assertSameInterfaces($original, $stubbed);
189202

190203
foreach ($original->getMethods() as $method) {
204+
$methodName = $original->getName() . '#' . $method->getName();
205+
206+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
207+
if (
208+
in_array($methodName, ['Closure#getCurrent'], true)
209+
) {
210+
continue;
211+
}
212+
191213
$stubbedMethod = $stubbed->getMethod($method->getName());
192-
self::assertNotNull($stubbedMethod);
214+
self::assertNotNull($stubbedMethod, $methodName);
193215

194216
$this->assertSameMethodAttributes($method, $stubbedMethod);
195217
}
@@ -204,10 +226,19 @@ private function assertSameClassAttributes(CoreReflectionClass $original, Reflec
204226
$originalConstantName = $originalConstant->getName();
205227
assert($originalConstantName !== '');
206228

229+
$constantName = $original->getName() . '::' . $originalConstant->getName();
230+
231+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
232+
if (
233+
in_array($constantName, ['Attribute::TARGET_CONSTANT'], true)
234+
) {
235+
continue;
236+
}
237+
207238
$stubbedConstant = $stubbed->getConstant($originalConstantName);
208239

209-
self::assertNotNull($stubbedConstant);
210-
self::assertSame($originalConstant->getValue(), $stubbedConstant->getValue());
240+
self::assertNotNull($stubbedConstant, $constantName);
241+
self::assertSame($originalConstant->getValue(), $stubbedConstant->getValue(), $constantName);
211242
}
212243
}
213244

@@ -301,6 +332,20 @@ public static function internalFunctionsProvider(): array
301332
static function (string $functionName): bool {
302333
$reflection = new CoreReflectionFunction($functionName);
303334

335+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
336+
if (
337+
PHP_VERSION_ID >= 80500
338+
&& in_array($functionName, [
339+
'array_first',
340+
'array_last',
341+
'clone',
342+
'get_error_handler',
343+
'get_exception_handler',
344+
], true)
345+
) {
346+
return false;
347+
}
348+
304349
// Check only always enabled extensions
305350
return in_array($reflection->getExtensionName(), self::EXTENSIONS, true);
306351
},
@@ -361,6 +406,18 @@ public static function internalConstantsProvider(): array
361406
}
362407

363408
foreach ($extensionConstants as $constantName => $constantValue) {
409+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
410+
if (
411+
PHP_VERSION_ID >= 80500
412+
&& in_array($constantName, [
413+
'IMAGETYPE_SVG',
414+
'IMAGETYPE_HEIF',
415+
'PHP_BUILD_DATE',
416+
], true)
417+
) {
418+
continue;
419+
}
420+
364421
$provider[] = [$constantName, $constantValue, $extensionName];
365422
}
366423
}

test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Roave\BetterReflectionTest\Fixture\InterfaceForSourceStubber;
3636
use Roave\BetterReflectionTest\Fixture\PHP81ClassForSourceStubber;
3737
use Roave\BetterReflectionTest\Fixture\PHP83ClassForSourceStubber;
38+
use Roave\BetterReflectionTest\Fixture\PHP85ClassForSourceStubber;
3839
use Roave\BetterReflectionTest\Fixture\PHP8ClassForSourceStubber;
3940
use Roave\BetterReflectionTest\Fixture\TraitForSourceStubber;
4041
use stdClass;
@@ -116,6 +117,7 @@ public function testCanStubTraits(): void
116117
self::assertNull($stubData->getExtensionName());
117118
}
118119

120+
#[RequiresPhp('< 8.5')]
119121
public function testClassStub(): void
120122
{
121123
require_once __DIR__ . '/../../Fixture/ClassForSourceStubber.php';
@@ -189,6 +191,17 @@ public function testClassStubWithTypedConstants(): void
189191
self::assertStringEqualsFile(__DIR__ . '/../../Fixture/PHP83ClassForSourceStubberExpected.php', $stubData->getStub());
190192
}
191193

194+
#[RequiresPhp('8.5')]
195+
public function testClassStubWithPHP85Changes(): void
196+
{
197+
require_once __DIR__ . '/../../Fixture/PHP85ClassForSourceStubber.php';
198+
199+
$stubData = $this->stubber->generateClassStub(PHP85ClassForSourceStubber::class);
200+
201+
self::assertNotNull($stubData);
202+
self::assertStringEqualsFile(__DIR__ . '/../../Fixture/PHP85ClassForSourceStubberExpected.php', $stubData->getStub());
203+
}
204+
192205
public function testClassWithoutNamespaceStub(): void
193206
{
194207
require_once __DIR__ . '/../../Fixture/ClassWithoutNamespaceForSourceStubber.php';

0 commit comments

Comments
 (0)