Test Apps for Laravel
Noted: It is better to perform the following these steps in a GUI VM environment rather than docker so you can check the laravel application using a browser
- Find out the earliest supported PHP version for Laravel 11: 8.2.0
docker run -it php:8.2 bash(docker only) / Setup PHP 8.2 using phpbrew- Then inside docker/VM:
curl -sS https://getcomposer.org/installer | phpmv composer.phar /usr/local/bin/composerapt update && apt install git zip unzipcomposer create-project --prefer-dist laravel/laravel 11- <log out of docker>
docker cp \<docker-id\>:/11 .(docker only)
Noted: Laravel framework is changing so the setup are also changing. Some steps may not valid for the future laravel versions but the idea is somehow similar.
We have a laravel test case testing controller, events, sql, cache. In order to get controller, events, listener setup, we need to refer to laravel document.
e.g. https://laravel.com/docs/11.x/events
- We need to edit this folder in order to fit in nosetest, here is the list of files. Can refer to the
11folder in master branch- Added
app/Http/Controllers/TestControllers.php(There are 2 functions for nosetest,nosetest()&nosetestError(). They are testing event + listeners, database, cache & exceptions - Updated
routes/web.phpfor/nosetest&/nosetesterrorrouting - Added
app/Events/NoseEvent.phpfor event object /php artisan make:event NoseEventand merged the code - Added
app/Listeners/NosetestQueuedListener.php/php artisan make:listener NosetestQueuedListener --event=NoseEventand merged the code - Added
app/Listeners/NosetestSyncedListener.php/ (refer https://laravel.com/docs/11.x/events#event-subscribers ) - Updated
app/Providers/EventServiceProvider.phpto listenNoseEvent(Not valid anymore for laravel 11+) - Added
app/Models/Nosetest.phpfor database object /php artisan make:model Nosetestand merged the code - Updated
bootstrap/cacheinto symbolic link because Jenkins doesn't have admin right in nosetest runtime - Added
database/migrations/2020_10_21_212030_create_nosetest_table.phpto create the database and table in sqlite - Updated
storage/framework/viewsinto symbolic link because Jenkins doesn't have admin right in nosetest runtime - Added
terminatefunction tovendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.phpfor nosetest [This path can be different from newer laravel version] (Not valid anymore for laravel 11+) - Updated
.envfor Jenkins environment (The keys are database connection parameters and using array for cache) - Create database and table file by touch
11/database/database.sqlite - Create database and table from the migrations files by
cd 11 && php artisan migrate - IMPORTANT Make sure all files are committed by editing
.gitignorefiles in all folder (e.g.11/and11/database/)
- Added
Tips: Use php artisan serve to test the laravel app step by step first and customize the environment setting for Jenkins
Reference: commit from the laravel 6 update