Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Fatal error: Uncaught Error: Undefined constant "Eloquent\Phony\Reflection\STDOUT" #252

Closed
yanneg opened this issue Feb 16, 2021 · 5 comments

Comments

@yanneg
Copy link

yanneg commented Feb 16, 2021

After recently upgrading a Symfony 5.2 project to PHP 8, I'm getting the following error message:

NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Undefined constant "Eloquent\Phony\Reflection\STDOUT" in /usr/src/app/vendor/eloquent/phony/src/Reflection/FeatureDetector.php:155
Stack trace:
#0 /usr/src/app/vendor/eloquent/phony/src/Reflection/FeatureDetector.php(98): Eloquent\Phony\Reflection\FeatureDetector->Eloquent\Phony\Reflection\{closure}(Object(Eloquent\Phony\Reflection\FeatureDetector))
#1 /usr/src/app/vendor/eloquent/phony/src/Difference/DifferenceEngine.php(50): Eloquent\Phony\Reflection\FeatureDetector->isSupported('stdout.ansi')
#2 /usr/src/app/vendor/eloquent/phony/src/Difference/DifferenceEngine.php(37): Eloquent\Phony\Difference\DifferenceEngine->setUseColor(NULL)
#3 /usr/src/app/vendor/eloquent/phony/src/Facade/FacadeContainerTrait.php(193): Eloquent\Phony\Difference\DifferenceEngine->__construct(Object(Eloquent\Phony\Reflection\FeatureDetector))
#4 /usr/src/app/vendor/eloquent/phony/src/Facade/FacadeContainer.php(18): Eloquent\Phony\Facade\FacadeContainer->initializeContainer(Object(Eloquent\Phony\Assertion\ExceptionAssertionRecorder))
#5 /usr/src/app/vendor/eloquent/phony/src/initialize.php(10): Eloquent\Phony\Facade\FacadeContainer->__construct()
#6 /usr/src/app/vendor/composer/autoload_real.php(71): require('/usr/src/app/ve...')
#7 /usr/src/app/vendor/composer/autoload_real.php(61): composerRequire34151eb540343bf5a399e451787004d2('a4b31be0740d153...', '/usr/src/app/ve...')
#8 /usr/src/app/vendor/autoload.php(7): ComposerAutoloaderInit34151eb540343bf5a399e451787004d2::getLoader()
#9 /usr/src/app/public/index.php(10): require('/usr/src/app/ve...')
#10 {main}
  thrown in /usr/src/app/vendor/eloquent/phony/src/Reflection/FeatureDetector.php on line 155

One solution could be explicitly checking for the CLI SAPI:

--- a/vendor/eloquent/phony/src/Reflection/FeatureDetector.php
+++ b/vendor/eloquent/phony/src/Reflection/FeatureDetector.php
@@ -152,7 +152,7 @@ class FeatureDetector
                 }
                 // @codeCoverageIgnoreEnd

-                return function_exists('posix_isatty') && @posix_isatty(STDOUT);
+                return function_exists('posix_isatty') && PHP_SAPI === 'cli' && @posix_isatty(STDOUT);
             },
         ];
     }
@ezzatron
Copy link
Contributor

Thanks for the report. I think I borrowed that code from the Symfony CLI component. I'll go have a look at what they're doing and see if they've made any changes. Could you help me out with the version(s) of Phony you're using?

@yanneg
Copy link
Author

yanneg commented Feb 16, 2021

Sorry for not mentioning that in my report. I'm using the latest version of phony - 5.0.1

@ezzatron
Copy link
Contributor

Thanks. I've just pushed a branch that should hopefully fix the issue. Could you give Phony dev-update-ansi-check a go and see if that works for you?

I'm also curious - what SAPI are you running this under? I would have assumed most people run their tests under the CLI SAPI so I'd like to know the use case 👍

@yanneg
Copy link
Author

yanneg commented Feb 16, 2021

That worked!

I'm only running phony under the CLI SAPI (via Kahlan) and that's never been a problem.
But because I have it installed as part of my dev dependencies, it gets automatically evaluated and included in my composer autoloader and that wasn't playing nicely in a Symfony fpm-fcgi SAPI context - even though phony was not being used.

@ezzatron
Copy link
Contributor

Fixed in 5.0.2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants