Search code examples
phpdockerphpstorm

Run PHPUnit by terminal with Docker


What I want

I have project, where don't have docker/docker-compose. I want run PHP scripts - PHPUnit by terminal. Best would be working with PhpStorm.

What I have

File docker-phpez

#!/usr/bin/env bash
# echo "Current working directory: '"$(pwd)"'"
docker run --rm -v $(pwd):/var/www -e SYMFONY_ENV=dev ezsystems/php:7.1-v1 php $@

Result

Checking version

Run this docker-phpez -v, give me:

PHP 7.1.6 (cli) (built: Jun 12 2017 21:35:13) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.6, Copyright (c) 1999-2017, by Zend Technologies
    with blackfire v1.17.1~linux-x64-non_zts71, https://blackfire.io, by SensioLabs

Then this is correct.

Checking mount

When I run listing (modify files) then, I see all needed files.

Run PHPUnit

When I try to run, it see config file in main folder, but won't see bootstrap file in path:

PHP Warning:  include(/var/www/src/Tests/../../vendor/ezsystems/ezpublish-kernel/config.php): failed to open stream: No such file or directory in /var/www/src/Tests/bootstrap.php on line 3

Question:

  • why PHP inside container don't see this file, when I see this running inside ls /var/www/src/Tests ?

Update v1:

running pwd

docker run --rm -v $(pwd):/var/www -e SYMFONY_ENV=dev ezsystems/php:7.1-v1 pwd

give:

/var/www

running ls

docker run --rm -v $(pwd):/var/www -e SYMFONY_ENV=dev ezsystems/php:7.1-v1 ls

give list of all files/folders in current folder.

Composer

docker run --rm -v $(pwd):/var/www -e SYMFONY_ENV=dev ezsystems/php:7.1-v1 composer install

run correctly and install all data.

All command are run in MAIN folder of project


Solution

  • This:

    /var/www/src/Tests/../../vendor/ezsystems/ezpublish-kernel/config.php
    

    is translated to:

    /var/www/vendor/ezsystems/ezpublish-kernel/config.php
    

    Because of ../..

    You are not looking there.