Skip to content

Commit 6f59325

Browse files
committed
Run tests and PHPStan on PHP 8.5
1 parent 0f0ba0a commit 6f59325

File tree

8 files changed

+107
-6
lines changed

8 files changed

+107
-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: 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+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
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+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
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+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
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+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
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+
// https://github.com/JetBrains/phpstorm-stubs/pull/1781
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
}

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)