Тёмный

PHP Testing Tutorial: Test Doubles - PHPUnit Mocks and Stubs 

Gary Clarke
Подписаться 17 тыс.
Просмотров 13 тыс.
50% 1

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 36   
@anasselmoussaoui
@anasselmoussaoui Год назад
This is the best video tutorial on the internet talking about mocks in PHP, just amazing. Thank you.
@GaryClarkeTech
@GaryClarkeTech Год назад
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!
@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
@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!
@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!
@NeverCodeAlone
@NeverCodeAlone 11 месяцев назад
Thx a lot for your work here.
@GaryClarkeTech
@GaryClarkeTech 11 месяцев назад
My pleasure!
@douglasfernando3845
@douglasfernando3845 Год назад
Successfully favorited video.
@obadaalzidi6452
@obadaalzidi6452 6 месяцев назад
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 6 месяцев назад
Exactly that
@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 ???
@juanmadelaflor6406
@juanmadelaflor6406 2 года назад
Ty Gary!!
@GaryClarkeTech
@GaryClarkeTech 2 года назад
Welcome 👍
@МухаметджинТимур
@МухаметджинТимур 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?
@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.
@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
@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
Просмотров 4 тыс.
Unit Tests and Test Doubles like Mocks, Stubs & Fakes
17:32
When To Unit, E2E, And Integration Test
14:58
Просмотров 99 тыс.
PHP Unit Testing with PHPUnit Tutorial
55:50
Просмотров 9 тыс.
Thoughts About Unit Testing | Prime Reacts
11:21
Просмотров 227 тыс.