Testing PHP - Up and running with PHPUnit

preview_player
Показать описание

💻Source code here:

👇Follow me on Social Media:

Chapters:
0:00 Introduction / overview
0:44 Install PHPUnit
1:21 Create a test file
2:30 Run a test from the command line
3:15 Making assertions
4:18 Tests which fail
6:07 Using colors in test feedback
6:35 Testing objects and classes
10:35 Using filter option to run individual tests
11:41 Autoloading classes in tests
13:39 Test scope
14:22 The setUp() method
15:16 The tearDown() method
16:24 Testing errors and exceptions
19:28 Test doubles
20:43 Creating mock objects
22:15 Mocking methods
25:57 Injecting mock test dependencies
27:54 Test number of times a method is expected to be called
29:03 Grouping tests
Рекомендации по теме
Комментарии
Автор

This is a great video, I'm doing a software developer apprenticeship, and this video saved me with learning unit testing, thank you sir!

KingDynamiteHD
Автор

This is great Gary, I am happy how you gradually incorporated things, many people start with a lot of bloatwares and make things harder for beginners to understand

nomanhanafi
Автор

This is GOLD.
BTW:
If you have received such an error:
Class 'ExampleAssertionsTest' could not be found in
You need to perform two steps:
1) Make sure your composer.json looks like that:
{
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
"psr-4": {
"": "tests/"
}
}
}
2) composer dump-autoload
Enjoy.

GreyDeathVaccine
Автор

Hey Gary, just wanted to let you know that you are getting me through my exams! Thank you so much for that :)

Byzzon
Автор

This tutorial was so peaceful with the birds chirping in the background. Thank you! 😄🙏🏻

dawid_dahl
Автор

I wish I could like this video multiple times as this is an excellent demonstration and introduction to TDD in PHP. Your explanation is clear and easy to grasp and you also explained the WHYs of every step.

Thank you for making this available to us!

ovuokeaghwotu
Автор

Clean 'n lean explanation. Congrats !!!

filanico
Автор

best explanation for unit test, thanks Gary

puneetchauhan
Автор

Hey, I was wondering if you can mock functions that are not in classes? I can’t find any clues to that topic …

ayayayayaka
Автор

Hi Gary! Very good explanation but could you explain where i should to do that? I am trying to open new project in my inteleji IDEA and i set phpunit library thru composer there.

But i can not figure it out where how you did it and why you have phpunit-demo package from the beginning

ИванОтрубов
Автор

Nice tutorial. Thanks because I found out something new.

AnonymousDeveloper
Автор

Hi may i ask how to test private/protected methods?

brtj
Автор

Hello Gray, i love your course, and i want to but the full course at your website,
but the problem is that i only have paypal as a payment method, is there a solution please? thanks :)

grayaahammed
Автор

Great video, nicely explained all the important topics with great examples. Thank you :)

AkanshaSaxena
Автор

By the way, do you have any testing tutorial where you show how to setup a test database which gets built and torned down with each test and such? If one wants to test db-related code.

dawid_dahl
Автор

I get this error unfortunately Undefined type 'PHPUnit\Framework\TestCase'. Any idea what could be wrong ?

tamamshud
Автор

Nice Tutorial.

Please make a tutorial series on CQRS, Microservices & DDD and how to implement them in Symfony.
Thanks.

abdulmobeen
Автор

Hey Gary, thanks for this simple explanation tutorial for testing . I have defined the Class which i want to test its functions but when i create new test class with extends PHPUnit\Framework\TestCase it returns me that error : Error: Class 'PHPUnit\Framework\TestCase' not found in on line 7

oussamaelaloui
Автор

Instead of having to learn all those assertions (AssertEquals, AssertSame, AssertIsFloat, assertGreaterThan, assertLessThan, etc), why doesn't phpUnit just use PHP logic? Inside of each testCase method, you should be able to do your own logic and return true or false. Like this:
if ($string1 == $string2) {return true;}

teddyruxpin
Автор

Could you please tell me which IDE are you using?

areebahmad
welcome to shbcf.ru