forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalyserIntegrationTest.php
672 lines (573 loc) · 21.6 KB
/
AnalyserIntegrationTest.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
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use Bug4288\MyClass;
use Bug4713\Service;
use ExtendingKnownClassWithCheck\Foo;
use PHPStan\File\FileHelper;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use function array_reverse;
use function extension_loaded;
use function method_exists;
use function restore_error_handler;
use const PHP_VERSION_ID;
class AnalyserIntegrationTest extends PHPStanTestCase
{
public function testUndefinedVariableFromAssignErrorHasLine(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/undefined-variable-assign.php');
$this->assertCount(2, $errors);
$error = $errors[0];
$this->assertSame('Undefined variable: $bar', $error->getMessage());
$this->assertSame(3, $error->getLine());
$error = $errors[1];
$this->assertSame('Variable $foo might not be defined.', $error->getMessage());
$this->assertSame(6, $error->getLine());
}
public function testMissingPropertyAndMethod(): void
{
$errors = $this->runAnalyse(__DIR__ . '/../../notAutoloaded/Foo.php');
$this->assertNoErrors($errors);
}
public function testMissingClassErrorAboutMisconfiguredAutoloader(): void
{
$errors = $this->runAnalyse(__DIR__ . '/../../notAutoloaded/Bar.php');
$this->assertNoErrors($errors);
}
public function testMissingFunctionErrorAboutMisconfiguredAutoloader(): void
{
$errors = $this->runAnalyse(__DIR__ . '/../../notAutoloaded/functionFoo.php');
$this->assertCount(1, $errors);
$this->assertSame('Function doSomething not found.', $errors[0]->getMessage());
$this->assertSame(7, $errors[0]->getLine());
}
public function testAnonymousClassWithInheritedConstructor(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/anonymous-class-with-inherited-constructor.php');
$this->assertNoErrors($errors);
}
public function testNestedFunctionCallsDoNotCauseExcessiveFunctionNesting(): void
{
if (extension_loaded('xdebug')) {
$this->markTestSkipped('This test takes too long with XDebug enabled.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/nested-functions.php');
$this->assertNoErrors($errors);
}
public function testExtendingUnknownClass(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/extending-unknown-class.php');
$this->assertCount(1, $errors);
if (self::$useStaticReflectionProvider) {
$this->assertSame(5, $errors[0]->getLine());
$this->assertSame('Class ExtendingUnknownClass\Foo extends unknown class ExtendingUnknownClass\Bar.', $errors[0]->getMessage());
} else {
$this->assertNull($errors[0]->getLine());
$this->assertSame('Class ExtendingUnknownClass\Bar not found.', $errors[0]->getMessage());
}
}
public function testExtendingKnownClassWithCheck(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/extending-known-class-with-check.php');
$this->assertNoErrors($errors);
$reflectionProvider = $this->createReflectionProvider();
$this->assertTrue($reflectionProvider->hasClass(Foo::class));
}
public function testInfiniteRecursionWithCallable(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/Foo-callable.php');
$this->assertNoErrors($errors);
}
public function testClassThatExtendsUnknownClassIn3rdPartyPropertyTypeShouldNotCauseAutoloading(): void
{
// no error about PHPStan\Tests\Baz not being able to be autoloaded
$errors = $this->runAnalyse(__DIR__ . '/data/ExtendsClassWithUnknownPropertyType.php');
$this->assertCount(1, $errors);
//$this->assertSame(11, $errors[0]->getLine());
$this->assertSame('Call to an undefined method ExtendsClassWithUnknownPropertyType::foo().', $errors[0]->getMessage());
}
public function testAnonymousClassesWithComments(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/AnonymousClassesWithComments.php');
$this->assertCount(3, $errors);
foreach ($errors as $error) {
$this->assertStringContainsString('Call to an undefined method', $error->getMessage());
}
}
public function testUniversalObjectCrateIssue(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/universal-object-crate.php');
$this->assertCount(1, $errors);
$this->assertSame('Parameter #1 $i of method UniversalObjectCrate\Foo::doBaz() expects int, string given.', $errors[0]->getMessage());
$this->assertSame(19, $errors[0]->getLine());
}
public function testCustomFunctionWithNameEquivalentInSignatureMap(): void
{
$signatureMapProvider = self::getContainer()->getByType(SignatureMapProvider::class);
if (!$signatureMapProvider->hasFunctionSignature('bcompiler_write_file')) {
$this->fail();
}
require_once __DIR__ . '/data/custom-function-in-signature-map.php';
$errors = $this->runAnalyse(__DIR__ . '/data/custom-function-in-signature-map.php');
$this->assertNoErrors($errors);
}
public function testAnonymousClassWithWrongFilename(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/anonymous-class-wrong-filename-regression.php');
$this->assertCount(5, $errors);
$this->assertStringContainsString('Method', $errors[0]->getMessage());
$this->assertStringContainsString('has invalid return type', $errors[0]->getMessage());
$this->assertSame(16, $errors[0]->getLine());
$this->assertStringContainsString('Method', $errors[1]->getMessage());
$this->assertStringContainsString('has invalid return type', $errors[1]->getMessage());
$this->assertSame(16, $errors[1]->getLine());
$this->assertSame('Instantiated class AnonymousClassWrongFilename\Bar not found.', $errors[2]->getMessage());
$this->assertSame(18, $errors[2]->getLine());
$this->assertStringContainsString('Parameter #1 $test of method', $errors[3]->getMessage());
$this->assertStringContainsString('$this(AnonymousClassWrongFilename\Foo) given', $errors[3]->getMessage());
$this->assertSame(23, $errors[3]->getLine());
$this->assertSame('Call to method test() on an unknown class AnonymousClassWrongFilename\Bar.', $errors[4]->getMessage());
$this->assertSame(24, $errors[4]->getLine());
}
public function testExtendsPdoStatementCrash(): void
{
if (PHP_VERSION_ID >= 80000 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped();
}
$errors = $this->runAnalyse(__DIR__ . '/data/extends-pdo-statement.php');
$this->assertNoErrors($errors);
}
public function testArrayDestructuringArrayDimFetch(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/array-destructuring-array-dim-fetch.php');
$this->assertNoErrors($errors);
}
public function testNestedNamespaces(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/nested-namespaces.php');
$this->assertCount(2, $errors);
$this->assertSame('Property y\x::$baz has unknown class x\baz as its type.', $errors[0]->getMessage());
$this->assertSame(15, $errors[0]->getLine());
$this->assertSame('Parameter $baz of method y\x::__construct() has invalid type x\baz.', $errors[1]->getMessage());
$this->assertSame(16, $errors[1]->getLine());
}
public function testClassExistsAutoloadingError(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/class-exists.php');
$this->assertNoErrors($errors);
}
public function testCollectWarnings(): void
{
if (PHP_VERSION_ID >= 80000 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Fatal error in PHP 8.0');
}
restore_error_handler();
$errors = $this->runAnalyse(__DIR__ . '/data/declaration-warning.php');
if (self::$useStaticReflectionProvider) {
$this->assertCount(1, $errors);
$this->assertSame('Parameter #1 $i of method DeclarationWarning\Bar::doFoo() is not optional.', $errors[0]->getMessage());
$this->assertSame(22, $errors[0]->getLine());
return;
}
$this->assertCount(2, $errors);
$messages = [
'Declaration of DeclarationWarning\Bar::doFoo(int $i): void should be compatible with DeclarationWarning\Foo::doFoo(): void',
'Parameter #1 $i of method DeclarationWarning\Bar::doFoo() is not optional.',
];
if (PHP_VERSION_ID < 70400) {
$messages = array_reverse($messages);
}
foreach ($messages as $i => $message) {
$this->assertSame($message, $errors[$i]->getMessage());
}
}
public function testPropertyAssignIntersectionStaticTypeBug(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/property-assign-intersection-static-type-bug.php');
$this->assertNoErrors($errors);
}
public function testBug2823(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-2823.php');
$this->assertNoErrors($errors);
}
public function testTwoSameClassesInSingleFile(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/two-same-classes.php');
$this->assertCount(5, $errors);
$error = $errors[0];
$this->assertSame('Property TwoSame\Foo::$prop (string) does not accept default value of type int.', $error->getMessage());
$this->assertSame(9, $error->getLine());
$error = $errors[1];
$this->assertSame('Access to undefined constant TwoSame\Foo::FOO_CONST.', $error->getMessage());
$this->assertSame(13, $error->getLine());
$error = $errors[2];
$this->assertSame('If condition is always false.', $error->getMessage());
$this->assertSame(26, $error->getLine());
$error = $errors[3];
$this->assertSame('Property TwoSame\Foo::$prop (int) does not accept default value of type string.', $error->getMessage());
$this->assertSame(33, $error->getLine());
$error = $errors[4];
$this->assertSame('Property TwoSame\Foo::$prop2 (int) does not accept default value of type string.', $error->getMessage());
$this->assertSame(36, $error->getLine());
}
public function testBug6936(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6936.php');
$this->assertNoErrors($errors);
}
public function testBug3405(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3405.php');
$this->assertNoErrors($errors);
}
public function testBug3415(): void
{
$errors = $this->runAnalyse(__DIR__ . '/../Rules/Methods/data/bug-3415.php');
$this->assertNoErrors($errors);
}
public function testBug3415Two(): void
{
$errors = $this->runAnalyse(__DIR__ . '/../Rules/Methods/data/bug-3415-2.php');
$this->assertNoErrors($errors);
}
public function testBug3468(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3468.php');
$this->assertNoErrors($errors);
}
public function testBug3686(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3686.php');
$this->assertNoErrors($errors);
}
public function testBug3379(): void
{
if (!self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires static reflection');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3379.php');
$this->assertCount(1, $errors);
$this->assertSame('Constant SOME_UNKNOWN_CONST not found.', $errors[0]->getMessage());
}
public function testBug3798(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3798.php');
$this->assertNoErrors($errors);
}
public function testBug3909(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3909.php');
$this->assertNoErrors($errors);
}
public function testBug4097(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4097.php');
$this->assertNoErrors($errors);
}
public function testBug4300(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4300.php');
$this->assertCount(1, $errors);
$this->assertSame('Comparison operation ">" between 0 and 0 is always false.', $errors[0]->getMessage());
$this->assertSame(13, $errors[0]->getLine());
}
public function testBug4513(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4513.php');
$this->assertNoErrors($errors);
}
public function testBug1871(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-1871.php');
$this->assertNoErrors($errors);
}
public function testBug3309(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3309.php');
$this->assertNoErrors($errors);
}
public function testBug6872(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6872.php');
$this->assertNoErrors($errors);
}
public function testBug3769(): void
{
require_once __DIR__ . '/../Rules/Generics/data/bug-3769.php';
$errors = $this->runAnalyse(__DIR__ . '/../Rules/Generics/data/bug-3769.php');
$this->assertNoErrors($errors);
}
public function testBug6301(): void
{
require_once __DIR__ . '/../Rules/Generics/data/bug-6301.php';
$errors = $this->runAnalyse(__DIR__ . '/../Rules/Generics/data/bug-6301.php');
$this->assertNoErrors($errors);
}
public function testBug3922(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3922-integration.php');
$this->assertNoErrors($errors);
}
public function testBug1843(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-1843.php');
$this->assertNoErrors($errors);
}
public function testBug4713(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4713.php');
$this->assertCount(1, $errors);
$this->assertSame('Method Bug4713\Service::createInstance() should return Bug4713\Service but returns object.', $errors[0]->getMessage());
$reflectionProvider = $this->createReflectionProvider();
$class = $reflectionProvider->getClass(Service::class);
$parameter = ParametersAcceptorSelector::selectSingle($class->getNativeMethod('createInstance')->getVariants())->getParameters()[0];
$defaultValue = $parameter->getDefaultValue();
$this->assertInstanceOf(ConstantStringType::class, $defaultValue);
$this->assertSame(Service::class, $defaultValue->getValue());
}
public function testBug4288(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4288.php');
$this->assertNoErrors($errors);
$reflectionProvider = $this->createReflectionProvider();
$class = $reflectionProvider->getClass(MyClass::class);
$parameter = ParametersAcceptorSelector::selectSingle($class->getNativeMethod('paginate')->getVariants())->getParameters()[0];
$defaultValue = $parameter->getDefaultValue();
$this->assertInstanceOf(ConstantIntegerType::class, $defaultValue);
$this->assertSame(10, $defaultValue->getValue());
$nativeProperty = $class->getNativeReflection()->getProperty('test');
if (!method_exists($nativeProperty, 'getDefaultValue')) {
return;
}
$this->assertSame(10, $nativeProperty->getDefaultValue());
}
public function testBug4702(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4702.php');
$this->assertNoErrors($errors);
}
public function testFunctionThatExistsOn72AndLater(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/ldap-exop-passwd.php');
$this->assertNoErrors($errors);
}
public function testBug4715(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4715.php');
$this->assertNoErrors($errors);
}
public function testBug4734(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4734.php');
$this->assertCount(3, $errors);
$this->assertSame('Unsafe access to private property Bug4734\Foo::$httpMethodParameterOverride through static::.', $errors[0]->getMessage());
$this->assertSame('Access to an undefined static property static(Bug4734\Foo)::$httpMethodParameterOverride3.', $errors[1]->getMessage());
$this->assertSame('Access to an undefined property Bug4734\Foo::$httpMethodParameterOverride4.', $errors[2]->getMessage());
}
public function testBug5231(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5231.php');
$this->assertNotEmpty($errors);
}
public function testBug5231Two(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5231_2.php');
$this->assertNotEmpty($errors);
}
public function testBug5529(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5529.php');
$this->assertNoErrors($errors);
}
public function testBug5527(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5527.php');
$this->assertNoErrors($errors);
}
public function testBug5639(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5639.php');
$this->assertNoErrors($errors);
}
public function testBug5657(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5657.php');
$this->assertNoErrors($errors);
}
public function testBug5951(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5951.php');
$this->assertNoErrors($errors);
}
public function testEnums(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/enums-integration.php');
$this->assertCount(3, $errors);
$this->assertSame('Access to an undefined property EnumIntegrationTest\Foo::TWO::$value.', $errors[0]->getMessage());
$this->assertSame(22, $errors[0]->getLine());
$this->assertSame('Access to undefined constant EnumIntegrationTest\Bar::NONEXISTENT.', $errors[1]->getMessage());
$this->assertSame(49, $errors[1]->getLine());
$this->assertSame('Strict comparison using === between EnumIntegrationTest\Foo::ONE and EnumIntegrationTest\Foo::TWO will always evaluate to false.', $errors[2]->getMessage());
$this->assertSame(79, $errors[2]->getLine());
}
public function testBug6255(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6255.php');
$this->assertNoErrors($errors);
}
public function testBug6300(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6300.php');
$this->assertCount(2, $errors);
$this->assertSame('Call to an undefined method Bug6300\Bar::get().', $errors[0]->getMessage());
$this->assertSame(23, $errors[0]->getLine());
$this->assertSame('Access to an undefined property Bug6300\Bar::$fooProp.', $errors[1]->getMessage());
$this->assertSame(24, $errors[1]->getLine());
}
public function testBug6466(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6466.php');
$this->assertNoErrors($errors);
}
public function testBug6494(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6494.php');
$this->assertNoErrors($errors);
}
public function testBug6253(): void
{
$errors = $this->runAnalyse(
__DIR__ . '/data/bug-6253.php',
[
__DIR__ . '/data/bug-6253.php',
__DIR__ . '/data/bug-6253-app-scope-trait.php',
__DIR__ . '/data/bug-6253-collection-trait.php',
],
);
$this->assertNoErrors($errors);
}
public function testBug6442(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6442.php');
$this->assertCount(2, $errors);
$this->assertSame('Dumped type: \'Bug6442\\\A\'', $errors[0]->getMessage());
$this->assertSame(9, $errors[0]->getLine());
$this->assertSame('Dumped type: \'Bug6442\\\B\'', $errors[1]->getMessage());
$this->assertSame(9, $errors[1]->getLine());
}
public function testBug6375(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6375.php');
$this->assertNoErrors($errors);
}
public function testBug6501(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6501.php');
$this->assertNoErrors($errors);
}
public function testBug6114(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6114.php');
$this->assertNoErrors($errors);
}
public function testBug6681(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6681.php');
$this->assertNoErrors($errors);
}
public function testBug6212(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6212.php');
$this->assertNoErrors($errors);
}
public function testBug6740(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6740-b.php');
$this->assertNoErrors($errors);
}
public function testBug6866(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6866.php');
$this->assertNoErrors($errors);
}
public function testBug6649(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6649.php');
$this->assertNoErrors($errors);
}
public function testBug6842(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6842.php');
$this->assertCount(1, $errors);
$this->assertSame('Generator expects value type T of DateTimeInterface, DateTime|DateTimeImmutable|T of DateTimeInterface given.', $errors[0]->getMessage());
$this->assertSame(28, $errors[0]->getLine());
}
public function testBug6896(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6896.php');
$this->assertCount(2, $errors);
}
public function testBug6940(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6940.php');
$this->assertNoErrors($errors);
}
public function testBug1447(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-1447.php');
$this->assertNoErrors($errors);
}
public function testBug5081(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5081.php');
$this->assertNoErrors($errors);
}
public function testBug1388(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-1388.php');
$this->assertNoErrors($errors);
}
/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
*/
private function runAnalyse(string $file, ?array $allAnalysedFiles = null): array
{
$file = $this->getFileHelper()->normalizePath($file);
/** @var Analyser $analyser */
$analyser = self::getContainer()->getByType(Analyser::class);
/** @var FileHelper $fileHelper */
$fileHelper = self::getContainer()->getByType(FileHelper::class);
/** @var Error[] $errors */
$errors = $analyser->analyse([$file], null, null, true, $allAnalysedFiles)->getErrors();
foreach ($errors as $error) {
$this->assertSame($fileHelper->normalizePath($file), $error->getFilePath());
}
return $errors;
}
}