How to run phpunit in laravel 5.5 - php

I have a problem running phpunit in my laravel 5.5. I already go to vendor/bin and then execute phpunit using my command prompt in windows. But cmd just give another option or flag as shown in the picture below :
I have read laravel 5.5 documentation for unittest. It's said that we just need to execute phpunit {as shown in https://laravel.com/docs/5.5/testing}
Then I tried this :
How to run single test method with phpunit?
phpunit --filter testBasicTest tests\Unit\ExampleTest
As shown below :
BUt it's said that 'cannot open the file'. Then I Tried
phpunit ExampleTest, but still cannot open the file. So what's wrong here...?
Thanks in advance
Note :
Here's my phpunit.xml :

You need to run phpunit without getting inside the bin folder.
Try this:
vendor/bin/phpunit
This will load your phpunit.xml file. Otherwise it cannot load your configuration file. Unless if you don't give spesific path:
vendor/bin/phpunit --configuration /path/to/laravels/phpunit.xml

Just install phpunit through composer:
composer global require phpunit/phpunit
then all you are set to test your laravel project.

Related

laravel 5.1 phpspec command not found

I'm trying to run phpspec but when I do a command phpspec run inside root project folder it just prints:
-bash: phpspec: command not found
But when I do composer show -i it shows it's installed (because it's in package.json):
phpspec/php-diff v1.0.2 A comprehensive li...
phpspec/phpspec 2.5.3 Specification-orie...
phpspec/prophecy v1.6.1 Highly opinionated...
What's wrong?
You probably need to add the path to the executable to your $PATH or, when you call it...call it by the full path to phpspec (something like ./vendor/bin/phpspec run)

vendor/bin/phpunit not working for Lumen

I'm new to Lumen (and Laravel). I've created a project with Composer and now I'm trying to get PHPUnit to work.
I'm following a book, where it should be possible to run a default passing test by typing vendor/bin/phpunit in the terminal, but it gives the error:
'vendor' is not recognized as an internal or external command,
operable program or batch file
I've checked that the phpunit file is actually there and that phpunit is added as dependency in my composer.json file. I've also tried ./vendor/bin/phpunit and vendor/bin/phpunit/phpunit, but with the same result.
I've searched Google to find a solution, but everyone else seem to have issues when running phpunit (wihout vendor/bin) and the solution is to use the full path vendor/bin/phpunit, but since I'm already doing that, it does not fix my problem.
I'm using PHPStorm on a Windows machine and running the PHP server via PHPStorm. I've not modified the default Lumen project.
Any help is greatly appreciated!
UPDATE:
Trying php vendor/bin/phpunit gives the following error:
You need to set up the project dependencies using the following
commands:
wget http://getcomposer.org/composer.phar
php composer.phar install
I'm not sure what that means, since I've already installed Composer. I used Composer to create the project and I haven't changed the dependencies from the default.
I had the same problem, for Windows it's vendor\bin\phpunit ;)
It turned out that some symlinks and permissions were not installed properly in the default project. I tried deleting the entire vendor/ directory and run composer install.
Now I can run phpunit with the command vendor\bin\phpunit (because I'm running on Windows - thanks Nizarii)
try this:
php vendor/bin/phpunit
Try putting php in front of the phpunit path like so:
php vendor/bin/phpunit

Laravel 5 phpunit is not running tests

I'm been at this for days with no success. Running Laravel 5.1.
As I understand according to the Laravel doc.
An ExampleTest.php file is provided in the tests directory. After installing a new Laravel application, simply run phpunit on the command line to run your tests.
Ok so after running phpunit I found it is not globally installed and is located in vendor/bin/phpunit. Proceeding to run vendor/bin/phpunit gives me a screen with all the command options for phpunit. Its does not actually run any tests.
I searched more and came across a post that mentioned it could be a symlink issue. I followed the instructions in the post with no success. From memory I installed Laravel from composer so the symlink should not be an issue anyway.
These instructions involved deleting various files. I did notice that composer was pulling files from its cache when updating. So I cleared its cache and followed the process again. Still no success.
What are the tests not running? I'm at my wits end. Especially since its is supposed to run easily out the box.
In the end I was not calling the bat file correctly. I was running
C:\localhost\myProject\vendor\bin> phpunit
Instead I needed to run
C:\localhost\myproject> call vendor\bin\phpunit
Hence it now is referencing the phpunit.xml file with the test location information.
You need to install phpunit globally:
composer global require phpunit/phpunit
Then you can run phpunit from your project root.
You could just run the phpunit that comes with the project, just go to your project root and run ./vendor/bin/phpunit, that way the tests will execute the way they should be and you could get feedback in case it fails.
For some reason I haven't figure out yet if you install phpunit globally in your computer you won't get feedback of your tests.

How to install PHPunit in a Laravel project

I'm trying to set up PHPunit in a Laravel project (which is being running in a Linux VM using Vagrant and VirtualBox). I've added PHPunit to composer.json and run composer install and composer update, and yet nothing is working. Running phpunit from the command line does nothing. (Nor does php phpunit or php phpunit.phar.)
How do I get PHPunit to run my tests?
You must now run it using:
vendor/bin/phpunit
Install phpunit globally and then can you can use it with just phpunit command in your local project instead of vendor/bin/phpunit
(your composer/vendor/bin has to be in system path)
composer global require phpunit/phpunit
or you can add following alias in your VM and then you can run it within your project directory with just phpunit command
alias phpunit='vendor/bin/phpunit'

Laravel 4 phpunit is doing nothing

I am trying to run the default testcase of laravel 4 for an app. Phpunit works when I explicitly mention the testfile path but doesn't seem to work otherwise, furthermore it returns 255 code when I try to run Phpunit only.
Any idea?
Checkout your phpunit.xml file, there you will find bootstrap path to autoloader.
Are you using global PHPUNit framework or you are using local (installed with composer) ?
I created my vim mapping so it is pointing always to current file:
nmap ,t :!clear && phpunit %<esc>

Categories