forked from phpspec/prophecy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassMirrorTest.php
700 lines (544 loc) · 22.9 KB
/
ClassMirrorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
<?php
namespace Tests\Prophecy\Doubler\Generator;
use PHPUnit\Framework\TestCase;
use Prophecy\Doubler\Generator\ClassMirror;
use Prophecy\Doubler\Generator\Node\ArgumentTypeNode;
use Prophecy\Doubler\Generator\Node\ReturnTypeNode;
use Prophecy\Exception\Doubler\ClassMirrorException;
use Prophecy\Exception\InvalidArgumentException;
class ClassMirrorTest extends TestCase
{
/**
* @test
*/
public function it_reflects_allowed_magic_methods()
{
$class = new \ReflectionClass('Fixtures\Prophecy\SpecialMethods');
$mirror = new ClassMirror();
$node = $mirror->reflect($class, array());
$this->assertCount(7, $node->getMethods());
}
/**
* @test
*/
public function it_reflects_protected_abstract_methods()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithProtectedAbstractMethod');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertEquals('Fixtures\Prophecy\WithProtectedAbstractMethod', $classNode->getParentClass());
$methodNodes = $classNode->getMethods();
$this->assertCount(1, $methodNodes);
$this->assertEquals('protected', $methodNodes['innerDetail']->getVisibility());
}
/**
* @test
*/
public function it_reflects_public_static_methods()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithStaticMethod');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertEquals('Fixtures\Prophecy\WithStaticMethod', $classNode->getParentClass());
$methodNodes = $classNode->getMethods();
$this->assertCount(1, $methodNodes);
$this->assertTrue($methodNodes['innerDetail']->isStatic());
}
/**
* @test
*/
public function it_marks_required_args_without_types_as_not_optional()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithArguments');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$methodNode = $classNode->getMethod('methodWithoutTypeHints');
$argNodes = $methodNode->getArguments();
$this->assertCount(1, $argNodes);
$this->assertEquals('arg', $argNodes[0]->getName());
$this->assertEquals(new ArgumentTypeNode(), $argNodes[0]->getTypeNode());
$this->assertFalse($argNodes[0]->isOptional());
$this->assertNull($argNodes[0]->getDefault());
$this->assertFalse($argNodes[0]->isPassedByReference());
$this->assertFalse($argNodes[0]->isVariadic());
}
/**
* @test
*/
public function it_properly_reads_methods_arguments_with_types()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithArguments');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$methodNode = $classNode->getMethod('methodWithArgs');
$argNodes = $methodNode->getArguments();
$this->assertCount(3, $argNodes);
$this->assertEquals('arg_1', $argNodes[0]->getName());
$this->assertEquals(new ArgumentTypeNode('ArrayAccess'), $argNodes[0]->getTypeNode());
$this->assertFalse($argNodes[0]->isOptional());
$this->assertEquals('arg_2', $argNodes[1]->getName());
$this->assertEquals(new ArgumentTypeNode('array'), $argNodes[1]->getTypeNode());
$this->assertTrue($argNodes[1]->isOptional());
$this->assertEquals(array(), $argNodes[1]->getDefault());
$this->assertFalse($argNodes[1]->isPassedByReference());
$this->assertFalse($argNodes[1]->isVariadic());
$this->assertEquals('arg_3', $argNodes[2]->getName());
$this->assertEquals(new ArgumentTypeNode('ArrayAccess', 'null'), $argNodes[2]->getTypeNode());
$this->assertTrue($argNodes[2]->isOptional());
$this->assertNull($argNodes[2]->getDefault());
$this->assertFalse($argNodes[2]->isPassedByReference());
$this->assertFalse($argNodes[2]->isVariadic());
}
/**
* @test
*/
public function it_properly_reads_methods_arguments_with_callable_types()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithCallableArgument');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$methodNode = $classNode->getMethod('methodWithArgs');
$argNodes = $methodNode->getArguments();
$this->assertCount(2, $argNodes);
$this->assertEquals('arg_1', $argNodes[0]->getName());
$this->assertEquals(new ArgumentTypeNode('callable'), $argNodes[0]->getTypeNode());
$this->assertFalse($argNodes[0]->isOptional());
$this->assertFalse($argNodes[0]->isPassedByReference());
$this->assertFalse($argNodes[0]->isVariadic());
$this->assertEquals('arg_2', $argNodes[1]->getName());
$this->assertEquals(new ArgumentTypeNode('callable', 'null'), $argNodes[1]->getTypeNode());
$this->assertTrue($argNodes[1]->isOptional());
$this->assertNull($argNodes[1]->getDefault());
$this->assertFalse($argNodes[1]->isPassedByReference());
$this->assertFalse($argNodes[1]->isVariadic());
}
/**
* @test
*/
public function it_properly_reads_methods_variadic_arguments()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithVariadicArgument');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$methodNode = $classNode->getMethod('methodWithArgs');
$argNodes = $methodNode->getArguments();
$this->assertCount(1, $argNodes);
$this->assertEquals('args', $argNodes[0]->getName());
$this->assertEquals(new ArgumentTypeNode(), $argNodes[0]->getTypeNode());
$this->assertFalse($argNodes[0]->isOptional());
$this->assertFalse($argNodes[0]->isPassedByReference());
$this->assertTrue($argNodes[0]->isVariadic());
}
/**
* @test
*/
public function it_properly_reads_methods_typehinted_variadic_arguments()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithTypehintedVariadicArgument');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$methodNode = $classNode->getMethod('methodWithTypeHintedArgs');
$argNodes = $methodNode->getArguments();
$this->assertCount(1, $argNodes);
$this->assertEquals('args', $argNodes[0]->getName());
$this->assertEquals(new ArgumentTypeNode('array'), $argNodes[0]->getTypeNode());
$this->assertFalse($argNodes[0]->isOptional());
$this->assertFalse($argNodes[0]->isPassedByReference());
$this->assertTrue($argNodes[0]->isVariadic());
}
/**
* @test
*/
public function it_marks_passed_by_reference_args_as_passed_by_reference()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithReferences');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertTrue($classNode->hasMethod('methodWithReferenceArgument'));
$argNodes = $classNode->getMethod('methodWithReferenceArgument')->getArguments();
$this->assertCount(2, $argNodes);
$this->assertTrue($argNodes[0]->isPassedByReference());
$this->assertTrue($argNodes[1]->isPassedByReference());
}
/**
* @test
*/
public function it_throws_an_exception_if_class_is_final()
{
$class = new \ReflectionClass('Fixtures\Prophecy\FinalClass');
$mirror = new ClassMirror();
$this->expectException(ClassMirrorException::class);
$mirror->reflect($class, array());
}
/**
* @test
*/
public function it_ignores_final_methods()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithFinalMethod');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertCount(0, $classNode->getMethods());
}
/**
* @test
*/
public function it_marks_final_methods_as_unextendable()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithFinalMethod');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertCount(1, $classNode->getUnextendableMethods());
$this->assertFalse($classNode->isExtendable('finalImplementation'));
}
/**
* @test
*/
public function it_throws_an_exception_if_interface_provided_instead_of_class()
{
$class = new \ReflectionClass('Fixtures\Prophecy\EmptyInterface');
$mirror = new ClassMirror();
$this->expectException(InvalidArgumentException::class);
$mirror->reflect($class, array());
}
/**
* @test
*/
public function it_reflects_all_interfaces_methods()
{
$mirror = new ClassMirror();
$classNode = $mirror->reflect(null, array(
new \ReflectionClass('Fixtures\Prophecy\Named'),
new \ReflectionClass('Fixtures\Prophecy\ModifierInterface'),
));
$this->assertEquals('stdClass', $classNode->getParentClass());
$this->assertEquals(array(
'Prophecy\Doubler\Generator\ReflectionInterface',
'Fixtures\Prophecy\ModifierInterface',
'Fixtures\Prophecy\Named',
), $classNode->getInterfaces());
$this->assertCount(3, $classNode->getMethods());
$this->assertTrue($classNode->hasMethod('getName'));
$this->assertTrue($classNode->hasMethod('isAbstract'));
$this->assertTrue($classNode->hasMethod('getVisibility'));
}
/**
* @test
*/
public function it_ignores_virtually_private_methods()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithVirtuallyPrivateMethod');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertCount(2, $classNode->getMethods());
$this->assertTrue($classNode->hasMethod('isAbstract'));
$this->assertTrue($classNode->hasMethod('__toString'));
$this->assertFalse($classNode->hasMethod('_getName'));
}
/**
* @test
*/
public function it_does_not_throw_exception_for_virtually_private_finals()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithFinalVirtuallyPrivateMethod');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertCount(0, $classNode->getMethods());
}
/**
* @test
*/
public function it_reflects_return_typehints()
{
$class = new \ReflectionClass('Fixtures\Prophecy\WithReturnTypehints');
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class, array());
$this->assertCount(3, $classNode->getMethods());
$this->assertTrue($classNode->hasMethod('getName'));
$this->assertTrue($classNode->hasMethod('getSelf'));
$this->assertTrue($classNode->hasMethod('getParent'));
$this->assertEquals(new ReturnTypeNode('string'), $classNode->getMethod('getName')->getReturnTypeNode());
$this->assertEquals(new ReturnTypeNode('\Fixtures\Prophecy\WithReturnTypehints'), $classNode->getMethod('getSelf')->getReturnTypeNode());
$this->assertEquals(new ReturnTypeNode('\Fixtures\Prophecy\EmptyClass'), $classNode->getMethod('getParent')->getReturnTypeNode());
}
/**
* @test
*/
public function it_throws_an_exception_if_class_provided_in_interfaces_list()
{
$class = new \ReflectionClass('Fixtures\Prophecy\EmptyClass');
$mirror = new ClassMirror();
$this->expectException(\InvalidArgumentException::class);
$mirror->reflect(null, array($class));
}
/**
* @test
*/
public function it_throws_an_exception_if_not_reflection_provided_as_interface()
{
$mirror = new ClassMirror();
$this->expectException(\InvalidArgumentException::class);
$mirror->reflect(null, array(null));
}
/**
* @test
*/
public function it_doesnt_use_scalar_typehints()
{
if (PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('Internal types have scalar hints in PHP 8');
}
$mirror = new ClassMirror();
$classNode = $mirror->reflect(new \ReflectionClass('ReflectionMethod'), array());
$method = $classNode->getMethod('export');
$arguments = $method->getArguments();
$this->assertEquals(new ArgumentTypeNode(), $arguments[0]->getTypeNode());
$this->assertEquals(new ArgumentTypeNode(), $arguments[1]->getTypeNode());
$this->assertEquals(new ArgumentTypeNode(), $arguments[2]->getTypeNode());
}
/**
* @test
*/
public function it_doesnt_fail_to_typehint_nonexistent_FQCN()
{
$mirror = new ClassMirror();
$classNode = $mirror->reflect(new \ReflectionClass('Fixtures\Prophecy\OptionalDepsClass'), array());
$method = $classNode->getMethod('iHaveAStrangeTypeHintedArg');
$arguments = $method->getArguments();
$this->assertEquals(new ArgumentTypeNode('I\Simply\Am\Nonexistent'), $arguments[0]->getTypeNode());
}
/**
* @test
*/
public function it_doesnt_fail_on_array_nullable_parameter_with_not_null_default_value()
{
$mirror = new ClassMirror();
$classNode = $mirror->reflect(new \ReflectionClass('Fixtures\Prophecy\NullableArrayParameter'), array());
$method = $classNode->getMethod('iHaveNullableArrayParameterWithNotNullDefaultValue');
$arguments = $method->getArguments();
$this->assertEquals(new ArgumentTypeNode('array', 'null'), $arguments[0]->getTypeNode());
}
/**
* @test
*/
public function it_doesnt_fail_to_typehint_nonexistent_RQCN()
{
$mirror = new ClassMirror();
$classNode = $mirror->reflect(new \ReflectionClass('Fixtures\Prophecy\OptionalDepsClass'), array());
$method = $classNode->getMethod('iHaveAnEvenStrangerTypeHintedArg');
$arguments = $method->getArguments();
$this->assertEquals(new ArgumentTypeNode('I\Simply\Am\Not'), $arguments[0]->getTypeNode());
}
/**
* @test
*/
function it_doesnt_fail_when_method_is_extended_with_more_params()
{
$mirror = new ClassMirror();
$classNode = $mirror->reflect(
new \ReflectionClass('Fixtures\Prophecy\MethodWithAdditionalParam'),
array(new \ReflectionClass('Fixtures\Prophecy\Named'))
);
$method = $classNode->getMethod('getName');
$this->assertCount(1, $method->getArguments());
$method = $classNode->getMethod('methodWithoutTypeHints');
$this->assertCount(2, $method->getArguments());
}
/**
* @test
* @doesNotPerformAssertions
*/
function it_doesnt_fail_to_mock_self_referencing_interface()
{
$class = $this->prophesize('Fixtures\Prophecy\SelfReferencing');
$class->reveal();
}
/**
* @test
*/
function it_changes_argument_names_if_they_are_varying()
{
// Use test doubles in this test, as arguments named ... in the Reflection API can only happen for internal classes
$class = $this->prophesize('ReflectionClass');
$method = $this->prophesize('ReflectionMethod');
$parameter = $this->prophesize('ReflectionParameter');
if (PHP_VERSION_ID >= 80200) {
$class->isReadOnly()->willReturn(false);
}
$class->getName()->willReturn('Custom\ClassName');
$class->isInterface()->willReturn(false);
$class->isFinal()->willReturn(false);
$class->getMethods(\ReflectionMethod::IS_PUBLIC)->willReturn(array($method));
$class->getMethods(\ReflectionMethod::IS_ABSTRACT)->willReturn(array());
$method->getParameters()->willReturn(array($parameter));
$method->getName()->willReturn('methodName');
$method->isFinal()->willReturn(false);
$method->isProtected()->willReturn(false);
$method->isStatic()->willReturn(false);
$method->returnsReference()->willReturn(false);
$method->hasReturnType()->willReturn(false);
if (\PHP_VERSION_ID >= 80100) {
$method->hasTentativeReturnType()->willReturn(false);
}
$parameter->getName()->willReturn('...');
$parameter->isDefaultValueAvailable()->willReturn(true);
$parameter->getDefaultValue()->willReturn(null);
$parameter->isPassedByReference()->willReturn(false);
$parameter->allowsNull()->willReturn(true);
$parameter->getClass()->willReturn($class);
$parameter->getType()->willReturn(null);
$parameter->hasType()->willReturn(false);
$parameter->isVariadic()->willReturn(false);
$parameter->getDeclaringClass()->willReturn($class);
$mirror = new ClassMirror();
$classNode = $mirror->reflect($class->reveal(), array());
$methodNodes = $classNode->getMethods();
$argumentNodes = $methodNodes['methodName']->getArguments();
$argumentNode = $argumentNodes[0];
$this->assertEquals('__dot_dot_dot__', $argumentNode->getName());
}
/** @test */
public function it_can_double_a_class_with_union_return_types()
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Union types are not supported in this PHP version');
}
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\UnionReturnTypes'), []);
$methodNode = $classNode->getMethods()['doSomething'];
$this->assertSame(['\stdClass', 'bool'], $methodNode->getReturnTypeNode()->getTypes());
}
/** @test */
public function it_can_double_a_class_with_union_argument_types()
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Union types are not supported in this PHP version');
}
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\UnionArgumentTypes'), []);
$methodNode = $classNode->getMethods()['doSomething'];
$this->assertEquals(new ArgumentTypeNode('bool', '\\stdClass'), $methodNode->getArguments()[0]->getTypeNode());
}
/** @test */
public function it_can_double_a_class_with_mixed_types()
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Mixed type is not supported in this PHP version');
}
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\MixedTypes'), []);
$methodNode = $classNode->getMethods()['doSomething'];
$this->assertEquals(new ArgumentTypeNode('mixed'), $methodNode->getArguments()[0]->getTypeNode());
$this->assertEquals(new ReturnTypeNode('mixed'), $methodNode->getReturnTypeNode());
}
/** @test */
public function it_can_double_inherited_self_return_type()
{
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\ClassExtendAbstractWithMethodWithReturnType'), []);
$methodNode = $classNode->getMethods()['returnSelf'];
$this->assertEquals(new ReturnTypeNode('Fixtures\Prophecy\AbstractBaseClassWithMethodWithReturnType'), $methodNode->getReturnTypeNode());
}
/**
* @test
*/
public function case_insensitive_method_names()
{
$prophecy = $this->prophesize('ArrayObject');
$prophecy->offsetGet(1)->willReturn(1)->shouldBeCalledTimes(1);
$prophecy->offsetget(2)->willReturn(2)->shouldBeCalledTimes(1);
$prophecy->OffsetGet(3)->willReturn(3)->shouldBeCalledTimes(1);
$arrayObject = $prophecy->reveal();
self::assertSame(1, $arrayObject->offsetGet(1));
self::assertSame(2, $arrayObject->offsetGet(2));
self::assertSame(3, $arrayObject->offsetGet(3));
}
/**
* @test
*/
public function it_can_double_never_return_type()
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Never type is not supported in this PHP version');
}
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\NeverType'), []);
$methodNode = $classNode->getMethods()['doSomething'];
$this->assertEquals(new ReturnTypeNode('never'), $methodNode->getReturnTypeNode());
}
/**
* @test
*/
public function it_can_not_double_an_enum()
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Enums are not supported in this PHP version');
}
$this->expectException(ClassMirrorException::class);
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\Enum'), []);
}
/**
* @test
*/
public function it_can_not_double_intersection_return_types()
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Intersection types are not supported in this PHP version');
}
$this->expectException(ClassMirrorException::class);
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\IntersectionReturnType'), []);
}
/**
* @test
*/
public function it_can_not_double_intersection_argument_types()
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Intersection types are not supported in this PHP version');
}
$this->expectException(ClassMirrorException::class);
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\IntersectionArgumentType'), []);
}
/**
* @test
*/
public function it_can_not_double_dnf_intersection_argument_types()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('DNF intersection types are not supported in this PHP version');
}
$this->expectException(ClassMirrorException::class);
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\DnfArgumentType'), []);
}
/**
* @test
*/
public function it_can_not_double_dnf_intersection_return_types()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('DNF intersection types are not supported in this PHP version');
}
$this->expectException(ClassMirrorException::class);
$classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\DnfReturnType'), []);
}
/**
* @test
*/
public function it_reflects_non_read_only_class()
{
$classNode = (new ClassMirror())->reflect(
new \ReflectionClass('Fixtures\Prophecy\EmptyClass'),
[]
);
$this->assertFalse($classNode->isReadOnly());
}
/**
* @test
*/
public function it_reflects_read_only_class()
{
if (PHP_VERSION_ID < 80200) {
$this->markTestSkipped('Read only classes are not supported in this PHP version');
}
$classNode = (new ClassMirror())->reflect(
new \ReflectionClass('Fixtures\Prophecy\ReadOnlyClass'),
[]
);
$this->assertTrue($classNode->isReadOnly());
}
}