This repository serves as a comprehensive collection of Laravel testing techniques and best practices, compiled from various technical tests and real-world scenarios encountered since 2022. It aims to provide developers with practical examples and insights into effective testing strategies for Laravel applications.
- Unit Tests: Demonstrates isolated testing of individual components, functions, and methods.
- API Tests: Provides examples of testing RESTful API endpoints and responses.
- Browser Tests: Includes Laravel Dusk examples for frontend and JavaScript testing.
- Database Testing: Covers strategies for testing database interactions and migrations.
- Test-Driven Development (TDD) Examples: Shows the TDD approach in action with Laravel.
- Test Doubles and Mocking: Illustrates the use of mock objects and test doubles for isolating dependencies in unit tests.
/tests
: Contains all test files organized by type (Unit, Browser, etc.)/database
: Contains database migrations and seeders used in tests/app
: Includes the Laravel application code being tested/app/Http/Controllers
: Houses the application's controllers for the Technical Tests/app/Helpers
: Contains helper functions and classes used across the application
- Git
- Docker
- Docker Compose
- PHP 8.3 or higher
- Composer
- Node.js and npm (for React testing)
-
Clone the repository with submodules:
git clone --recurse-submodules https://github.com/rayrlam/testing-playground.git cd testing-playground
-
If you've already cloned the project and want to load submodules:
git submodule update --init --recursive
- Navigate to the Laravel testing directory:
cd laravel-testing
- Copy the
.env.example
file to.env
:cp .env.example .env
composer install
- Start the Docker environment:
./vendor/bin/sail up -d
- Generate application key:
./vendor/bin/sail artisan key:generate
- Run migrations:
./vendor/bin/sail artisan migrate ./vendor/bin/sail artisan db:seed
- Laravel Dusk
./vendor/bin/sail dusk
- PHPUnit
./vendor/bin/sail test
- Access the Laravel application at
http://127.0.0.1/
We welcome contributions! If you have additional test examples, improvements, or bug fixes, please feel free to submit a pull request.
This project is open-sourced software licensed under the MIT license.