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

[Bug]: v2.6.0 returns error when run in MacOS docker laravel/sail context #249

Closed
1 task done
dennyweiss opened this issue Apr 17, 2023 · 5 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@dennyweiss
Copy link

dennyweiss commented Apr 17, 2023

Short bug description

Executing code in Laravel Tinker leads to an error message as output instead of printed values.

Extended bug description

I receive this error or no output when I try to run expressions with Laravel Tinker:

// Laravel Tinker started at 2023-04-17 17:06:32
PHP Warning:  require(/AbsolutePathOnHostSystem/web2api/vendor/autoload.php): Failed to open stream: No such file or directory in Command line code on line 9
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP Fatal error:  Uncaught Error: Failed opening required '//AbsolutePathOnHostSystem/web2api/vendor/autoload.php' (include_path='.:/usr/share/php') in Command line code:9
Stack trace:
#0 {main}
  thrown in Command line code on line 9

*** Execution finished ***

Your project is not the problem

  • I tried using a fresh laravel install - I'm fairly certain it has nothing to do with my project.

How to reproduce?

  1. Run simple expressions like echo 'abcd';
  2. Expect something like: abced

Expected behavior

abcd as output

Screenshots

No response

IDE & Version

2023.01

PHP Version

PHP 8.1.17

OS and version

MacOS 13.2.1 (22D68)

Laravel Tinker plugin version

2.6.0

Interpreter type

Docker compose

Laravel Version

v9.52.4

Tinker version

v2.8.1

Psysh version

v0.11.10

Additional Context

I use Colima as a docker runtime. PHPStorm does recognize the docker-compose environment as Docker Desktop for Mac is installed.

@dennyweiss dennyweiss added the bug Something isn't working label Apr 17, 2023
@Roboroads
Copy link
Owner

So, it could be any of these reasons for this:

  1. your path mapping for your interpreter is not setup correctly.
  2. your local folder is not shared with your interpreter.
  3. the path where PHP is executed isn't setup correctly, I can't imagine /AbsolutePathOnHostSystem/web2api is the right path on the interpreter.

Anyway, it's an error with your interpreter settings, thats 100% sure. Please check under Settings -> (...) PHP and see if your path mappings are correct and if the correct working directory is selected in your compose file.

@dennyweiss
Copy link
Author

@Roboroads I think it's not as easy as you think because the same settings work with PHPStorm 2022.03 & Laravel Tinker v2.4.0. With v2.5.0 + v2.5.1 and the changed path resolution, the buggy behavior started.

So your hint with the path mappings is a good one.

Notice: I changed my real path to /AbsolutePathOnHostSystem/web2api for github (you know privacy). In reality, the path points to the real filesystem location on the host system and also maps it via PHPStorm > PHP > Servers to the right in the container mount location. I'm able to run all tools e.g. xdebug, inside the container with PHPStorm, so a general mapping mismatch is not the source of the issue

When I look at the path mappings for the interpreter I recognize the following correct settings:

phpstorm-colima-sail-mappings

@Roboroads is your plugin taking into account that there can be more than one path as mapping?

For completeness these are the plugin settings. It's also not getting better when I set the paths to the container location: /var/www/html

phpstorm-laravel-tinker-paths

@dennyweiss
Copy link
Author

I've spotted the problem. Since version v2.5.0 you changed the project base path resolution from __DIR__ to $projectSettings->laravelRoot and ended with:

$app = require_once ($projectSettings->laravelRoot ?: __DIR__) . '/bootstrap/app.php';

Currently, you address the following cases:

  1. __DIR__ laravel installed in project root -> works for the local and remote interpreters
  2. $projectSettings->laravelRoot custom laravel root -> works only for local or maybe for docker on Linux but not for Docker for Mac & not Docker for Windows because, in these cases, the project root of the host system is not the root for the remote/container

✅ Workaround/Solution

In case of a correct setup remote interpreter (interpreter and mappings) and your PHP project is located at the root in the remote environment (aka docker container), then leave the Laravel Tinker > Project Settings for Laravel root folder and Vendor root folder empty. This applies to the Laravel Tinker plugin v2.6.0.

⚠️ Real Solution
A natural solution has to address the case that there could be running a laravel application in a remote environment (aka docker container) that is not located at the root.

@Roboroads
Copy link
Owner

Ah yes. This is why those two settings were made. You can change those path to reflect the correct paths in the interpreter.

@Roboroads
Copy link
Owner

I've added all the info into #250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants