PHP Testing Tutorial: Test Doubles - PHPUnit Mocks and Stubs

  Рет қаралды 12,651

Gary Clarke

Gary Clarke

Күн бұрын

Пікірлер: 36
@anasselmoussaoui
@anasselmoussaoui 2 жыл бұрын
This is the best video tutorial on the internet talking about mocks in PHP, just amazing. Thank you.
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
You're welcome. I'm glad you liked it!
@atuzon1986
@atuzon1986 Жыл бұрын
Agree with that
@sofascialistadankulamegado1781
@sofascialistadankulamegado1781 2 жыл бұрын
I have adhd and have trouble with getting comfortable with tutorial styles and formats. Your video here is just bliss to me. Thank you thank you! Please don't stop making videos!
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
You're welcome. I'm glad that you enjoy my delivery!
@PaulKeeWong
@PaulKeeWong 2 жыл бұрын
You explain the Mock in unittest that very easy understanding, you have reproduced difference use cases are very important to understand!! Thank you so much!
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
Welcome! Glad it was helpful!
@wpwilds
@wpwilds Жыл бұрын
this is a very informative video, please don't stop making videos about php because your way of explaining is very good, god bless you
@GaryClarkeTech
@GaryClarkeTech Жыл бұрын
Thanks Archaf..I appreciate the kind words. More to come soon!
@micasntna
@micasntna 2 жыл бұрын
This is actually an amazing subject that I’m currently doing
@NeverCodeAlone
@NeverCodeAlone 2 жыл бұрын
Yes I also trz my best on it and hope that will work
@douglasfernando3845
@douglasfernando3845 Жыл бұрын
Successfully favorited video.
@obadaalzidi6452
@obadaalzidi6452 7 ай бұрын
Thanks for this great video. So basically when we type hint the return type of the method that we're testing, and we call it on the mocked object we'll get null casted to that type.
@GaryClarkeTech
@GaryClarkeTech 7 ай бұрын
Exactly that
@samhk2222
@samhk2222 2 жыл бұрын
i want to hit the like button for every test passed. Thanks, the best tutorial available on this subject.
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
Cheers Samuel..I really appreciate it. Hope you manage to use it in your projects!
@juanmadelaflor6406
@juanmadelaflor6406 2 жыл бұрын
Ty Gary!!
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
Welcome 👍
@NeverCodeAlone
@NeverCodeAlone Жыл бұрын
Thx a lot for your work here.
@GaryClarkeTech
@GaryClarkeTech Жыл бұрын
My pleasure!
@МухаметджинТимур
@МухаметджинТимур 2 жыл бұрын
Thanks for video. I have one question: how can i test the private or protected methods of class which return void?
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
There are a couple of ways... 1) Don't test them in isolation...only test the public API of the class 2) Use Reflection to make the method accessible
@МухаметджинТимур
@МухаметджинТимур 2 жыл бұрын
@@GaryClarkeTech thanks!!!
@NeverCodeAlone
@NeverCodeAlone 2 жыл бұрын
Makes this sense?
@parijke
@parijke 2 жыл бұрын
Nice Gary
@wisamalkhatib4020
@wisamalkhatib4020 Жыл бұрын
Hello would you please explain how to mock protect method and return specific value
@GaryClarkeTech
@GaryClarkeTech Жыл бұрын
You can use Reflection to make methods public on the reflected object..BUT...I don't recommend doing that and recommend that you just test your public API. I cover this in the full course.
@wisamalkhatib4020
@wisamalkhatib4020 Жыл бұрын
@@GaryClarkeTech Hello Thank you for your quick reply in Reflection i get the method and set as pupblic method what should i do after that ? how can i say return true because this protect method calle an api to return bool value
@qkenkenu
@qkenkenu 2 жыл бұрын
What you do @Gary Clarke - is defenatly amazing, I'm watching carefully tutorials where the key feature is to make "TESTS", and have no idea what the test are really needed for? Maded to check, is sometching that we anyway overriding each time will bring proper value? I dont know, are test are bringed to life just because to keep programers at work ???
@NoahNobody
@NoahNobody 2 жыл бұрын
We have a PDO class at work that takes care of creating a PDO db instance. Is it possible to mock that?
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
Yeah..if you own it, I don't see why not. It won't work if it uses a static factory method to do this though...you can only stub instance methods.
@NeverCodeAlone
@NeverCodeAlone 2 жыл бұрын
Very nice video thx a lot
@markwilkinson276
@markwilkinson276 Жыл бұрын
I have a trait which is used for handling HTTP requests. Is it possible to mock and test a trait? Really like your video and have been able to apply it so far for other areas of my app, but now I've hit a wall where I'm unsure how to handle traits. It's worth noting that I have a get() method which calls a protected makeRequest() method inside it - is it possible to test nested method calls? Again, can't think how this would work
@GaryClarkeTech
@GaryClarkeTech Жыл бұрын
Yes..you can stub all of the public, non-static methods of your class, even if you are getting them from traits. Testing a nested protected method will require a bit of imagination...also consider refactoring for testability. Lots of that kinda stuff in the full course!
@lmartyn
@lmartyn 2 жыл бұрын
This is great. I know and use it now, but wish I had known sooner
@GaryClarkeTech
@GaryClarkeTech 2 жыл бұрын
Cheers Łukasz..bookmark it, it will come in handy as a reference 👍
PHP Test Doubles - Fakes, Stubs, and Mocks
50:53
Gary Clarke
Рет қаралды 4,1 М.
8 Things You'll ❤️ About PHP 8
14:26
Gary Clarke
Рет қаралды 7 М.
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 6 МЛН
I Turned My Mom into Anxiety Mode! 😆💥 #prank #familyfun #funny
00:32
Каха и лужа  #непосредственнокаха
00:15
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 79 МЛН
Unit Tests and Test Doubles like Mocks, Stubs & Fakes
17:32
Cognitive Programmer
Рет қаралды 136 М.
PHP Attributes 50 Minute Tutorial
50:12
Gary Clarke
Рет қаралды 10 М.
When To Unit, E2E, And Integration Test
14:58
ThePrimeTime
Рет қаралды 101 М.
Professional Python Testing with Mocks
21:19
NeuralNine
Рет қаралды 59 М.
Intro to Python Mocks | Python tutorial
18:42
Red Eyed Coder Club
Рет қаралды 87 М.
Pytest Tutorial - How to Test Python Code
1:28:39
freeCodeCamp.org
Рет қаралды 213 М.
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 6 МЛН