PHPUnit does nothing Gitlab-ci - php

When Gitlab-ci execute the script : php vendor/phpunit/phpunit --colors --verbose --configuration phpunit.xml
PHPUnit seems to do nothing this is the output from Gitlabci :
$ php vendor/phpunit/phpunit --colors --verbose --configuration phpunit.xml
Job succeeded
I've tried with no option for PHPUnit and it's still the same i don't understand why, it's working properly on my local
I'm working with the framework Laravel

If you installed phpunit with composer and haven't changed the bin-dir configuration, the path to phpunit is vendor/bin/phpunit:
php ./vendor/bin/phpunit
You should also be able to simply call the phpunit script directly:
./vendor/bin/phpunit
Assuming your current working directory is the root of your project.

Related

PhpStorm doesn't read PHP configuration from Docker container

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.

Call phpunit from console in my symfony project

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.

How to run unit tests with Codeception in Yii2?

I'm new to the Codeception framework and trying to run the unit test scripts from this directory:
tests/codeception/frontend/unit
DB configuration for testing has been done in config-local.php.
Now, my question is how to run the test scripts? I've tried to run the following commands from the terminal:
frontend tests
cd frontend
codecept build
codecept run
But it says Codecept: command not found.
Install Codeception via composer:
$ composer require "codeception/codeception"
From now on Codeception (with installed PHPUnit) can be run as:
$ php vendor/bin/codecept
Next, initialize your testing environment:
$ php vendor/bin/codecept bootstrap
Finally, run the following commands from the yii2 tests/codeception/frontend folder:
$ php vendor/bin/codecept build
$ php vendor/bin/codecept run
Follow this Quickstart Guide to read more about Codeception installation process.
Important note: if you want codecept command to work from the command line:
codecept bootstrap
codecept run
... then you need to configure the $PATH variable properly.
The fallowing examples need installation codecept globally. This method work for the current user and linux systems.
composer global require "codeception/codeception=2.1.*"
composer global require "codeception/specify=*"
composer global require "codeception/verify=*"
You can set new path $PATH: in /home/user/.bashrc
export PATH="$PATH:/home/user/.config/composer/vendor/bin"
or set alias in .bashrc
alias codecept="/home/user/.config/composer/vendor/bin/codecept"
Now you can use simply
codecept build
codecept run

Laravel 5.2 Testing : Test is not running

I have create a test via terminal with command :
php artisan make:test UserTest
Now i want to run the test with the following command :
vendor/bin/UserTest
But it returns
bash: vendor/bin/UserTest: No such file or directory
PHPunit is Installed. I have checked.
Am i missing something ?
Run tests with this command from Laravel root project directory:
vendor/bin/phpunit
If you want to run custom package tests, use:
vendor/bin/phpunit packages/name/package/

Showing docker container output within an IDE

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.

Categories