Minu uus hobiprojekt Sooduskoodid. Panin üles 01.12.23. Vaatame, mis sellest saab. Hetkel tundub, et on üsna hästi vastu võetud.
01.01.24 seisuga võib öelda, et 1. kuu on läinud päris hästi. Search Console ütleb, et detsembris 248 klikki, Analyticsist ~2600 külastajat (peamiselt sotsiaalmeedia kaudu).
Lehte vahepeal täiendanud ka erinevate funktsionaalsustega, mis kahjuks väga välja ei paista 🙂
Veel aasta viimasel õhtul tegin tagasiside nupud kupongidele koos cache’is istuva rate limiteriga, et ise ka teaksin, mis koodid töötavad ja mis mitte. Loodan, need lähiajal Livewire komponentideks teha, et lehte uuesti ei laetaks. Siis oleks juba nagu päris.
In Zone webhosting I have several apps under one account. WordPress websites use PHP 7.4 (as WP does not support php 8). But my Laravel apps use PHP 8.
I can choose php version for server. For example:
laravel-app.mydomain.com – this uses php 8.0
wordpress.mydomain.com – this uses php 7.4
If I need to use command line interface (cli) then php version is always the same that I have set for my main domain settings. If I need to use specific PHP version in cli then I need PHPRC prefix before command of export PHPRC in the beginning of the bash script.
At some point var_dump in Postman started printing HTML instead of json and made debugging experience worse. I used php artisan serve and suspected that my CLI php is using xdebug. This advice I found helpful.
sudo phpdismod -s cli xdebug – to disable xdebug
sudo phpenmod -s cli xdebug – to enable xdebug
This is how you can disable and enable xdebug from command line. After this that <pre> thing should go away from Postman responses.
I need to test helper method that accepts Illuminate\Database\Eloquent\Collection as a parameter. But I can not figure out how to prepare it inside a unit test. My logic says it should be simple to create Collection from assoc array. But I just can’t get it to work.
At the moment, not to get stuck, I will probably use feature testing (because if feature (API endpoint) works then probably my helper method also works). Though, it feels stupid workaround.
If you are getting the response “No tests executed” from php artisan test then please check that your test classes have their names in singular. ContactTest instead of ContactTests.
I spent like 3h to figure out why my Feature tests don’t run from command line while working well in phpStorm. The reason was that my class names were in plural.
In phpStorm see Settings -> PHP -> Test Frameworks -> Test Runner. Check if you have default configuration file phpunit.xml checked. No need to change anything in this file.
Create .env.testing and copy whole DB_ block from .env (not just parts that are different). Change values to your test database values.
Then run php artisan config:clear which will clear configuration cache.
Everything should work 🙂
I spent several hours figuring it out. Hopefully you don’t.
Created new Laravel project by composer create-project laravel/laravel example-app. Trying to run tests/Feature/ExampleTest.php in PhpStorm and I get an error Class 'phpunit' could not be found in '/home/robert/phpunit-test-app/vendor/phpunit/phpunit/phpunit'. What does it even mean?! 😀 There are no answers on Google at the moment and this post will probably rank well.
Solution
For some reason my CLI interpreter did not make any sense. It took me quite a few hours to figure it out.
Panin lõpuks uue blogi lisamise vormi tööle (lehe allosas). See ei tee muud, kui saadab mulle e-mailile uue blogi lisamise info.
Pisut oodatust kauem kulus aega sellele, et .env failis e-maili saatmise konfiguratsiooni paika saada. Arenduse ajal kasutasin mailtrap.io teenust aga toodangus tahtsin ikka Zone enda SMTPd kasutada. Siin näidises oleva konfiguratsiooniga tekkis pildil olev viga. Põhjuseks, et mul oli Laravel 8 → Laravel 9 uuendamise käigus puudu jäänud mail.php failis rida 'verify_peer_name' => false (StackOverflow, Github).
Lisaks asendasin (peamiselt õppimise eesmärgil) Query Builder andmebaasipäringud Eloquent ORM päringutega, mis eeldatavasti võiksid olla kiiremad (eeldusel, et Eloquent oskab natuke nutikama päringu kokku panna kui ma ehk ise oskaks) ja paremini loetavad (kuigi nad on kohati päris õudsed). Näiteks selline näeb välja rubriigi päring.
Kui .NETis (koolis) arendus käis nii, et teed mudeli+seosed ja mudeli põhjal scaffoldid migrationi (me enamasti isegi ei süvenenud, mida üldse toodeti sinna), siis Laravelis teen mõlemad käsitsi ja nad üksteisest midagi ei tea. Migration on ainult andmebaasi muudatusteks (määrad baasis indeksid ja seosed). Model on Eloquenti päringute jaoks ja ta ei tea midagi sellest, mis baasis toimub.
Lisaks kirjutasin PostsSeeder‘i, mis Fakeri abil teeb kiiresti palju postitusi, et saaksin vaadata, kuidas rakendus 100k või miljoni postitusega töötab. Arenduse andmebaas on Dockeri konteinerina mul pisikeses Hetzneri CPX11 purgis (2 vCPU, 2GB RAM ja 40GB ketast).
Kellaaegadega tegelesin ka. Avastasin, et blogide RSS annab UTC ajad. Sellepärast võis jääda mulje, et Eestis on väga palju varahommikusi blogijaid aga tegelt oli lihtsalt kellaaeg vale. Need on vaja kuidagi Europe/Tallinn aegadeks saada. Lahendasin hetkel nii, et Carbon teeb need mallis korda aga ma sellega lõpuni rahul ei saa olla, sest mul on andmebaasis kuupäev ja kellaaeg eraldi. Natuke pean veel nuputama, kuidas seda veakindlalt lahendada.