Using phpunit in laravel 4 without /vendor/bin/ - cmd

I have installed phpunit in this instance of laravel using composer. The files are present in the laravel/vendor/bin folder. when I run vendor/bin/phpunit the example test runs. In all the tutorials I am watching on unit testing in laravel the tutors simply run phpunit and it runs the test.
In the laravel documentation it says that I should be able to simply run phpunit to initiate the tests.
Is the documentation refering to phpunit being installed system wide and do the tutors in the video simply have it installed system wide or am I missing something?

In linux, get phpunit path by typing which phpunit in the terminal. Its probably in the /usr/bin/ dir. execute
alias phpunit='/usr/bin/phpunit'
in the terminal.

They have it installed system wide.
If you are in Windows, you can modify your PATH system variable to include the path to phpunit. For example on mine, I've appended ;C:\wamp\www\rel\vendor\bin to it.
Then you'd just have to navigate to the folder your project is in which should have the phpunit.xml file that was included with laravel and run phpunit on your command prompt.
Unfortunately, I am not completely sure how to do this on Linux or OSX.

In Mac OS, just go to your Laravel project directory via Terminal and then enter this command:
alias phpunit="~/Your Project Directory Name/vendor/bin/phpunit"
From now on you can run PHPUnit by just simply typing phpunit.

Related

DDEV/Laravel/PHPUnit: Problems with setup in PhpStorm

Using Laravel with DDEV/Docker on a Mac, I am stuck getting PhpStorm to run directly PHPUnit with coverage. I am following these instructions: https://ddev.readthedocs.io/en/stable/users/topics/phpstorm/
I started the setup with
curl -s "https://laravel.build/myproject?with=mysql,redis,memcached" | bash
Everything's is working fine, including debugging with Xdebug after I turned on Xdebug with
ddev xdebug on
PHPUnit works fine via console as well:
ddev exec phpunit
Composer version is 2.1.4.
Following the instructions named above, I am stuck at point 6.
What am I missing out? PHPUnit is located within the directory and it is composer-installed as well:
With composer version 2.2 the phpunit executable in vendor/bin is not a symlink anymore. It‘s a PHP file which includes the original executable with help of stream-wrapper, but including phpunit is not allowed: https://github.com/sebastianbergmann/phpunit/issues/4096#issuecomment-585900398
The bug is solved in composer:
https://github.com/composer/composer/issues/10387#issuecomment-1000246631
Use the following to get the latest dev version until this fix was official released:
composer self-update --snapshot
Further you can configure PhpStorm to use the original file instead:
vendor/phpunit/phpunit/phpunit
Thanks to all of you guys, I really appreciate your help.
Here is how I solved it:
I installed ddev-edge to avoid composer 2.1.x. I could not change it to 2.2 in config.yaml without failing ddev to restart when using stable version of ddev. It only worked on an active docker instance.
Then configurated ddev to use latest PHP-version 8.1 (for a new project from scratch, it makes sense anyway).
Then the error with PHPUnit changed to an error telling me that the PHP version is too old for the PHPUnit version. That was because PHPStorm automatically picked PHP 7.4 as default when connecting to Docker and checking the CLI remote interpreter.
So I changed the PHP executable from "php" to "php8.1"
See screenshots.
Now running PHPUnit from PHPStorm works fine, even with coverage.

phpunit testing not working on Laravel 5.4

I am new to using phpunit in Laravel for testing. When I tried and typed in phpunit in commandline, I got an
error.
I even tried to to use ./vendor/bin/phpunit like most people suggested and it still doesn't work. Here are all the errors that I have gotten. enter image description here
You need first to run composer, after this you have to run phpunit using the convention of your OS, I saw you are in Windows, so you need to run vendor\bin\phpunit or you can use gitbash to emulate Unix system.

Cannot open file "/tests/ExampleTest.php" Laravel5 using Windows10

i am running phpunit testing in laravel5 on windows 10,and getting this error by running the following command.
Cannot open file "/tests/ExampleTest.php",
D:\wamp64\www\forum\vendor\bin>phpunit /tests/ ExampleTest.php
Can you please suggest me what could be the issue?
Its seems that "phpunit" is not installed globally,try run this command from cli to install it globally and then you can use unit testing globally.
"composer global require phpunit/phpunit"

Can't find /root/.composer/vendor/bin/laravel: No such file or directory

I have installed composer on Centos 7 virtualbox with PHP 5.6.27. I will show the commands that I have used and the issues that I am now having. I should first say that all of these commands have worked on previous installations.
Okay so for starters here is what I used to install composer.
curl -sS https://getcomposer.org/installer | php
Followed by
mv composer.phar /usr/local/bin/composer
Now I am trying to install laravel via the commands listed below.
composer global require "acacha/adminlte-laravel-installer=~3.0"
Up to this point all of the commands listed above have successfully worked.
Now here is the current problem. When I try to run the following command I get an error.
laravel new laravel-with-admin-lte
-bash: /root/.composer/vendor/bin/laravel: No such file or directory.
I have tried a whole set of remedies for this message but it cannot find the .composer directory. Can anyone tell me where the correct .composer directory is and how I can modify it so that it looks to the proper location to finalize this installation?
I appreciate any solutions that you can provide me. I have struggled with this for two days straight and have googled everything under the sun. Hopefully, someone on here has had a similar solution with a valid resolution.
Put an alias to the freshly installed Laravel installer in your user configuration .bashrc:
nano ~/.bashrc
And place this inside the file:
alias laravel='~/.config/composer/vendor/bin/laravel'
And run the following to make sure your bashrc profile is reloaded:
source ~/.bashrc
laravel new project
download as superuser
download installer
sudo composer global require "laravel/installer=~1.1"
setting up path
export PATH="~/.composer/vendor/bin:$PATH"
check laravel command
laravel
I had the same problem, so I changed the directory.
This is the directory where your bash was created: /root/.config/composer
enter image description here
but when excute the laravel command, the system search en the directory : bash: /root/.composer/vendor/bin/laravel:
enter image description here
So, just you need to change the address /root/.config/composer/vendor to /root/.composer/vendor.
PD. sorry I am learning english, so it is a little bad.

How do I get phpunit to work in cloud9 IDE?

Just started out a laravel project on cloud9 IDE but I can't get phpunit to work. Every time I run the PHPUnit command I get a
command not found
response. From the file structure in the project I can see phpunit files. I have never used cloud 9 for a laravel project before so I can't really tell if thats how it's supposed to behave. Has anyone successfully used phpunit on cloud9 before?
You can install phpunit globally using composer (available in the default C9 workspace). Phpunit 4.8.* works with PHP 5.5.
sudo composer global require phpunit/phpunit:4.8.*
The phpunit executable will be installed in ~/.composer/vendor/bin/ so add the following line at the end of the ~/.profile file to make the command available elsewhere.
export PATH=~/.composer/vendor/bin:$PATH
Run source ~/.profile afterwards to register the new path then simply run phpunit in your Laravel installation folder.

Resources