One of the clearest tutorials I've ever seen about dependency injection and mocking. Thank you guy for the time you dedicated to this series, and go on!
it's a huge help that your tuts are well divided for each topics. I haven't the time to watch all so I watch the ones I needed at the time and it helps a lot since your explanation and examples are well executed too
Thank you Mansoor. Really glad to hear that. I personally don't do TDD so not sure if I would make a series on it. But I might make a separate series on phpunit.
very clear, precise, this video is gold. Thank you very much. This helps me a ton while applying tests to our legacy products. I wish I can like this several thousand times.
Was able to go through this lesson regardless. I'm pressing on. . I'm real glad to have this lesson. I may never have come across this by now if I was still trying to learn PHP the way I was learning before. Thanks alot Gio.
Thank you so much for putting such amazing contents!! I'm new to unit test. so if there is a private dependency function inside public function charge(), how can we mock the private method? Thank you in advance!!!
Ideally, you shouldnt be testing private methods on its own but test the underlying method that calls or depends on that private method. If your private method is too complex and you must have a test for it then you could try with reflection API or extract the private method into a separate class & have test for that class
Thank you Man, I believe your tutorial is the best PHP tutorial I have seen, but I should say It would not be better if you said that static methods cannot be tested ;)
and about solving it, we should refactor static methods to non-static for testing. I think the addition of this topic will make your excellent education more attractive
@@shahrokhmoghimi4230 thank you. I talk about disadvantages of static methods in another lesson where we discuss static. We don't have any static methods in this lesson so not sure what you mean.
@@ProgramWithGio Thank you for your fast feedback, I know and I have almost seen your all of tutorial :), I mean, it would be better that you mention it in this lesson because it possible anyone is reached straight to this lesson (or previous lesson) with search. like me several months ago :)
I am at 5:15 min now trying to run test, I am geting an error: Error: Class "services\SalesTaxService" not found; and indeed - it is mentioned in InvoiceService but does not exist; and what should I do?! I believe it never existed in this course, or am I missing something?
I'm coding for years and I watched a lot of tutorials but I must say this is something very different, very serious, and very experienced. Great job man! BTW: do you have any recommendations for some tutorials with examples for writing more complex tests with Mockery (besides the official documentation for which you've already put the link in the description)?
That's a good one. Just a thought though, I find that creating a dummy class that extends the dependency works better than using a mocking library 1. it's easies since you don't have to learn any extra mocking library 2. it's safer because if for some reason you change the name of a method of the original class in this case from 'charge' to 'pay' for example the test will still pass because of how mocking libraries works. Having a simple dummy class extending the original will force you to update the dummy class too I think Any thoughts on that?? Thanks!
Yea sure, in some cases it can be better & easier. About changing method name it depends how you use mocking, if you are expecting a method call with name charge in your mock it will fail if you change method name to something else and it doesn't get called
@@ProgramWithGio Thanks for your quick reply! Also there is the issue of the readability of the test. For simple mocks it's ok but it can get really messy and unreadable for more complex dependencies
Thank you. What happens if the function we are testing is a static function and is full with calls to other static methods (some within the same class)?
Eminem has a song called Mockingbird and it has an intro that says: " I know sometimes things may not always make sense to you right now" So Eminem was teaching us about mocking before Gio did!
Thank you for this video, Gio! Could you please add timestamp marks like you did in part 1 to split up the video into units of meaning / categories? Thanks :) Another point to consider is to use native PHP 8 attributes instead of PHP Annotations
Thank you. I usually add timestamps to videos where it makes sense if I cover multiple topics. As for attributes I use them in places where it is available. Don't think phpunit supports them yet unless I missed it in the documentation
@@ProgramWithGio Yes, I discovered this also right now. For others wondering: ETA of PHPUNIT 10 is February 2023. With PHPUnit 10 PHP8.1 compatibility will come to us.
Gio, I'm a bit confused about concepts. Am I right that general name for all fake classes are Mock objects that in turn can have fixed output ("to stub") or do output via expectations ("to mock")?
Hi Gio, I've a question. I want to learn Laravel after completing all of these series. What do you think should I learn more PHP after I complete this course or is this enough for learning Laravel?
@@ProgramWithGio hello my friend. Thank you for your answer, it turns out it was a problem with my php plugin in vscode. I've switched to PHP storm and the problem disappeared. Thank you again for the amazing tutorials and your kindness
No you shouldn't remove it, tests are there so that you can test them continuously, especially after making changes or refactoring the method that you are testing.
Hi sir, I have seen your vdos and manage my whole project from procedure php to oops. I have 4 years of experience in this backend web development, should I change this field
Bro, i have some problems. I notice that this video is not the continuation from lesson 3.1 as it contains new classes. I reverted to your repo which contains the course material and found that Services/InvoiceService class is not the same. Please advise.
Hey, yes this is the continuation, the classes might be a bit different because the lesson is different. I added the InvoiceService class specifically for this lesson to learn about mocks.
For the email test, I tried to not specify the with method, and it worked. I think we don't need to test the arguments it's enough that the "send" method is called. what do you think Gio ?? Thanks for the great content 🤍
That's ok. It mainly depends on what exactly you are testing, if all you care about to test if send method is called then its fine, if you want to test with specific arguments then you would write test to handle that as well
One of the clearest tutorials I've ever seen about dependency injection and mocking. Thank you guy for the time you dedicated to this series, and go on!
Thank you, glad you like it 🙏
Great tutorial, in less than 20 minutes i understood things that at my university i couldn't understand in half a year. Thank You.
That's awesome, thank you 💙💙
it's a huge help that your tuts are well divided for each topics. I haven't the time to watch all so I watch the ones I needed at the time and it helps a lot since your explanation and examples are well executed too
Happy to hear
Great tutorial. Finally, I am able to understand Mocking. Thank you, Gio. Love your content.
Could we expect a series on TDD / PHPUnit on an advanced level? Would love to see that.
Thank you Mansoor. Really glad to hear that. I personally don't do TDD so not sure if I would make a series on it. But I might make a separate series on phpunit.
The best explanation of Mocking I have seen! Thank you for you videos!
Thank you 🙌
want more in this testing series. great content 👍
Thank you 🙌
Thanks for this intro. It will go a long way to helping me understand and write tests better.
You are welcome
Your videos on testing have been a huge help, thanks.
Glad to hear that 👍
Great job ! Thank you form gaza
شكرا جزيلا لك
very clear, precise, this video is gold. Thank you very much. This helps me a ton while applying tests to our legacy products. I wish I can like this several thousand times.
Thank you, glad it was helpful 💙
Love your channel!!
Thank you so much!
Thanks for the explanation, it is now clear for me how to mock in PHPUnit!
Great to hear
This is what exactly I was looking for. :) I really appreciate it. Life saver!!!
Excellent! Thanks for this extremely useful PHP series!
Thank you
Great job ! I wait for next videos ;D
Thank you
Was able to go through this lesson regardless. I'm pressing on. . I'm real glad to have this lesson. I may never have come across this by now if I was still trying to learn PHP the way I was learning before. Thanks alot Gio.
Awesome, thank you 💙
Your content is pure gold!
Thank you
explained in detail and clearly! Thanks for it
You're welcome 🙌
the change in voice was noticable XD
🙊🙊
Awesome!
Thanks
Awesome, super clear, better than the PHPUnit docs! 😂 Thank you!
Thank you 🙌
so helpful, thank you Gio
Glad to hear, you're welcome
Thank you very much for this.
You're welcome 🙌
Fantastic!!!
Many thanks!
thanks bro
You're welcome 🙌
great video for PHP unit
💙💙
Great video.....thanks so much
Thank you
Thank you so much for putting such amazing contents!! I'm new to unit test. so if there is a private dependency function inside public function charge(), how can we mock the private method? Thank you in advance!!!
Ideally, you shouldnt be testing private methods on its own but test the underlying method that calls or depends on that private method. If your private method is too complex and you must have a test for it then you could try with reflection API or extract the private method into a separate class & have test for that class
Thank you Man, I believe your tutorial is the best PHP tutorial I have seen, but I should say It would not be better if you said that static methods cannot be tested ;)
and about solving it, we should refactor static methods to non-static for testing. I think the addition of this topic will make your excellent education more attractive
@@shahrokhmoghimi4230 thank you. I talk about disadvantages of static methods in another lesson where we discuss static. We don't have any static methods in this lesson so not sure what you mean.
@@ProgramWithGio Thank you for your fast feedback, I know and I have almost seen your all of tutorial :), I mean, it would be better that you mention it in this lesson because it possible anyone is reached straight to this lesson (or previous lesson) with search. like me several months ago :)
Awesome
I am at 5:15 min now trying to run test, I am geting an error: Error: Class "services\SalesTaxService" not found; and indeed - it is mentioned in InvoiceService but does not exist; and what should I do?! I believe it never existed in this course, or am I missing something?
Its in the repository source code (link in description). Simply copy it & create it on your end
Thank you.
💙
I'm coding for years and I watched a lot of tutorials but I must say this is something very different, very serious, and very experienced. Great job man! BTW: do you have any recommendations for some tutorials with examples for writing more complex tests with Mockery (besides the official documentation for which you've already put the link in the description)?
Thank you 💙. I don't have any recommendations at the moment. I would say check Laracasts they have a lot of testing related lessons
I agree. I really agree. No rambling. Straight to the point, understandable and packed.
Thank you
You're welcome
That's a good one.
Just a thought though, I find that creating a dummy class that extends the dependency works better than using a mocking library
1. it's easies since you don't have to learn any extra mocking library
2. it's safer because if for some reason you change the name of a method of the original class in this case from 'charge' to 'pay' for example the test will still pass because of how mocking libraries works. Having a simple dummy class extending the original will force you to update the dummy class too I think
Any thoughts on that??
Thanks!
Yea sure, in some cases it can be better & easier. About changing method name it depends how you use mocking, if you are expecting a method call with name charge in your mock it will fail if you change method name to something else and it doesn't get called
@@ProgramWithGio Thanks for your quick reply! Also there is the issue of the readability of the test. For simple mocks it's ok but it can get really messy and unreadable for more complex dependencies
@@SaiyanJin85 yup. Sometimes simple dummy class is all that's needed
Thank you. What happens if the function we are testing is a static function and is full with calls to other static methods (some within the same class)?
One of the reasons why I avoid statics is because its harder to write tests for it
@@ProgramWithGio Yes, I had to refactor the entire code.
Eminem has a song called Mockingbird and it has an intro that says: " I know sometimes things may not always make sense to you right now"
So Eminem was teaching us about mocking before Gio did!
good one :D
Hi there.
Will you make a project with php?
Yes towards the end of the series
Thank you for this video, Gio! Could you please add timestamp marks like you did in part 1 to split up the video into units of meaning / categories? Thanks :) Another point to consider is to use native PHP 8 attributes instead of PHP Annotations
Thank you. I usually add timestamps to videos where it makes sense if I cover multiple topics. As for attributes I use them in places where it is available. Don't think phpunit supports them yet unless I missed it in the documentation
@@ProgramWithGio Yes, I discovered this also right now. For others wondering: ETA of PHPUNIT 10 is February 2023. With PHPUnit 10 PHP8.1 compatibility will come to us.
Gio, I'm a bit confused about concepts.
Am I right that general name for all fake classes are Mock objects that in turn can have fixed output ("to stub") or do output via expectations ("to mock")?
Yes pretty much
what is the difference between the customer array placed in as rvalue and other time as lvalue at the end of the video?
Not sure what you mean, can you point at timestamps?
Hi Gio, I've a question. I want to learn Laravel after completing all of these series. What do you think should I learn more PHP after I complete this course or is this enough for learning Laravel?
Hello! You could start learning Laravel even now. Laracasts is great resource
@@ProgramWithGio thanx a lot for the answer
@@johongirrahimov2343 you're welcome 👍
So, if we write tests after creating business logic, is it behavior driven development or what?
dont know if there is a term for that but I dont think its BDD
Hi, may i ask how to test private or protected methods?
Either test the method that calls it or use reflection
How many frameworks and libraries do you know about
I haven't counted it & don't plan to count it :). I learn things as I need them.
Sir, I don't understand why sleep function didn't work when we call a method on mocked dependency
Because it was mocked, the original function didnt execute, function on mocked class did.
@@ProgramWithGio thanks you
When I try to use ->expects in a class created from ->createMock it says that it doesn't exists. What should I do?
Can you share screenshot or github link to your code so I can check it out?
@@ProgramWithGio hello my friend. Thank you for your answer, it turns out it was a problem with my php plugin in vscode. I've switched to PHP storm and the problem disappeared. Thank you again for the amazing tutorials and your kindness
@@adrianosilveira4429 Awesome, glad it worked out. Thank you for your support
after i test the code with phpunit i should delete the test files? please i want a answer
No you shouldn't remove it, tests are there so that you can test them continuously, especially after making changes or refactoring the method that you are testing.
@@ProgramWithGio Thanks, i have a problem => undefined method 'method' what i do
@@TITAN-sv5eg can't really help you without seeing the code, put it up in GitHub and share the link to the repo and I can check it out.
Hi sir, I have seen your vdos and manage my whole project from procedure php to oops. I have 4 years of experience in this backend web development, should I change this field
Hello! If you enjoy what you do then I would say no. PHP is on demand and will be on demand for as long as it runs most of the web
@@ProgramWithGio I will do that. Thanks for your guidance. I m from India. My target is to get job overseas.
@@akhileshkumar-iu9uq you're welcome. Good luck 🤞
thanks ^_^
You're welcome
Facing problems when trying to call the same mock method with a different arguments
What problems are you facing? Feel free to DM me on Twitter & I'll help troubleshoot it
Gio is php documentation simplified
Heh thank you
Bro, i have some problems. I notice that this video is not the continuation from lesson 3.1 as it contains new classes. I reverted to your repo which contains the course material and found that Services/InvoiceService class is not the same. Please advise.
Hey, yes this is the continuation, the classes might be a bit different because the lesson is different. I added the InvoiceService class specifically for this lesson to learn about mocks.
For the email test, I tried to not specify the with method, and it worked. I think we don't need to test the arguments it's enough that the "send" method is called. what do you think Gio ??
Thanks for the great content 🤍
That's ok. It mainly depends on what exactly you are testing, if all you care about to test if send method is called then its fine, if you want to test with specific arguments then you would write test to handle that as well