Skip to content

Commit

Permalink
add failing test reproducing larastan#1883
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkawata committed May 15, 2024
1 parent 555119c commit ee6491e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\File\FileHelper;
use PHPStan\Testing\PHPStanTestCase;

use function count;
use function version_compare;

class IntegrationTest extends PHPStanTestCase
Expand All @@ -22,6 +23,7 @@ public static function dataIntegrationTests(): iterable
yield [__DIR__ . '/data/model-properties.php'];
yield [__DIR__ . '/data/blade-view.php'];
yield [__DIR__ . '/data/helpers.php'];
yield [__DIR__ . '/data/bug-1883.php', ['Call to an undefined static method RedisFacade::noSuchMethod().']];

if (! version_compare(LARAVEL_VERSION, '10.0.0', '>=')) {
return;
Expand All @@ -37,8 +39,20 @@ public function testIntegration(string $file, array|null $expectedErrors = null)

if ($expectedErrors === null) {
$this->assertNoErrors($errors);
} else { // @phpcs:ignore
// TODO: compare errors
} else {
$this->assertSameErrorMessages($expectedErrors, $errors);
}
}

/**
* @param string[] $expectedErrors
* @param Error[] $errors
*/
private function assertSameErrorMessages(array $expectedErrors, array $errors): void
{
$this->assertCount(count($expectedErrors), $errors);
foreach ($errors as $index => $error) {
$this->assertSame($expectedErrors[$index], $error->getMessage());
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Integration/data/bug-1883.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Illuminate\Support\Facades\Facade;

/**
* @mixin RedisAlias
*/
class RedisFacade extends Facade
{
}


function test(): void
{
RedisFacade::noSuchMethod();
}
6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ public function customMacroString(): string
if (version_compare(PHP_VERSION, '8.1.0', '>=') && version_compare(PHP_VERSION, '8.2.0', '<')) {
include_once 'enum-definition.php';
}

class RedisFacade
{
}

class_alias(RedisFacade::class, RedisAlias::class);

0 comments on commit ee6491e

Please sign in to comment.