This is GOLD. BTW: If you have received such an error: Class 'ExampleAssertionsTest' could not be found in '/home/$USER/projects/phpunit-demo/tests/ExampleAssertionsTest.php'. 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.
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
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!
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 :)
Hi Grayaa...it's a pain. The site is hosted on Teachable which only allows me to take PayPal payments if the course price is in USD but I set the course price in euros because that is the currency that most of my followers use. I don't have a solution atm but I'll work on it.
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
phpunit-demo is just the name of the folder I created for the project. All you need to do is create a new folder, open that with your IDE, then install phpunit into that folder.
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;}
You could try something like this I guess: bestofphp.com/repo/php-mock-php-mock-php-testing But I think a better way would be to wrap classes and methods around the functions and use those wrappers instead because they can be mocked.
@@GaryClarkeTech thank you for the quick answer. I got a finished project where I have to write tests. It’s kinda hard to rewrite everything in a class
You can use Reflection like so: $class = new ReflectionClass('MyClass'); $method = $class->getMethod($name); $method->setAccessible(true); But some consider to be a bit of a hack. 'Best practice' is to test only a class's public interface.
Thanks Daniel. It's actually all custom colors which I set myself...I think I just picked one of the built in dark themes as a start point. I show how to do it in this PHPStorm recording > ua-cam.com/video/nva_En6MPf8/v-deo.html
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.
Yes but it's in a Symfony tutorial rather than just a plain PHP tutorial (ua-cam.com/video/TOa7JGbRwvk/v-deo.html) I may demo how to do this in plain PHP in the Beyond The Basics course which I am working on.
That would be a great addition. I am looking for such a thing (haven't managed yet to get it done via fixtures, so now I just import an sql-dump every time I start my tests. Not sure if this the best way to do it.
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 O:\xampp\htdocs\Jmeter_\Page_login\tests\tests.php on line 7
Hi..I'm not sure why it didn't work but I've pasted it in again. Here it is for your convenience: www.udemy.com/course/the-complete-object-oriented-php-developer-course/?referralCode=F2C53858029119CC9F39
I watched this video to understand Mocking and when he get there Unfortunately you started coping and passting and talking faster whitout explaining anyway thx
Thanks Naseem..this is genuinely my favourite kind of feedback because it helps me improve my content (much more useful than a downthumb!). Thanks for watching and I'll cover mocking again some time soon.
This is GOLD.
BTW:
If you have received such an error:
Class 'ExampleAssertionsTest' could not be found in '/home/$USER/projects/phpunit-demo/tests/ExampleAssertionsTest.php'.
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.
This is a great video, I'm doing a software developer apprenticeship, and this video saved me with learning unit testing, thank you sir!
Great stuff...also check out the full course. A link is in the description.
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
Cheers Noman I appreciate that and I'm glad that it helped!
I've got a full testing course at garyclarke.tech if you want to take things even further
This tutorial was so peaceful with the birds chirping in the background. Thank you! 😄🙏🏻
Thanks Dawid...it wasn't actually intentional...I was just using the wrong type of mic so all the background noise was picked up!
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!
Glad it was helpful! 👍
Hey Gary, just wanted to let you know that you are getting me through my exams! Thank you so much for that :)
That's awesome Thetisk...best of luck!
Nice Tutorial.
Please make a tutorial series on CQRS, Microservices & DDD and how to implement them in Symfony.
Thanks.
Thanks for the suggestions Abdul..much appreciated. I'll see what I can do!
Clean 'n lean explanation. Congrats !!!
Appreciate it!
Save time in reading docs. Thank you
best explanation for unit test, thanks Gary
Welcome Puneet
Thank you for this awesome Video!
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 :)
Hi Grayaa...it's a pain. The site is hosted on Teachable which only allows me to take PayPal payments if the course price is in USD but I set the course price in euros because that is the currency that most of my followers use. I don't have a solution atm but I'll work on it.
Great. Thanks for your effort.
Welcome!
Great video, nicely explained all the important topics with great examples. Thank you :)
You're very welcome!
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
phpunit-demo is just the name of the folder I created for the project.
All you need to do is create a new folder, open that with your IDE, then install phpunit into that folder.
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;}
because of better output debug feedback (echoing assertion values for example)
Nice tutorial. Thanks because I found out something new.
Glad to hear that!
めっちゃわかりやすい
nice video 💪🏼
Thanks a lot for the useful tutorial
Thanks You Gary
Thanks
Hey, I was wondering if you can mock functions that are not in classes? I can’t find any clues to that topic …
You could try something like this I guess:
bestofphp.com/repo/php-mock-php-mock-php-testing
But I think a better way would be to wrap classes and methods around the functions and use those wrappers instead because they can be mocked.
@@GaryClarkeTech thank you for the quick answer. I got a finished project where I have to write tests. It’s kinda hard to rewrite everything in a class
@@ayayayayaka37 Yes...legacy code is hard to make testable. I've been there many times 😭
Thanks Amazing.
very helpful thank u sir
Happy to help
😈 Amazing 😈 very helpful 😈 thank you 😈
Welcome Barack 👍
Hi may i ask how to test private/protected methods?
You can use Reflection like so:
$class = new ReflectionClass('MyClass');
$method = $class->getMethod($name);
$method->setAccessible(true);
But some consider to be a bit of a hack. 'Best practice' is to test only a class's public interface.
Great content! Can you tell us the theme that you are using? It looks very nice.
Thanks Daniel. It's actually all custom colors which I set myself...I think I just picked one of the built in dark themes as a start point.
I show how to do it in this PHPStorm recording > ua-cam.com/video/nva_En6MPf8/v-deo.html
@@GaryClarkeTech Looks nice. I was just watching that same video as you replied :D Keep up the awesome work :)
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.
Yes but it's in a Symfony tutorial rather than just a plain PHP tutorial (ua-cam.com/video/TOa7JGbRwvk/v-deo.html)
I may demo how to do this in plain PHP in the Beyond The Basics course which I am working on.
@@GaryClarkeTech Awesome, thanks!
That would be a great addition. I am looking for such a thing (haven't managed yet to get it done via fixtures, so now I just import an sql-dump every time I start my tests. Not sure if this the best way to do it.
I get this error unfortunately Undefined type 'PHPUnit\Framework\TestCase'. Any idea what could be wrong ?
I'd need more info. Where are you using it?
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 O:\xampp\htdocs\Jmeter_\Page_login\tests\tests.php on line 7
Have you composer installed it? And is it working for any other test classes?
Hi, Gary! Thank you for such a good demonstration! Your Udemy link isn't working. Please could you update the link? I want to buy this course.
Hi..I'm not sure why it didn't work but I've pasted it in again. Here it is for your convenience:
www.udemy.com/course/the-complete-object-oriented-php-developer-course/?referralCode=F2C53858029119CC9F39
@@GaryClarkeTech Thank you! It works now!
Great! Thx
Welcome Andrew 👍
Could you please tell me which IDE are you using?
PHPStorm
Amazing :D
Thanks Paweł!
I watched this video to understand Mocking and when he get there Unfortunately you started coping and passting and talking faster whitout explaining anyway thx
Thanks Naseem..this is genuinely my favourite kind of feedback because it helps me improve my content (much more useful than a downthumb!). Thanks for watching and I'll cover mocking again some time soon.