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
Related
I am developing a PHP web application inside of a Docker container. Using volumes: inside of my docker-compose.yml file, I have specified a local directory so that any files generated are dumped and persist after the container is destroyed.
volumes:
- ./docroot:/var/www/html
Inside my Dockerfile, I RUN a command that installs a command line management tool:
RUN curl -sS https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer && \
ln -s /root/.composer/vendor/bin/drush /usr/local/bin/drush
RUN composer global require drush/drush:8.3.3 && \
composer global update
When the container comes up, I can use docker-compose exec -it <container> bash to get inside the container, and everything works fine. drush is in my path, and I can use it globally throughout the container to manage the app.
Now here is the strange part. Part of my application is that I have to run that command from a PHP script inside the container to help automatically manage some of the build process.
Using php, I run exec('drush dbupdate', $output, $retval); $retval returns a exit status of 127, or command not found and $output is empty. If I switch up the exec to use the full path I get an exit status 126.
If I go back into the container, I can run that command just fine. Note all other cli commands work as expected with exec (ls, whoami, etc but which drush returns exist status 1)
What am I missing? Why can I use it with no problems manually, but PHP exec() can't find it? passthru(), shell_exec(), and others have the same behavior.
composer global install will not install the command "globally" for all users, but "globally" as in "for all projects".
Generally, these packages are installed in the home directory for the user executing the command (e.g. ~/.composer), and if they are available in your path is because ~/.composer/vendor/bin is added to the session path.
But when you run composer global require (while building the image) or when you "log in" to the running container (using exec [...] bash) the user involved is root. But when your PHP script runs, it's being executed by another user (presumably www-data). And for that user, ~/.composer does not contain anything.
Maybe do not install drush using composer, but rather download the PHAR file directly or something like that while you are building the image, and put it in /usr/local/bin.
If you are using Drupal >= 8, the recommended way of installing Drush is not as a "global" dependency, but as "project" dependency, so that the appropriate drush version is installed. This comes straight from the docs:
It is recommended that Drupal 8 sites be built using Composer, with Drush listed as a dependency. That project already includes Drush in its composer.json. If your Composer project doesn't yet depend on Drush, run composer require drush/drush to add it. After this step, you may call Drush via vendor/bin/drush
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.
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 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/
I did a fresh installation of Ubuntu and after installing Yii2 etc I can't seem to be able to run codecept anymore.
I'm using Yii2. I required the latest codecept version in composer.json which is working fine. But I can't seem to find a way to get codeception running again.
I've been looking through all the guides but none of them have anything other then just to composer require or add it to the composer.json. I do have noticed when I wanted to add codecept to my $PATH that I don't have a codecept file in root/vendor/bin/, where I think the $PATH entry should point to.
I have no idea where to go from here. Did I miss some step somewhere maybe?
Just to sum things up:
codeception (yiisoft/yii2-codeception) is installed.
root/vendor/bin/ does not contain anything that points to codeception.
command: codecept run unit returns: codecept: Command not found
command: (./)vendor/bin/codecept return: "path": no such file or directory.
codecept: command not found on Ubuntu then you should follow these steps:
sudo composer global require "codeception/codeception=2.1.*" "codeception/specify=*" "codeception/verify=*"
and then run this command:
sudo ln -s ~/.composer/vendor/bin/codecept /usr/local/bin/codecept
So codecept build and codecept run will work.
If you are using Windows then run this command:
composer global require "codeception/codeception=2.1.*" "codeception/specify=*" "codeception/verify=*"
Add this line into your path:
~\AppData\Roaming\Composer\vendor\bin
You should add composer global packages binaries to your PATH.
For local development I'm using Vagrant, here is example for it:
export PATH=$PATH:/home/vagrant/.composer/vendor/bin
If you have some like this error:
$ php ./vendor/bin/codecept run
Could not open input file: ./vendor/bin/codecept
Just run:
$ rm composer.lock
$ composer update