What I want
Run PHPUnit by terminal and configuration in PhpStorm
What I Have
Previous problem
Resolved in HERE - about not finding files
File that running
#!/usr/bin/env bash
# echo "Current working directory: '"$(pwd)"'"
cd $(pwd) && docker run --rm -t -v $(pwd):/var/www -e SYMFONY_ENV=dev ezsystems/php:7.1-v1-dev php $#
Summary
When I run this by terminal:
docker-phpez vendor/bin/phpunit --coverage-text
Everything working correctly.
When I try to run this with configuration of PhpStorm, I get warning that: PHP is not installed.
But running this as remote PHP interpreter, gives me:
docker://ezsystems/php:7.1-v1/php /opt/.phpstorm_helpers/phpunit.php --configuration /var/www/phpunit.xml.dist
Testing started at 17:06 ...
The value $_SERVER['IDE_PHPUNIT_PHPUNIT_PHAR'] is specified, but file doesn't exist '/var/www/vendor/bin/phpunit'
Process finished with exit code 1
Looking like mounting doesn't work.
Question:
do you know why? How to fix that?
In previous version of PhpStorm I didn't had any problem with that.
Right now, I have 2016.3.2.
Because after update you have to update tags for phpstorm_helpers docker image. There i put more how it should be fixed: https://youtrack.jetbrains.com/issue/IDEA-189164
After updating PHPStorm to 2017.1.4, what I did:
switched to docker configuration
phpunit loaded from composer's autoload.php
Started to working. Still don't know why docker-phpez not working by PHPStorm, but I will stop for now.
Related
I try to configure VSCode to use our php executable inside a docker container. Firstly i tried it on a macintosh and everything works as expected. At work we use windows pc´s and i cant get it to work.
Workspace Settings
"php.suggest.basic": false,
"php.executablePath": "C:\\Source\\stack\\.bin\\php.bat",
"php.validate.executablePath": "C:\\Source\\stack\\.bin\\php.bat",
"php.validate.run": "onSave",
"php.validate.enable": true
I tried to set a .sh, .exe or .bat file but none of them seemed to work.
php.bat
#echo off
docker run -i stack_php php %*
php.sh
#!/bin/sh
docker run stack_php php "$#"
return $?
Anybody of you can help me get this to work? We would like to change our IDE from PHPStorm to VSCode but we arent able to so because everything a developer needs is stored in docker containers.
I came up with a solution on Linux for multiple laravel sail projects.
Create a file named 'php' on /usr/local/bin
sudo touch /usr/local/bin/php
Make it executable:
sudo chmod +x /usr/local/bin/php
Edit the file (with sudo) and paste this code:
path=$(printf '%s\n' "${PWD##*/}")
command="docker exec ${path}_laravel.test_1 php "$#""
echo "Running php on docker ${path}_laravel.test_1"
$command
Now just run, example, 'php -v' inside the laravel sail project.
Or you can use plugin for that: https://marketplace.visualstudio.com/items?itemName=henriiik.docker-linter
Example how to configure it correctly could be found in their repository https://github.com/henriiik/vscode-docker-linter/blob/master/playground-php/.vscode/settings.json
You will need to modify the existing settings to look like this example below...
{
"php.validate.enable": false,
"docker-linter.php.enable": true,
"docker-linter.php.container": "stack_php",
"docker-linter.php.machine": ""
}
If you are running Docker on Windows and WSL2 you should replace the underscores for dash like this:
path=$(printf '%s\n' "${PWD##*/}")
command="docker exec ${path}-laravel.test-1 php "$#""
echo "Running php on docker ${path}-laravel.test-1"
$command
It took me a while to find out, i hope this can help someone.
I had the exact same issue, and just found a solution, but in my case I'm working under the Windows Subsystem for Linux, not straight Windows, so I'm not sure if/how it would be adapted. You can read more about it here: set PHP path from host to docker container
For me, the part that seemed to resolve the problem was moving the "wrapper" to /usr/local/bin, and then setting that as my php.validate.executablePath for the Workspace (you could also set it at the Remote WSL level, but in my case, I might develop with multiple versions of PHP)
I hope that might help you!
Update:
I just saw someone in the comments was working in Windows!
They suggested putting
docker exec -i your_container_name php %*
into a .bat file; looking at what you've already done, the difference appears to be using exec instead of run
Microsoft now has an extension that allows you to open a vscode project inside a container context. This lets you use the PHP executable loaded inside a Docker container for intellisense and other features.
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers
https://github.com/Microsoft/vscode-remote-release#readme
I've put this line into settings.json and it worked for me.
"php.validate.executablePath": "docker run --rm php:8.2-alpine php",
Go ahead and replace php:8.2-alpine with required php image (not container) name.
You can add it to Workspace settings.json to use different php versions for each project.
ps: I'm using MacOS, but pretty sure it should work on Windows too.
this is my current status:
I have a running symfony environment, based on a docker image. Everything works fine and from PHPStorm i can execute phpunit tests. But i want to execute them manually from console.
After i started all services by using docker-compose up --build, i login into the phpfpm service by: docker-compose exec -it phpfpm bash
then i move into my symfony project folder that contain all folders and files like "app/, bin/, vendor/, ... composer.json... etc"
I could go by calling vendor/phpunit/phpunit/phpunit but i want to get a shorter way. Is there any chance, maybe calling bin/phpunit or something like this?
Thanks in advance,
Max
PHPUnit has that script in the own composer.json, so bin (or vendor/bin) directory should contains a relevant symlink after running composer install. Also check your composer.json for bin-dir settings.
At least you always can create a symlink:
$ ln -s vendor/phpunit/phpunit/phpunit phpunit
According to the symfony docs the preferable way of using phpunit is by .phar file. In this way you can download phpunit as a .phar file and it will works both outside and inside docker container.
wget https://phar.phpunit.de/phpunit-6.0.phar
php phpunit-6.0.phar --version
Type now php phpunit-6.0.phar to run tests.
I am developing a project using PhpStorm and I am using Php 7.1 with Docker. I would like to integrate PHP code sniffer in PhpStorm.
In PhpStorm I go to Settings|Languages&Frameworks|PHP|CodeSniffer and I try to add a new configuration, I provide as PHP Code Sniffer (phpcs) path the path of a script with the following content:
#!/usr/bin/env bash
docker run --rm -ti --volume "$(pwd):/app:rw" -u $(id -u):$(id -g) prooph/php:7.1-cli php vendor/bin/phpcs "$#"
which just runs phpcs in my docker container.
When I click on Validate, PhpStorm gives me the following message:
The input device is not a TTY
The same script works perfectly when it's run from PhpStorm console.
Am I doing something wrong? Or what I am trying to do is just not supported?
You should run it without -t flag:
#!/usr/bin/env bash
docker run --rm -i --volume "$(pwd):/app:rw" -u $(id -u):$(id -g) prooph/php:7.1-cli php vendor/bin/phpcs "$#"
-t allocates a pseudo-TTY, that's why it works on PhpStorm console.
In PhpStorm 2019 it works out of the box, without the need of a bash script wrapper.
First, you need to go to Project Settings > Languages & Frameworks > PHP.
Click the button ... next to the field "CLI interpreter" and configure it to works with Docker, selecting your Image name.
Once you have configured the CLI interpreter, go to Project Settings > Languages & Frameworks > PHP > Quality Tools and click on the three dots (...) button next to PHP_CodeSniffer. Add new configuration that uses the CLI interpreter you just added and fill the CodeSniffer path (in my case this is "/opt/project/vendor/bin/phpcs").
Voilà!
I am using docker container on Linux Mint host machine to run PHPUnit tests, like this:
docker run -t -i --volume=$PWD:/var/www username/phpunit:v1 --stderr tests/
PHPUnit 4.8.3 by Sebastian Bergmann and contributors.
..........
Time: 1.18 seconds, Memory: 11.25Mb
So, this works fine. My next step was to create File Watcher inside IDE(PHPStorm), so that this docker command is run every time some of the test files change. However, when IDE runs the command, instead of getting the output like above, what I get is this error mesage:
cannot enable tty mode on non tty input
Looks like this is happening a lot on Windows machines, but I couldn't find what causes this issue on Linux. Is there a way to fix this ?
You are running the command from an IDE, which most probably isn't a terminal. So you might want to remove the -t parameter from the command:
docker run -i --volume=$PWD:/var/www username/phpunit:v1 --stderr tests/
Find a more detailed answer here.
I'm trying to install Laravel Homestead in order to be able to test my Laravel projects locally.
I'm following this tutorial: http://laravel.com/docs/4.2/homestead
In the "Installing Homestead" part I followed the second step "Manually Via Git (No Local PHP)",I don't have any PHP installed locally and can't use Composer. (Wasn't PHP supposed to be installed as part of Homestead?)
I got to this part:
Once you have installed the Homestead CLI tool, run the bash init.sh command to create the Homestead.yaml configuration file:
bash init.sh
In command prompt I tried to enter the following command:
bash init.sh
I got the following error:
'bash' is not recognized as an internal or external command, operable program or batch file.
Then I tried to enter the same command in Git Bash, and I got the following error:
bash: init.sh: No such file or directory
When I tried to enter in Git Bash simply
init.sh
I got the following error:
sh.exe": init.sh: command not found
I ran into this problem well. You need to hop into your terminal (I am on Mac.)
Type into your console: cd ~/Homestead
and to make sure you are in your newly generated Homestead folder (you can always click Finder > your home directory > Homestead to confirm it's where it should be),
then while in terminal simply type ls -- if it lists all of the files like Vagrantfile, composer.lock and bash init.sh, you should be in.
Once you know you are in the correct Homestead folder, it is now at that point in which you run bash init.sh
After doing this it now says Homestead initialized!
.sh is a unix/linux script executable, that isn't recognized on Windows. There's a init.bat included in the package, but it isn't referenced in the tutorial.
Just run init.bat from the command line. It will copy the files to:
%HOMEDRIVE%%HOMEPATH%\.homestead
You need install Git Bash, and then run commands into Git Bash.
Try init.bat that worked for me
If the init.bat refused to work
Go to the Homestead folder.
C:/Users/Computer Name/Homestead
You will see init.bat: double click to run it.
Problem solved.
I found the answer you may be looking for. I was having the same problems with this. Just make sure at the end of bash init.sh you put a ;
So in the git bash cmd you will have this line
$ bash init.sh;
Just do it using sudo.
$sudo bash init.sh