Skip to content

Commit fd58278

Browse files
SanderMullerclaude
authored andcommitted
Cover the facade-alias shape with an e2e project
An autoloader that resolves a short alias whose name is also a global function - Laravel's Cache, File, Str and Hash all are - is declined by the locator without the fix, so `use File;` reports class.notFound. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7fde888 commit fd58278

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎.github/workflows/e2e-tests.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ jobs:
140140
cd e2e/bug-12972c
141141
composer install
142142
../../bin/phpstan analyze
143+
- script: |
144+
cd e2e/bug-15102b
145+
../../bin/phpstan analyze
143146
- script: |
144147
cd e2e/bug-14724
145148
composer install

‎e2e/bug-15102b/bootstrap.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
// The shape Illuminate\Foundation\AliasLoader creates: a prepended autoloader that
4+
// resolves a short alias to a real class with class_alias(), reading no file. The alias
5+
// names collide with global functions - Laravel's Cache, File, Str, Hash all do.
6+
require_once __DIR__ . '/src/Real.php';
7+
8+
spl_autoload_register(static function (string $class): void {
9+
if ($class !== 'File') {
10+
return;
11+
}
12+
13+
class_alias(E2eFacadeAlias\Real::class, 'File');
14+
}, true, true);

‎e2e/bug-15102b/phpstan.dist.neon‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 8
3+
bootstrapFiles:
4+
- bootstrap.php
5+
paths:
6+
- test.php

‎e2e/bug-15102b/src/Real.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace E2eFacadeAlias;
4+
5+
class Real
6+
{
7+
8+
public function doFoo(): void
9+
{
10+
}
11+
12+
}

‎e2e/bug-15102b/test.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php declare(strict_types = 1);
2+
3+
function (File $file): void {
4+
$file->doFoo();
5+
};

0 commit comments

Comments
 (0)