From 3b9211f7aced5d51f46ed234ff90fc67f180a892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 14 Oct 2023 15:27:31 +0200 Subject: [PATCH] test: Refactor the e2e_035 test to clarify the desired behaviour --- fixtures/set035-composer-files-autoload/index.php | 14 +++++++------- fixtures/set035-composer-files-autoload/test.php | 8 +++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fixtures/set035-composer-files-autoload/index.php b/fixtures/set035-composer-files-autoload/index.php index 30c27de5..560c2a86 100644 --- a/fixtures/set035-composer-files-autoload/index.php +++ b/fixtures/set035-composer-files-autoload/index.php @@ -5,7 +5,7 @@ use Throwable; use const PHP_EOL; -// Autoload the scoped vendor guzzle. This is to mimick a scoped code that would +// Autoload the scoped vendor guzzle. This is to mimic a scoped code that would // load this code. // Triggering the autoloading will autoload the Guzzle `functions.php` file which // declares the _scoped_ functions. @@ -19,9 +19,9 @@ echo 'Autoload code.'.PHP_EOL; require __DIR__.'/vendor/autoload.php'; -// Will fail to find the function -try { - \GuzzleHttp\describe_type('hello'); -} catch (Throwable $throwable) { - echo $throwable->getMessage().PHP_EOL; -} +// This is the test: it should have autoloaded the function file from the regular autoload +// despite the scoped file having been loaded previously. +\GuzzleHttp\describe_type('hello'); + +// Mimic PHPStan that uses some autoloaded code + diff --git a/fixtures/set035-composer-files-autoload/test.php b/fixtures/set035-composer-files-autoload/test.php index 03c636ad..0db9bd6c 100644 --- a/fixtures/set035-composer-files-autoload/test.php +++ b/fixtures/set035-composer-files-autoload/test.php @@ -6,5 +6,11 @@ '#PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\\describe_type\(\)#', $output, ); +$expectedResult = false; -exit($functionAutoloadFailed ? 1 : 0); +if ($functionAutoloadFailed) { + echo $output; + echo PHP_EOL; +} + +exit($functionAutoloadFailed === $expectedResult ? 0 : 1);