If you're looking to level up your Laravel skills? My new course "Mastering Laravel 10 Query Builder, Eloquent & Relationships" is the perfect opportunity: www.udemy.com/course/mastering-laravel-10-query-builder-eloquent-relationships/?referralCode=C784C3DB5B8925207FCB
One thing is missing. How to set up test database. (if you already have some data) So the tests will use different db and then they will wipe out the test db.
suppose i have a simple post crud. now my question is how to determine what to test? if i test each validation of a suppose store post, there may be more than 10 validations, then we have to create > 10 test methods? plus there are all these test in this videoes. making the all these test will be like creating the whole project again?
Thank you for greate video PS. 13:00 This UserTest class was created with --unit option then Laravel extend from PHPUnit\Framework\TestCase. Without --unit, it will extend from Tests\TestCase.
Didnt get the delete user method :( Why we check if a user exists when we always create one before that ? And why at the end we hardcode assertTrue(true), isn't that way the test never possible to fail?
TRying to follow. But yours is assuming same versions and having PHPUnit installed correctly... I'm using Windows MS Code... PHP 8.3.7, PHPUnit 11.3.1, Composer 2.7.6 .... I can't run the commands because of version issues. VENDOR is below the root and copying that into the directory gets other errors.
Regression testing basically perform after completing of retesting. The main purpose of regression testing is to check the impact of modification. Whether still our application is acting stable.
hi dude, I believe that there is an error in the code you wrote for the user delete testing.. you are creating the user with the factory, then checking if the user exists with an if statement.. but in case that statement won't be true, the test will assert true regardless.. I'm not sure if you get what I mean.. as far as I know test shouldn't contain any if statements ?!
Hi, Dary, I came across your channel, when I tried to find a Sanctum puzzle. The puzzle is when using Sanctum, it will generate a token, then send a request with the correct token to backend, it will work, it is great. But if I modify the token to make the wrong one, then send a request with the postman, it won't show any error, it will redirect to login page directly. So do you know how show an error message when send a wrong token to the backend?
Yes, PHPUnit can be used for functional testing in PHP. It allows for the creation of automated tests that simulate user interactions with the application and can test the application's functionality as a whole.
Please any idea why my php artisan test gives this? I am using Lumen. >Command "test" is not defined. >Do you want to run "make:test" instead? (yes/no) [no]:
Hi Ramziddin, I found a pretty interesting comment on the internet about testing: what do you do when you write code without tests? after almost every change you run the whole application, you wait until it starts, you go to the page you've just changed, you input some data, you press the button and you check... if the answer is correct, if the popup appeared, if the mail was sent and so on. you DO test. but you just do it manually. and you repeat all those tests after every change. and if you don't repeat them then you will find bugs on production and you will have to correct them quickly under stress and you will have to again check if you've fixed them correctly. and you will have to do it manually... Hope this makes sense.
@@codewithdary that's odd. i think a better approach is to clone the existing DB schema and append _test to the DB name. then delete that DB after the tests are done
@@codewithdary but there's an option for data persistence during tests, right? for example i want to test the relations. i would send API json with a mix of bad and good test data, and i want to count that only good data are the ones that are actually saved, right? i could be wrong but other frameworks use a cloned DB for tests and then drops that DB once the tests are done, so your current DB is untouched. in laravel, it's like setting the flag --env=.env.testing, using a test DB. although other frameworks does it implicitely.
@@codewithdary I'd ordinarily agree with you - and I think you've done a great job putting this video together - but you are saving data to the db at 20:04 ( ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-UjA-16diixc.html ) . Laravel has a doc on testing an it does state that it will auto create a testing db and tear it down after tests..
if I want to test function or Controller I already created did i need to make php artisan make:test UnitTest and copy my function in it ? and same question with test database
You should be verifying responses in tests, and not the entire controller you created. If you are using the database, you should check if the right access methods are triggered.
@@codewithdary I have problem with http test when I try it it give this error Failed asserting that two strings are equal. and aim an arrow to response->assertRedirect('/signin');
Try running composer dump-autoload in case you upgraded recently. Otherwise try to delete your vendor directory and try running composer install to see if that helps