Laravel 5.8 Tutorial From Scratch - e49 - Testing 101 Using PHPUnit

preview_player
Показать описание
Testing is an integral part of modern PHP development. Let's work to get our customer controller under test.

DigitalOcean Referral

Resources
Course Source Code

About This Course

Ready to get started on your path to Laravel Artisan? In this series, we are breaking down all of the basics of Laravel to get you comfortable using the world's most popular PHP framework. Let's get started!
Рекомендации по теме
Комментарии
Автор

in laravel 7,
run "php artisan test" instead of "vendor/bin/phpunit"

akashthoriya
Автор

I MISS YOUR VIDEOS SO MUCH!
I suggest a video with relationships: product, category, subcategory, ( to help for laravel eCommerce )

linguapharm
Автор

Great tutorial, I suggest you to make such a integration with third-party like pusher, payment gateway and etc. Thanks a lot.

RoisulAsolole
Автор

For those who actually use MySQL as their DB and get error when trying to run tests in sqlite, I suggest to use MySQL for testing also.
You need to create separate database (smth like mydatabase-test);
In phpunit.xml bellow <server name="SESSION_DRIVER" value="array"/> (inside <php> tags) add:
<server name="DB_DATABASE" value="mydatabase-test"/>


So what this does is it uses MySQL instead of sqlite. I think this is slower, but it eliminates any compatibility issues.

kiprasbiel
Автор

Great! as Always!
It would be great to have some videos about creating a complete API with Laravel.
thanks so much for your help

mavbcn
Автор

Before Starting this lesson, I wish to let everyone know that laravel's recent version has changed the naming standard for test cases. SO if you use:
public function
{
// code here
}
IT WILL FAIL. It will not be detected by PHPUnit at all. The new format is that you use prefix the function name with "test" so it should be named:
public function
{
// code here
}

atiquechowdhury
Автор

when I run phpunit test in console, Vendor/bin/phpunit --filter only_logged_..._list, it shows : no test executs. I finially find this problem solved method.
Add test prefix to any test function in Test.php. like this : test_only_logged_..._list. It's gain the same effects as videos shows. Maybe the version of Phpunit : my version is 7.20. CHeers, hopefully helpful.

Leo-jhnj
Автор

Please, give us an accounting system or ecommerce app with Laravel. Your teaching skill has no equal.

busuyiowoyemi
Автор

This is the part of testing that I do not get. What should we test and what should we not test. I mean we can't test everything right? Especially if we work an hourly freelance project, writing to test every little thing is going to cost our clients too much. Or are you showing these things as an example, like asserting that the name is 3 letters, then asserting if the name is passed, I mean you can't do this with each field right. That would be too much. But where do we draw the line?

aseemlalfakawma
Автор

First of all I want to appreciate because of your high quality and useful tutorials ... In this episode u wrote some tests that triggered a question that why we should test this obvious actions ? We easily run app on browser and see the results ...are these tests essential for development ?

chichakjamshidi
Автор

With the current version of Laravel and Telescope I see no issue with running PHPUnit. Looks like the new version of Telescope is no longer causing issues.

uros.u.novakovic
Автор

Dang it. Your too late for me. I've been binge watching PHPUnit videos at Laracasts. Thanks for making these videos nonetheless! I'm a fan of the channel. :D

robbradley
Автор

I have a telescope switched on in my application, but phpunit is still working properly! Don't you know the reason Mr.Gonzalez?

TDarkCoder
Автор

Again, for the windows users:cls && "./vendor/bin/phpunit" --options [NAME_OF_OPTION]
although:
file: phpunit.xml
<server name="DB_CONNECTION" value="mysql"/>
<server name="DB_DATABASE" value="yourDatabaseName"/> // :memory: - for me doesn't work
file:
// Have to add \App\Users or use App\User;

ngapis
Автор

when I tried to execute "vendor/bin/phpunit" it gives me "vendor is not recognized as an internal or external command, operable program or batch file."

geraldterencio
Автор

There is an error in that store array you have put 'active' 2 times but php unit didn't catch that mistake!
Why ?

salmankabirshouvo
Автор

Sir please make a blog for beginners #Laravel ?

MuhammadAdnan-gxrd
Автор

whoa nice, is better coding while doing phpunit

tothebone
Автор

Hello. Thank you for tutorials. When testing, that user can add new customers. Wouldn't be better instead of "assertCount" to use "AssertDatabaseHas" and compare if input matches with database data?

linasgutauskas
Автор

Haha, this one overwritten my whole existing database with laravel migration data. Not happy.

dgloria