Skip to content

Commit dccbd10

Browse files
authored
Merge pull request #1546 from kukulich/test
PHPUnit 12.5
2 parents 1a47e5f + 627fd5e commit dccbd10

File tree

54 files changed

+1047
-1164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1047
-1164
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
],
3434
"require-dev": {
3535
"phpbench/phpbench": "^1.4.3",
36-
"phpunit/phpunit": "^11.5.50"
36+
"phpunit/phpunit": "^12.5.8"
3737
},
3838
"autoload": {
3939
"psr-4": {

composer.lock

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

src/SourceLocator/SourceStubber/PhpStormStubs/CachingVisitor.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use function explode;
2121
use function in_array;
2222
use function is_resource;
23+
use function restore_error_handler;
24+
use function set_error_handler;
2325
use function sprintf;
2426
use function strtolower;
2527
use function strtoupper;
@@ -212,9 +214,15 @@ private function updateConstantValue(Node\Expr\FuncCall|Node\Const_ $node, strin
212214
return;
213215
}
214216

215-
// @ because access to deprecated constant throws deprecated warning
216-
/** @var scalar|resource|list<scalar>|null $constantValue */
217-
$constantValue = @constant($constantName);
217+
// Error handler to suppress deprecated constant warnings (e.g., E_STRICT in PHP 8.4+)
218+
set_error_handler(static fn (): bool => true);
219+
try {
220+
/** @var scalar|resource|list<scalar>|null $constantValue */
221+
$constantValue = constant($constantName);
222+
} finally {
223+
restore_error_handler();
224+
}
225+
218226
$normalizedConstantValue = is_resource($constantValue)
219227
? $this->builderFactory->funcCall('constant', [$constantName])
220228
/** @phpstan-ignore argument.type */

test/unit/NodeCompiler/Exception/UnableToCompileNodeTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ public function testBecauseOfNotFoundConstantReference(CompilerContext $context,
8181
#[DataProvider('supportedContextTypes')]
8282
public function testBecauseOfNotFoundClassConstantReference(CompilerContext $context, string $contextName): void
8383
{
84-
$targetClass = $this->createMock(ReflectionClass::class);
84+
$targetClass = self::createStub(ReflectionClass::class);
8585

8686
$targetClass
87-
->expects(self::any())
8887
->method('getName')
8988
->willReturn('An\\Example');
9089

@@ -107,10 +106,9 @@ public function testBecauseOfNotFoundClassConstantReference(CompilerContext $con
107106
#[DataProvider('supportedContextTypes')]
108107
public function testBecauseOfOfInvalidEnumCasePropertyFetch(CompilerContext $context, string $contextName): void
109108
{
110-
$targetClass = $this->createMock(ReflectionClass::class);
109+
$targetClass = self::createStub(ReflectionClass::class);
111110

112111
$targetClass
113-
->expects(self::any())
114112
->method('getName')
115113
->willReturn('An\\Example');
116114

test/unit/Reflection/Adapter/ReflectionAttributeTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testCoreReflectionMethods(string $methodName): void
3939
self::assertSame(ReflectionAttributeAdapter::class, $reflectionTypeAdapterReflection->getMethod($methodName)->getDeclaringClass()->getName());
4040
}
4141

42-
/** @return list<array{0: string, 1: class-string|null, 2: mixed, 3: list<mixed>}> */
42+
/** @return list<array{0: non-empty-string, 1: class-string|null, 2: mixed, 3: list<mixed>}> */
4343
public static function methodExpectationProvider(): array
4444
{
4545
return [
@@ -53,19 +53,21 @@ public static function methodExpectationProvider(): array
5353
}
5454

5555
/**
56+
* @param non-empty-string $methodName
5657
* @param list<mixed> $args
5758
* @param class-string<Throwable>|null $expectedException
5859
*/
5960
#[DataProvider('methodExpectationProvider')]
6061
public function testAdapterMethods(string $methodName, string|null $expectedException, mixed $returnValue, array $args): void
6162
{
62-
$reflectionStub = $this->createMock(BetterReflectionAttribute::class);
63-
6463
if ($expectedException === null) {
64+
$reflectionStub = $this->createMock(BetterReflectionAttribute::class);
6565
$reflectionStub->expects($this->once())
6666
->method($methodName)
6767
->with(...$args)
6868
->willReturn($returnValue);
69+
} else {
70+
$reflectionStub = self::createStub(BetterReflectionAttribute::class);
6971
}
7072

7173
if ($expectedException !== null) {
@@ -78,7 +80,7 @@ public function testAdapterMethods(string $methodName, string|null $expectedExce
7880

7981
public function testPropertyName(): void
8082
{
81-
$betterReflectionAttribute = $this->createMock(BetterReflectionAttribute::class);
83+
$betterReflectionAttribute = self::createStub(BetterReflectionAttribute::class);
8284
$betterReflectionAttribute
8385
->method('getName')
8486
->willReturn('Foo');
@@ -92,7 +94,7 @@ public function testUnknownProperty(): void
9294
$this->expectException(OutOfBoundsException::class);
9395
$this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionAttribute::$foo does not exist.');
9496

95-
$betterReflectionAttribute = $this->createMock(BetterReflectionAttribute::class);
97+
$betterReflectionAttribute = self::createStub(BetterReflectionAttribute::class);
9698
$reflectionAttributeAdapter = new ReflectionAttributeAdapter($betterReflectionAttribute);
9799
/** @phpstan-ignore property.notFound, expr.resultUnused */
98100
$reflectionAttributeAdapter->foo;

test/unit/Reflection/Adapter/ReflectionClassConstantTest.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testCoreReflectionMethods(string $methodName): void
4646
self::assertSame(ReflectionClassConstantAdapter::class, $reflectionClassConstantAdapterReflection->getMethod($methodName)->getDeclaringClass()->getName());
4747
}
4848

49-
/** @return list<array{0: string, 1: class-string|null, 2: mixed, 3: list<mixed>}> */
49+
/** @return list<array{0: non-empty-string, 1: class-string|null, 2: mixed, 3: list<mixed>}> */
5050
public static function methodExpectationProvider(): array
5151
{
5252
return [
@@ -67,6 +67,7 @@ public static function methodExpectationProvider(): array
6767
}
6868

6969
/**
70+
* @param non-empty-string $methodName
7071
* @param list<mixed> $args
7172
* @param class-string<Throwable>|null $expectedException
7273
*/
@@ -105,21 +106,21 @@ public static function dataAdapterMethodsForEnumCase(): array
105106
#[DataProvider('dataAdapterMethodsForEnumCase')]
106107
public function testAdapterMethodsForEnumCase(string $methodName, mixed $expectedValue): void
107108
{
108-
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($this->createMock(BetterReflectionEnumCase::class));
109+
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter(self::createStub(BetterReflectionEnumCase::class));
109110

110111
self::assertSame($expectedValue, $reflectionClassConstantAdapter->{$methodName}());
111112
}
112113

113114
public function testHasTypeForEnumCase(): void
114115
{
115-
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($this->createMock(BetterReflectionEnumCase::class));
116+
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter(self::createStub(BetterReflectionEnumCase::class));
116117

117118
self::assertFalse($reflectionClassConstantAdapter->hasType());
118119
}
119120

120121
public function testGetTypeForEnumCase(): void
121122
{
122-
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($this->createMock(BetterReflectionEnumCase::class));
123+
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter(self::createStub(BetterReflectionEnumCase::class));
123124

124125
self::assertNull($reflectionClassConstantAdapter->getType());
125126
}
@@ -128,12 +129,12 @@ public function testGetValueForEnumCase(): void
128129
{
129130
require_once __DIR__ . '/../../Fixture/Enums.php';
130131

131-
$reflectionClassAdapter = $this->createMock(BetterReflectionClass::class);
132+
$reflectionClassAdapter = self::createStub(BetterReflectionClass::class);
132133
$reflectionClassAdapter
133134
->method('getName')
134135
->willReturn(PureEnum::class);
135136

136-
$reflectionEnumCaseAdapter = $this->createMock(BetterReflectionEnumCase::class);
137+
$reflectionEnumCaseAdapter = self::createStub(BetterReflectionEnumCase::class);
137138
$reflectionEnumCaseAdapter
138139
->method('getDeclaringClass')
139140
->willReturn($reflectionClassAdapter);
@@ -148,7 +149,7 @@ public function testGetValueForEnumCase(): void
148149

149150
public function testGetDocCommentReturnsFalseWhenNoDocComment(): void
150151
{
151-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
152+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
152153
$betterReflectionClassConstant
153154
->method('getDocComment')
154155
->willReturn(null);
@@ -160,18 +161,18 @@ public function testGetDocCommentReturnsFalseWhenNoDocComment(): void
160161

161162
public function testGetAttributes(): void
162163
{
163-
$betterReflectionAttribute1 = $this->createMock(BetterReflectionAttribute::class);
164+
$betterReflectionAttribute1 = self::createStub(BetterReflectionAttribute::class);
164165
$betterReflectionAttribute1
165166
->method('getName')
166167
->willReturn('SomeAttribute');
167-
$betterReflectionAttribute2 = $this->createMock(BetterReflectionAttribute::class);
168+
$betterReflectionAttribute2 = self::createStub(BetterReflectionAttribute::class);
168169
$betterReflectionAttribute2
169170
->method('getName')
170171
->willReturn('AnotherAttribute');
171172

172173
$betterReflectionAttributes = [$betterReflectionAttribute1, $betterReflectionAttribute2];
173174

174-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
175+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
175176
$betterReflectionClassConstant
176177
->method('getAttributes')
177178
->willReturn($betterReflectionAttributes);
@@ -191,21 +192,21 @@ public function testGetAttributesWithName(): void
191192
/** @phpstan-var class-string $anotherAttributeClassName */
192193
$anotherAttributeClassName = 'AnotherAttribute';
193194

194-
$betterReflectionAttribute1 = $this->createMock(BetterReflectionAttribute::class);
195+
$betterReflectionAttribute1 = self::createStub(BetterReflectionAttribute::class);
195196
$betterReflectionAttribute1
196197
->method('getName')
197198
->willReturn($someAttributeClassName);
198-
$betterReflectionAttribute2 = $this->createMock(BetterReflectionAttribute::class);
199+
$betterReflectionAttribute2 = self::createStub(BetterReflectionAttribute::class);
199200
$betterReflectionAttribute2
200201
->method('getName')
201202
->willReturn($anotherAttributeClassName);
202203

203204
$betterReflectionAttributes = [$betterReflectionAttribute1, $betterReflectionAttribute2];
204205

205-
$betterReflectionClassConstant = $this->getMockBuilder(BetterReflectionClassConstant::class)
206+
$betterReflectionClassConstant = self::getStubBuilder(BetterReflectionClassConstant::class)
206207
->disableOriginalConstructor()
207208
->onlyMethods(['getAttributes'])
208-
->getMock();
209+
->getStub();
209210

210211
$betterReflectionClassConstant
211212
->method('getAttributes')
@@ -227,7 +228,7 @@ public function testGetAttributesWithInstance(): void
227228
/** @phpstan-var class-string $interfaceName */
228229
$interfaceName = 'InterfaceName';
229230

230-
$betterReflectionAttributeClass1 = $this->createMock(BetterReflectionClass::class);
231+
$betterReflectionAttributeClass1 = self::createStub(BetterReflectionClass::class);
231232
$betterReflectionAttributeClass1
232233
->method('getName')
233234
->willReturn($className);
@@ -244,12 +245,12 @@ public function testGetAttributesWithInstance(): void
244245
[$interfaceName, false],
245246
]);
246247

247-
$betterReflectionAttribute1 = $this->createMock(BetterReflectionAttribute::class);
248+
$betterReflectionAttribute1 = self::createStub(BetterReflectionAttribute::class);
248249
$betterReflectionAttribute1
249250
->method('getClass')
250251
->willReturn($betterReflectionAttributeClass1);
251252

252-
$betterReflectionAttributeClass2 = $this->createMock(BetterReflectionClass::class);
253+
$betterReflectionAttributeClass2 = self::createStub(BetterReflectionClass::class);
253254
$betterReflectionAttributeClass2
254255
->method('getName')
255256
->willReturn('Whatever');
@@ -268,12 +269,12 @@ public function testGetAttributesWithInstance(): void
268269
[$interfaceName, true],
269270
]);
270271

271-
$betterReflectionAttribute2 = $this->createMock(BetterReflectionAttribute::class);
272+
$betterReflectionAttribute2 = self::createStub(BetterReflectionAttribute::class);
272273
$betterReflectionAttribute2
273274
->method('getClass')
274275
->willReturn($betterReflectionAttributeClass2);
275276

276-
$betterReflectionAttributeClass3 = $this->createMock(BetterReflectionClass::class);
277+
$betterReflectionAttributeClass3 = self::createStub(BetterReflectionClass::class);
277278
$betterReflectionAttributeClass3
278279
->method('getName')
279280
->willReturn('Whatever');
@@ -292,7 +293,7 @@ public function testGetAttributesWithInstance(): void
292293
[$interfaceName, true],
293294
]);
294295

295-
$betterReflectionAttribute3 = $this->createMock(BetterReflectionAttribute::class);
296+
$betterReflectionAttribute3 = self::createStub(BetterReflectionAttribute::class);
296297
$betterReflectionAttribute3
297298
->method('getClass')
298299
->willReturn($betterReflectionAttributeClass3);
@@ -303,10 +304,10 @@ public function testGetAttributesWithInstance(): void
303304
$betterReflectionAttribute3,
304305
];
305306

306-
$betterReflectionClassConstant = $this->getMockBuilder(BetterReflectionClassConstant::class)
307+
$betterReflectionClassConstant = self::getStubBuilder(BetterReflectionClassConstant::class)
307308
->disableOriginalConstructor()
308309
->onlyMethods(['getAttributes'])
309-
->getMock();
310+
->getStub();
310311

311312
$betterReflectionClassConstant
312313
->method('getAttributes')
@@ -321,7 +322,7 @@ public function testGetAttributesWithInstance(): void
321322

322323
public function testGetAttributesThrowsExceptionForInvalidFlags(): void
323324
{
324-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
325+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
325326
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($betterReflectionClassConstant);
326327

327328
$this->expectException(ValueError::class);
@@ -330,21 +331,21 @@ public function testGetAttributesThrowsExceptionForInvalidFlags(): void
330331

331332
public function testIsEnumCaseWithClassConstant(): void
332333
{
333-
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($this->createMock(BetterReflectionClassConstant::class));
334+
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter(self::createStub(BetterReflectionClassConstant::class));
334335

335336
self::assertFalse($reflectionClassConstantAdapter->isEnumCase());
336337
}
337338

338339
public function testIsEnumCaseWithEnumCase(): void
339340
{
340-
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($this->createMock(BetterReflectionEnumCase::class));
341+
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter(self::createStub(BetterReflectionEnumCase::class));
341342

342343
self::assertTrue($reflectionClassConstantAdapter->isEnumCase());
343344
}
344345

345346
public function testPropertyName(): void
346347
{
347-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
348+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
348349
$betterReflectionClassConstant
349350
->method('getName')
350351
->willReturn('FOO');
@@ -355,12 +356,12 @@ public function testPropertyName(): void
355356

356357
public function testPropertyClass(): void
357358
{
358-
$betterReflectionClass = $this->createMock(BetterReflectionClass::class);
359+
$betterReflectionClass = self::createStub(BetterReflectionClass::class);
359360
$betterReflectionClass
360361
->method('getName')
361362
->willReturn('Foo');
362363

363-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
364+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
364365
$betterReflectionClassConstant
365366
->method('getImplementingClass')
366367
->willReturn($betterReflectionClass);
@@ -371,7 +372,7 @@ public function testPropertyClass(): void
371372

372373
public function testUnknownProperty(): void
373374
{
374-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
375+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
375376
$reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($betterReflectionClassConstant);
376377
$this->expectException(OutOfBoundsException::class);
377378
$this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionClassConstant::$foo does not exist.');
@@ -381,12 +382,12 @@ public function testUnknownProperty(): void
381382

382383
public function testGetDeclaringClassForClass(): void
383384
{
384-
$betterReflectionClass = $this->createMock(BetterReflectionClass::class);
385+
$betterReflectionClass = self::createStub(BetterReflectionClass::class);
385386
$betterReflectionClass
386387
->method('getName')
387388
->willReturn('DeclaringClass');
388389

389-
$betterReflectionClassConstant = $this->createMock(BetterReflectionClassConstant::class);
390+
$betterReflectionClassConstant = self::createStub(BetterReflectionClassConstant::class);
390391
$betterReflectionClassConstant
391392
->method('getImplementingClass')
392393
->willReturn($betterReflectionClass);
@@ -399,12 +400,12 @@ public function testGetDeclaringClassForClass(): void
399400

400401
public function testGetDeclaringClassForEnum(): void
401402
{
402-
$betterReflectionEnum = $this->createMock(BetterReflectionEnum::class);
403+
$betterReflectionEnum = self::createStub(BetterReflectionEnum::class);
403404
$betterReflectionEnum
404405
->method('getName')
405406
->willReturn('DeclaringEnum');
406407

407-
$betterReflectionEnumCase = $this->createMock(BetterReflectionEnumCase::class);
408+
$betterReflectionEnumCase = self::createStub(BetterReflectionEnumCase::class);
408409
$betterReflectionEnumCase
409410
->method('getDeclaringClass')
410411
->willReturn($betterReflectionEnum);

0 commit comments

Comments
 (0)