Usually I see tutorials to tests Laravel which are just functional tests, I think unit testing should be given priority too. Done for this blog post.
To clone and run this locally do the following:
- git clone [email protected]:geshan/laravel-unit-test-example.git
- cd laravel-unit-test-example
- cp .env.example .env
- run
composer install --prefer-dist - php artisan serve
- try
http://localhost:8000/place/Cashon your browser you should seeCheckout for Cash with total 100 - try
http://localhost:8000/place/CreditCardon your browser you should seeCheckout for CreditCard with total 95
PHPUnit is used to write the unit tests, to run the tests run the following command after composer install is done.
>./vendor/bin/phpunit
To run with docker and nginx proxy at virtual host laravel.dev do the following steps
- Add
laravel.devto your/etc/hostswithsudo echo '120.0.0.1 laravel.dev' >> /etc/hosts - Run jwilder/nginx-proxy with
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro -v ~/projects/nginx-proxy/logs:/var/log/nginx jwilder/nginx-proxyit will have logs in the~/projects/nginx-proxy/logsfolder - Then start the container with docker-compose up (check the docker-compose.yml file for details)
- Then point your browser to
http://laravel.dev/place/Cashto see the desired output. (you might need to 777 your storage folder in case of errors)
- Run dydx/maria db
docker run -d -p 3306:3306 -v ~/Projects/data:/var/lib/data --name=mysql dydx/alpine-mariadb - Uncomment the following in docker-compose.yml
external_links:
- mysql:mysql
- username and password is homestead:secret, now your mysql host for laravel should be
mysql