Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when using phiremock if HOME env is also the project root #10

Closed
michaelarnauts opened this issue Mar 13, 2023 · 1 comment
Closed

Comments

@michaelarnauts
Copy link

When setting the HOME env variable to the project root, phiremock has an internal conflict regarding the ~/.phiremock file or directory.

Problem description

For example, my home dir is /opt/app, my project is also installed there, so the compose vendor dir is /opt/app/vendor/.

The following happens in the file vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php:

  • The getDefaultExpectationsDir() function will return /opt/app/.phiremock/expectations as directory, this directory will be created if it doesn't exists. Basicly, the /opt/app/.phiremock directory will be created.
  • The searchFileAndGetConfig() function will try /../../../../../../.phiremock as a config file, what will also end up as /opt/app/.phiremock. If file_exists returns true (it will), it will try to include that file, but in this case, it's a directory.

This will throw the following exception:

Fatal error: Uncaught Error: Failed opening required '/opt/app/vendor/mcustiel/phiremock-server/src/Utils/Config/../../../../../../.phiremock' (include_path='.:/usr/local/lib/php') in /opt/app/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php:112
Stack trace:
#0 /opt/app/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php(92): Mcustiel\Phiremock\Server\Utils\Config\ConfigBuilder->searchFileAndGetConfig()
#1 /opt/app/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php(59): Mcustiel\Phiremock\Server\Utils\Config\ConfigBuilder->getConfigurationFromConfigFile()
#2 /opt/app/vendor/mcustiel/phiremock-server/src/Cli/Commands/PhiremockServerCommand.php(126): Mcustiel\Phiremock\Server\Utils\Config\ConfigBuilder->build(Array)
#3 /opt/app/vendor/symfony/console/Command/Command.php(312): Mcustiel\Phiremock\Server\Cli\Commands\PhiremockServerCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /opt/app/vendor/symfony/console/Application.php(1022): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /opt/app/vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(Mcustiel\Phiremock\Server\Cli\Commands\PhiremockServerCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /opt/app/vendor/symfony/console/Application.php(168): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /opt/app/vendor/mcustiel/phiremock-server/bin/phiremock.php(38): Symfony\Component\Console\Application->run()
#8 /opt/app/vendor/mcustiel/phiremock-server/bin/phiremock(4): require('/opt/app/vendor...')
#9 /opt/app/vendor/bin/phiremock(120): include('/opt/app/vendor...')
#10 {main}
  thrown in /opt/app/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php on line 112

Possible fix (untested)

In searchFileAndGetConfig(), we should check not only if the file_exist, but also a is_file():

===================================================================
diff --git a/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php b/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php
--- a/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php	
+++ b/vendor/mcustiel/phiremock-server/src/Utils/Config/ConfigBuilder.php	(date 1678721595534)
@@ -108,7 +108,7 @@
             '.phiremock.dist',
         ];
         foreach ($configFiles as $configFilePath) {
-            if (file_exists($configFilePath)) {
+            if (file_exists($configFilePath) && is_file($configFilePath)) {
                 return require $configFilePath;
             }
         }

mcustiel added a commit that referenced this issue Mar 24, 2023
* Updated phar

* fix: check if phiremock config file is actually a file

* chore(#10): added php8.2 to scrutinizer

* fix: modified another file_exists check to be is_file

* chore: updated phiremock.phar
@mcustiel mcustiel closed this as completed Apr 8, 2023
@mcustiel
Copy link
Owner

mcustiel commented Apr 8, 2023

Fixed in v1.2

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

No branches or pull requests

2 participants