PHPUnit Tutorial Part 2 - Mocking - Full PHP 8 Tutorial

Поділитися
Вставка
  • Опубліковано 16 вер 2024

КОМЕНТАРІ • 121

  • @giobongio
    @giobongio Рік тому +12

    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!

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

  • @johnp6115
    @johnp6115 3 роки тому +3

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

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

  • @janedawg09
    @janedawg09 4 місяці тому

    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 2 роки тому +3

    Great tutorial. Finally, I am able to understand Mocking. Thank you, Gio. Love your content.

    • @MansoorKhan-ns2bt
      @MansoorKhan-ns2bt 2 роки тому

      Could we expect a series on TDD / PHPUnit on an advanced level? Would love to see that.

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +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.

  • @SouravRakshit_srv
    @SouravRakshit_srv 2 роки тому +2

    want more in this testing series. great content 👍

  • @josephajibodu2377
    @josephajibodu2377 2 роки тому +2

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

  • @harshshah8420
    @harshshah8420 2 роки тому +4

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

  • @yuriymiroshnychenko5446
    @yuriymiroshnychenko5446 2 роки тому +1

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

  • @invgreat5608
    @invgreat5608 Рік тому +1

    Love your channel!!

  • @parijke
    @parijke 3 роки тому +3

    Awesome!

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

  • @gracjankubicki7004
    @gracjankubicki7004 3 роки тому +2

    Great job ! I wait for next videos ;D

  • @amarjanovic989
    @amarjanovic989 2 роки тому +1

    Thank you very much for this.

  • @aruppaul1468
    @aruppaul1468 3 роки тому +3

    thanks bro

  • @walis85300
    @walis85300 2 роки тому

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

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

  • @thisisthelogic
    @thisisthelogic 2 роки тому

    Your content is pure gold!

  • @donmikele07
    @donmikele07 2 роки тому +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  Рік тому +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 Рік тому

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

  • @Vitalii-m6r
    @Vitalii-m6r Рік тому

    Excellent! Thanks for this extremely useful PHP series!

  • @bijianwu5124
    @bijianwu5124 Рік тому

    explained in detail and clearly! Thanks for it

  • @wotizit
    @wotizit 2 роки тому +1

    Awesome

  • @benderbg
    @benderbg 20 днів тому

    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!

  • @n8finch
    @n8finch Рік тому

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

  • @ntdash2153
    @ntdash2153 2 роки тому

    the change in voice was noticable XD

  • @windsurf17
    @windsurf17 2 роки тому

    Fantastic!!!

  • @WhiteSiroi
    @WhiteSiroi Рік тому

    so helpful, thank you Gio

  • @ClawHammer23
    @ClawHammer23 3 роки тому +1

    Great video.....thanks so much

  • @federicobau8651
    @federicobau8651 2 роки тому

    great video for PHP unit

  • @SaiyanJin85
    @SaiyanJin85 11 місяців тому

    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  11 місяців тому

      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 11 місяців тому

      @@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  11 місяців тому +1

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

  • @memack101
    @memack101 2 роки тому

    Thank you.

  • @rushko75
    @rushko75 Рік тому

    Thank you

  • @beticohernandez9536
    @beticohernandez9536 2 роки тому +2

    Hi there.
    Will you make a project with php?

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

  • @Darkray201
    @Darkray201 Рік тому

    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  Рік тому

      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 8 місяців тому

    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  7 місяців тому

      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 👍

  • @nicolaeifrim380
    @nicolaeifrim380 8 місяців тому

    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  7 місяців тому

      One of the reasons why I avoid statics is because its harder to write tests for it

    • @nicolaeifrim380
      @nicolaeifrim380 7 місяців тому

      @@ProgramWithGio Yes, I had to refactor the entire code.

  • @redzambala6193
    @redzambala6193 8 місяців тому

    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  8 місяців тому +1

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

  • @bakosyy
    @bakosyy 10 місяців тому

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

    • @ProgramWithGio
      @ProgramWithGio  10 місяців тому +1

      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 роки тому +1

      Because it was mocked, the original function didnt execute, function on mocked class did.

    • @baptistedara8026
      @baptistedara8026 2 роки тому

      @@ProgramWithGio thanks you

  • @omaryahia
    @omaryahia 11 місяців тому

    thanks ^_^

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

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

  • @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 11 місяців тому

    Gio is php documentation simplified

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

  • @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 7 місяців тому

    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  6 місяців тому +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