PHPUnit Tutorial Part 2 - Mocking - Full PHP 8 Tutorial

  Рет қаралды 34,347

Program With Gio

Program With Gio

Күн бұрын

Пікірлер: 124
@giobongio
@giobongio 2 жыл бұрын
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!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you, glad you like it 🙏
@jaWitold
@jaWitold 2 жыл бұрын
Great tutorial, in less than 20 minutes i understood things that at my university i couldn't understand in half a year. Thank You.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
That's awesome, thank you 💙💙
@janedawg09
@janedawg09 7 ай бұрын
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
@ProgramWithGio
@ProgramWithGio 7 ай бұрын
Happy to hear
@johnp6115
@johnp6115 3 жыл бұрын
Your videos on testing have been a huge help, thanks.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Glad to hear that 👍
@joseph_oluwayomi
@joseph_oluwayomi 2 жыл бұрын
Thanks for this intro. It will go a long way to helping me understand and write tests better.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You are welcome
@wesammohammed1819
@wesammohammed1819 23 сағат бұрын
Great job ! Thank you form gaza شكرا جزيلا لك
@MansoorKhan-ns2bt
@MansoorKhan-ns2bt 3 жыл бұрын
Great tutorial. Finally, I am able to understand Mocking. Thank you, Gio. Love your content.
@MansoorKhan-ns2bt
@MansoorKhan-ns2bt 3 жыл бұрын
Could we expect a series on TDD / PHPUnit on an advanced level? Would love to see that.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
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.
@longtran12345678
@longtran12345678 2 жыл бұрын
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.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you, glad it was helpful 💙
@yuriymiroshnychenko5446
@yuriymiroshnychenko5446 2 жыл бұрын
The best explanation of Mocking I have seen! Thank you for you videos!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 🙌
@harshshah8420
@harshshah8420 3 жыл бұрын
This is what exactly I was looking for. :) I really appreciate it. Life saver!!!
@Zubbee
@Zubbee 2 жыл бұрын
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.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Awesome, thank you 💙
@SouravRakshit_srv
@SouravRakshit_srv 3 жыл бұрын
want more in this testing series. great content 👍
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thank you 🙌
@invgreat5608
@invgreat5608 Жыл бұрын
Love your channel!!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you so much!
@walis85300
@walis85300 2 жыл бұрын
Thanks for the explanation, it is now clear for me how to mock in PHPUnit!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Great to hear
@parijke
@parijke 3 жыл бұрын
Awesome!
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thanks
@gracjankubicki7004
@gracjankubicki7004 3 жыл бұрын
Great job ! I wait for next videos ;D
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thank you
@thisisthelogic
@thisisthelogic 2 жыл бұрын
Your content is pure gold!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you
@Vitalii-m6r
@Vitalii-m6r Жыл бұрын
Excellent! Thanks for this extremely useful PHP series!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you
@n8finch
@n8finch Жыл бұрын
Awesome, super clear, better than the PHPUnit docs! 😂 Thank you!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙌
@bijianwu5124
@bijianwu5124 2 жыл бұрын
explained in detail and clearly! Thanks for it
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome 🙌
@ntdash2153
@ntdash2153 2 жыл бұрын
the change in voice was noticable XD
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
🙊🙊
@amarjanovic989
@amarjanovic989 3 жыл бұрын
Thank you very much for this.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
You're welcome 🙌
@WhiteSiroi
@WhiteSiroi 2 жыл бұрын
so helpful, thank you Gio
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Glad to hear, you're welcome
@windsurf17
@windsurf17 2 жыл бұрын
Fantastic!!!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Many thanks!
@wotizit
@wotizit 3 жыл бұрын
Awesome
@federicobau8651
@federicobau8651 2 жыл бұрын
great video for PHP unit
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
💙💙
@aruppaul1468
@aruppaul1468 3 жыл бұрын
thanks bro
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
You're welcome 🙌
@ClawHammer23
@ClawHammer23 3 жыл бұрын
Great video.....thanks so much
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thank you
@benderbg
@benderbg 3 ай бұрын
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!
@ProgramWithGio
@ProgramWithGio 3 ай бұрын
good one :D
@donmikele07
@donmikele07 2 жыл бұрын
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)?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 💙. I don't have any recommendations at the moment. I would say check Laracasts they have a lot of testing related lessons
@AlbertAngmor
@AlbertAngmor 2 жыл бұрын
I agree. I really agree. No rambling. Straight to the point, understandable and packed.
@shahrokhmoghimi4230
@shahrokhmoghimi4230 Жыл бұрын
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 ;)
@shahrokhmoghimi4230
@shahrokhmoghimi4230 Жыл бұрын
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
@ProgramWithGio
@ProgramWithGio Жыл бұрын
@@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.
@shahrokhmoghimi4230
@shahrokhmoghimi4230 Жыл бұрын
​@@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 :)
@memack101
@memack101 2 жыл бұрын
Thank you.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
💙
@SaiyanJin85
@SaiyanJin85 Жыл бұрын
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!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
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
@SaiyanJin85
@SaiyanJin85 Жыл бұрын
@@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
@ProgramWithGio
@ProgramWithGio Жыл бұрын
@@SaiyanJin85 yup. Sometimes simple dummy class is all that's needed
@rushko75
@rushko75 Жыл бұрын
Thank you
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@alexandrbisir3784
@alexandrbisir3784 Жыл бұрын
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!!!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
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
@aerohcss
@aerohcss 2 ай бұрын
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")?
@ProgramWithGio
@ProgramWithGio 2 ай бұрын
Yes pretty much
@redzambala6193
@redzambala6193 11 ай бұрын
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?
@ProgramWithGio
@ProgramWithGio 11 ай бұрын
Its in the repository source code (link in description). Simply copy it & create it on your end
@nicolaeifrim380
@nicolaeifrim380 11 ай бұрын
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)?
@ProgramWithGio
@ProgramWithGio 10 ай бұрын
One of the reasons why I avoid statics is because its harder to write tests for it
@nicolaeifrim380
@nicolaeifrim380 10 ай бұрын
@@ProgramWithGio Yes, I had to refactor the entire code.
@beticohernandez9536
@beticohernandez9536 3 жыл бұрын
Hi there. Will you make a project with php?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Yes towards the end of the series
@johongirrahimov2343
@johongirrahimov2343 3 жыл бұрын
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
@ProgramWithGio 3 жыл бұрын
Hello! You could start learning Laravel even now. Laracasts is great resource
@johongirrahimov2343
@johongirrahimov2343 3 жыл бұрын
@@ProgramWithGio thanx a lot for the answer
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
@@johongirrahimov2343 you're welcome 👍
@Darkray201
@Darkray201 2 жыл бұрын
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
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
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
@Darkray201
@Darkray201 2 жыл бұрын
​@@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.
@carnaqe1154
@carnaqe1154 11 ай бұрын
what is the difference between the customer array placed in as rvalue and other time as lvalue at the end of the video?
@ProgramWithGio
@ProgramWithGio 10 ай бұрын
Not sure what you mean, can you point at timestamps?
@bakosyy
@bakosyy Жыл бұрын
So, if we write tests after creating business logic, is it behavior driven development or what?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
dont know if there is a term for that but I dont think its BDD
@baptistedara8026
@baptistedara8026 2 жыл бұрын
Sir, I don't understand why sleep function didn't work when we call a method on mocked dependency
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Because it was mocked, the original function didnt execute, function on mocked class did.
@baptistedara8026
@baptistedara8026 2 жыл бұрын
@@ProgramWithGio thanks you
@adrianosilveira4429
@adrianosilveira4429 2 жыл бұрын
When I try to use ->expects in a class created from ->createMock it says that it doesn't exists. What should I do?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Can you share screenshot or github link to your code so I can check it out?
@adrianosilveira4429
@adrianosilveira4429 2 жыл бұрын
@@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
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
@@adrianosilveira4429 Awesome, glad it worked out. Thank you for your support
@b4rt1j1
@b4rt1j1 2 жыл бұрын
Hi, may i ask how to test private or protected methods?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Either test the method that calls it or use reflection
@akhileshkumar-iu9uq
@akhileshkumar-iu9uq 3 жыл бұрын
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
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
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
@akhileshkumar-iu9uq
@akhileshkumar-iu9uq 3 жыл бұрын
@@ProgramWithGio I will do that. Thanks for your guidance. I m from India. My target is to get job overseas.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
@@akhileshkumar-iu9uq you're welcome. Good luck 🤞
@DigitaSkills101
@DigitaSkills101 2 жыл бұрын
How many frameworks and libraries do you know about
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
I haven't counted it & don't plan to count it :). I learn things as I need them.
@omaryahia
@omaryahia Жыл бұрын
thanks ^_^
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@TITAN-sv5eg
@TITAN-sv5eg Жыл бұрын
after i test the code with phpunit i should delete the test files? please i want a answer
@ProgramWithGio
@ProgramWithGio Жыл бұрын
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.
@TITAN-sv5eg
@TITAN-sv5eg Жыл бұрын
@@ProgramWithGio Thanks, i have a problem => undefined method 'method' what i do
@ProgramWithGio
@ProgramWithGio Жыл бұрын
@@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.
@manzurahammed7051
@manzurahammed7051 2 жыл бұрын
Facing problems when trying to call the same mock method with a different arguments
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
What problems are you facing? Feel free to DM me on Twitter & I'll help troubleshoot it
@samuelaniogbu5089
@samuelaniogbu5089 Жыл бұрын
Gio is php documentation simplified
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Heh thank you
@truthteachers
@truthteachers Жыл бұрын
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.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
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.
@dev_troy8903
@dev_troy8903 10 ай бұрын
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 🤍
@ProgramWithGio
@ProgramWithGio 10 ай бұрын
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
Dependency Injection & DI Containers - Full PHP 8 Tutorial
6:42
Program With Gio
Рет қаралды 36 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
PHP Testing Tutorial: Test Doubles - PHPUnit Mocks and Stubs
51:15
PHP Unit Testing - PHPUnit Tutorial - Full PHP 8 Tutorial
31:04
Program With Gio
Рет қаралды 72 М.
PHP Test Doubles - Fakes, Stubs, and Mocks
50:53
Gary Clarke
Рет қаралды 4,2 М.
Готовим Middleware в PHP
24:51
loftblog
Рет қаралды 10 М.
Unit Tests and Test Doubles like Mocks, Stubs & Fakes
17:32
Cognitive Programmer
Рет қаралды 137 М.
PHPUnit in Laravel: Simple Example of Why/How to Test
12:11
Laravel Daily
Рет қаралды 67 М.
The ONLY REASON To Unit Test
8:26
Theo - t3․gg
Рет қаралды 86 М.
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН