I just installed Laravel 5.5.* using following composer commands:
composer create-project --prefer-dist laravel/laravel blog "5.5.*" --prefer-source
Here is my Laravel instalation folder:
╭─yusuf#yusuf-he ~/test-laravel/blog/vendor/laravel/framework ‹cf750b0›
╰─➤ ls
CHANGELOG-5.4.md CHANGELOG-5.5.md CODE_OF_CONDUCT.md composer.json CONTRIBUTING.md LICENSE.md phpunit.xml.dist README.md src tests
And now I am wondering about how to run the unit tests that owned by the Framework it self ?
I've tried this but got another error:
╭─yusuf#yusuf-he ~/test-laravel/blog ‹f4cba4f*›
╰─➤ ./vendor/bin/phpunit ./vendor/laravel/framework/tests
PHP Fatal error: Class 'Illuminate\Tests\Integration\Database\DatabaseTestCase' not found in /home/yusuf/test-laravel/blog/vendor/laravel/framework/tests/Integration/Database/EloquentBelongsToManyTest.php on line 16
Fatal error: Class 'Illuminate\Tests\Integration\Database\DatabaseTestCase' not found in /home/yusuf/test-laravel/blog/vendor/laravel/framework/tests/Integration/Database/EloquentBelongsToManyTest.php on line 16
I need this to make sure that installed Laravel 5.5 is running well in my environtment.
Set the environment database testing on the .env file and phpunit.xml
Finally I got the answer by my-self, to test the Framework it self by running unit tests I need to install it from the inside of Framework folder.
cd ~/test-laravel/blog/vendor/laravel/framework
composer install
./vendor/bin/phpunit
Don't forget to set/uncomment the redis connection in php phpunit.xml
<env name="REDIS_HOST" value="127.0.0.1" />
<env name="REDIS_PORT" value="6379" />
and don't forget to make sure that your redis server is on
redis-server
Related
I want to create new laravel project by composer. I use composer create-project laravel/laravel new-project command for create new project. then, my project is created following this picture.
I start Laravel's local development server using the Laravel's Artisan CLI serve command (first cd new-project and then php artisan serve command). But I got the following error.
Why is there no vendor folder in this project?!!!
How do I fix this error?
(I used PHP 8.1.10)
You need to issue composer install to install packages which creates the vendor/ folder
After setting up Homestead for 1 specific project only, I want to run the Artisan CLI for database migrations. I tried to follow this tutorial and I keep getting this error:
Could not open input file: artisan
I set up the project by running these commands (Windows):
composer require laravel/homestead --dev
vendor\\bin\\homestead make
vagrant up
And then I made sure to be in the root project directory and then run php artisan list, which gives the error above.
I also tried to ssh into the Homestead VM and navigated to the code folder (where my project resides) and run php artisan list, to which it gives the same error.
Attached is my working directory where I run the artisan command, as requested:
I have tried running it in root dir and in vendor\\laravel to no avail.
So how would one run the artisan CLI in a Laravel Homestead project?
I think I've figured it out. The problem was that I haven't set up a Laravel project using composer yet, and skipped to install Laravel Homestead for this project.
So to make a Laravel project named e.g. quickstart, one should first create the project by running
composer create-project laravel/laravel quickstart --prefer-dist
(see https://laravel.com/docs/5.1/quickstart#installation for more details)
Only after that, set up homestead for the project by running
composer require laravel/homestead --dev
vendor\bin\homestead make
And now the project should be fully initialized.
Refs: https://laravel.com/docs/5.7/homestead#per-project-installation
I just installed a fresh Laravel 5 project, my first one on this version. PHPUnit is supposed to be out of the box with the framework and every tutorials I saw just say to type phpunit within the project folder to launch the Unit Tests.
I checked and PHPUnit is in the composer.json, I also did a composer install and composer update just in case it wouldn't be here
website(master)$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing phpunit/phpunit (4.6.1)
- Installing phpunit/phpunit (4.6.2)
Downloading: 100%
But it just doesn't work phpunit isn't recognized at all
website(master)$ phpunit
-bash: phpunit: command not found
Seems like nobody got this problem before as I Googled it. I hope I'm not doing any stupid mistake. Any idea or suggestion ? Thanks guys ;)
I didn't install PHPUnit globally and didn't define the path. So for anyone who would have same problem :
composer global require phpunit/phpunit
composer global require phpunit/dbunit
Then you add this to you ~/.bash_profile or ~/.profile
export PATH=~/.composer/vendor/bin:$PATH
This occurs when you don't have phpunit installed globally.
Run this command to use the local version (installed with composer):
vendor/bin/phpunit
in windows machine the command is different please use this command
php vendor/phpunit/phpunit/phpunit
orignal source
You can run this command in cmd before running phpunit command:
doskey phpunit="vendor/bin/phpunit"
And if you are lazy as I am, you can run this one:
doskey pu="vendor/bin/phpunit"
for people who have WINDOWS 7, use the .\vendor\bin\phpunit command instead of ./vendor/bin/phpunit
Run the command
composer config --list --global | grep -w home
You can find the find the [home] with composer path, similar to this one.
[home] /home/example_username/.config/composer
The path ~/.config/composer is where composer global packages are installed. Next run the command...
export PATH=~/.config/composer/vendor/bin:$PATH
I made a permanent link to my phpunit like this
echo 'alias phpunit=vendor/bin/phpunit' >> ~/.bash_aliases
now phpunit is working by itself and stays even after I restart the terminal
Include this line on your composer.json
"phpunit/phpunit": "4.0.*",
Run composer update.
You should be able to run the following command on your Laravel directory.
vendor/bin/phpunit
I'm using Homestead to serve my Laravel application. I'm trying to run PHPUnit. According to the docs:
An example test file is provided in the app/tests directory. After
installing a new Laravel application, simply run phpunit on the
command line to run your tests.
Well, when I'm "simply running" phpunit in my project root (inside the Homestead environment) I get this:
The program 'phpunit' is currently not installed.
Do I need to install PHPUnit separately then? The documentation does not mention it. What am I doing wrong?
You can install it globally on the system using.
composer global require phpunit/phpunit
However, if you need different versions for different projects this can cause issues.
The alternative option is to use the version installed as part of your dependencies by referencing the path to your vendor directory.
./vendor/bin/phpunit
You could even add an alias to your aliases file in your ~/Homestead directory. That way you're always using the phpunit version that is installed with your project dependencies.
alias phpunit=./vendor/bin/phpunit
You'll need to restart the homestead box to make use of the alias.
You can install it globally with:
$ composer global require "phpunit/phpunit=4.4.*"
# then use
$ phpunit
or you can use it with your local composer:
$ composer require "phpunit/phpunit=4.4.*"
# then
$ vendor/bin/phpunit
Since it's a package required for development, Laravel provide PHPunit(require-dev section in composer), you should find it in vendor's folder :
$ your_app/vendor/bin/
You can run the command from the root of your app folder by typing :
$ vendor/bin/phpunit
I hope it will help !
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'