PHPUnit Tutorial Part 2 - Mocking - Full PHP 8 Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น • 124

  • @giobongio
    @giobongio 2 ปีที่แล้ว +13

    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 ปีที่แล้ว +1

    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

  • @MansoorKhan-ns2bt
    @MansoorKhan-ns2bt 3 ปีที่แล้ว +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 ปีที่แล้ว +1

      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.

  • @yuriymiroshnychenko5446
    @yuriymiroshnychenko5446 2 ปีที่แล้ว +1

    The best explanation of Mocking I have seen! Thank you for you videos!

  • @SouravRakshit_srv
    @SouravRakshit_srv 3 ปีที่แล้ว +2

    want more in this testing series. great content 👍

  • @joseph_oluwayomi
    @joseph_oluwayomi 2 ปีที่แล้ว +2

    Thanks for this intro. It will go a long way to helping me understand and write tests better.

  • @johnp6115
    @johnp6115 3 ปีที่แล้ว +3

    Your videos on testing have been a huge help, thanks.

  • @wesammohammed1819
    @wesammohammed1819 3 วันที่ผ่านมา

    Great job ! Thank you form gaza
    شكرا جزيلا لك

  • @longtran12345678
    @longtran12345678 2 ปีที่แล้ว +4

    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 💙

  • @invgreat5608
    @invgreat5608 ปีที่แล้ว +1

    Love your channel!!

  • @walis85300
    @walis85300 2 ปีที่แล้ว

    Thanks for the explanation, it is now clear for me how to mock in PHPUnit!

  • @harshshah8420
    @harshshah8420 3 ปีที่แล้ว +4

    This is what exactly I was looking for. :) I really appreciate it. Life saver!!!

  • @Vitalii-m6r
    @Vitalii-m6r ปีที่แล้ว

    Excellent! Thanks for this extremely useful PHP series!

  • @gracjankubicki7004
    @gracjankubicki7004 3 ปีที่แล้ว +2

    Great job ! I wait for next videos ;D

  • @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.

  • @thisisthelogic
    @thisisthelogic 2 ปีที่แล้ว

    Your content is pure gold!

  • @bijianwu5124
    @bijianwu5124 2 ปีที่แล้ว

    explained in detail and clearly! Thanks for it

  • @ntdash2153
    @ntdash2153 2 ปีที่แล้ว

    the change in voice was noticable XD

  • @parijke
    @parijke 3 ปีที่แล้ว +3

    Awesome!

  • @n8finch
    @n8finch ปีที่แล้ว

    Awesome, super clear, better than the PHPUnit docs! 😂 Thank you!

  • @WhiteSiroi
    @WhiteSiroi 2 ปีที่แล้ว

    so helpful, thank you Gio

  • @amarjanovic989
    @amarjanovic989 3 ปีที่แล้ว +1

    Thank you very much for this.

  • @windsurf17
    @windsurf17 2 ปีที่แล้ว

    Fantastic!!!

  • @aruppaul1468
    @aruppaul1468 3 ปีที่แล้ว +3

    thanks bro

  • @federicobau8651
    @federicobau8651 2 ปีที่แล้ว

    great video for PHP unit

  • @ClawHammer23
    @ClawHammer23 3 ปีที่แล้ว +1

    Great video.....thanks so much

  • @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  ปีที่แล้ว +1

      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

  • @shahrokhmoghimi4230
    @shahrokhmoghimi4230 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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  ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

      ​@@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 :)

  • @wotizit
    @wotizit 3 ปีที่แล้ว +1

    Awesome

  • @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 หลายเดือนก่อน +1

      Its in the repository source code (link in description). Simply copy it & create it on your end

  • @memack101
    @memack101 2 ปีที่แล้ว

    Thank you.

  • @donmikele07
    @donmikele07 2 ปีที่แล้ว +3

    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 ปีที่แล้ว +3

      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 ปีที่แล้ว +1

      I agree. I really agree. No rambling. Straight to the point, understandable and packed.

  • @rushko75
    @rushko75 ปีที่แล้ว

    Thank you

  • @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  ปีที่แล้ว +1

      @@SaiyanJin85 yup. Sometimes simple dummy class is all that's needed

  • @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.

  • @benderbg
    @benderbg 4 หลายเดือนก่อน

    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!

  • @beticohernandez9536
    @beticohernandez9536 3 ปีที่แล้ว +2

    Hi there.
    Will you make a project with php?

    • @ProgramWithGio
      @ProgramWithGio  3 ปีที่แล้ว +1

      Yes towards the end of the series

  • @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 ปีที่แล้ว +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.

  • @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")?

  • @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?

  • @johongirrahimov2343
    @johongirrahimov2343 3 ปีที่แล้ว +1

    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 👍

  • @bakosyy
    @bakosyy ปีที่แล้ว

    So, if we write tests after creating business logic, is it behavior driven development or what?

    • @ProgramWithGio
      @ProgramWithGio  ปีที่แล้ว +1

      dont know if there is a term for that but I dont think its BDD

  • @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

  • @DigitaSkills101
    @DigitaSkills101 2 ปีที่แล้ว

    How many frameworks and libraries do you know about

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +3

      I haven't counted it & don't plan to count it :). I learn things as I need them.

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@adrianosilveira4429 Awesome, glad it worked out. Thank you for your support

  • @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.

  • @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 ปีที่แล้ว +1

      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 🤞

  • @omaryahia
    @omaryahia ปีที่แล้ว

    thanks ^_^

  • @manzurahammed7051
    @manzurahammed7051 2 ปีที่แล้ว

    Facing problems when trying to call the same mock method with a different arguments

    • @ProgramWithGio
      @ProgramWithGio  2 ปีที่แล้ว +1

      What problems are you facing? Feel free to DM me on Twitter & I'll help troubleshoot it

  • @samuelaniogbu5089
    @samuelaniogbu5089 ปีที่แล้ว

    Gio is php documentation simplified

  • @truthteachers
    @truthteachers ปีที่แล้ว +1

    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 หลายเดือนก่อน +1

      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