PHP Unit Testing - PHPUnit Tutorial - Full PHP 8 Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ค. 2024
  • In this video, you will learn how to install & configure PHPUnit, how to write unit tests, data providers & so on. Note that this is part one of a two-part video and in the next video we'll do more testing along with things like stubs, mocking & test doubles.
    SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
    👍 Smash the like button
    🤝 Subscribe to the channel & turn the notifications on
    💬 Post comments, any feedback is greatly appreciated
    ⭐ Become a Patreon: / programwithgio
    THANK YOU!
    🛠️ TOOLS & SERVICES I USE
    Digital Ocean Hosting - Get 100$ credit - m.do.co/c/38b935ad74e5
    Domains on Namecheap - namecheap.pxf.io/rnRjdQ
    Envato Elements - 1.envato.market/c/2937311/298...
    LESSON 3.1
    Course Outline - github.com/ggelashvili/learnp...
    Course Playlist - • Learn PHP The Right Wa...
    RESOURCES
    Docs - phpunit.readthedocs.io/
    Video about comparing objects - • PHP Variable Storage &...
    Source Repo - github.com/ggelashvili/learnp...
    TABLE OF CONTENTS
    00:00 - Install PHPUnit
    02:22 - PHPUnit Configuration
    03:56 - Writing Unit Tests
    12:08 - Share test setup code (setup method)
    14:33 - Data providers & testing exceptions
    22:11 - External data providers & test class autoloading
    25:14 - More tests
    27:56 - Strict comparison vs loose comparison in tests (assertEquals vs assertSame)
    ** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

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

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

    The contents of this channel are on next level. You videos inspire me alot, more and more to study the core PHP and I get amazed with the beauty of PHP.

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

      I'm really glad to hear that. Thank you 🙏

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

    Your content is very very great, you talk about things no one has mentioned before.
    Keep going Gio

  • @mwaas
    @mwaas ปีที่แล้ว +5

    One of the amazing things about this course is the deep and behind the scenes explanation.
    If programming courses are minerals then this course is a Diamond

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

      Thank you for kind words buddy 🙌

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

    I need to dive into this channel because it seems to have quality PHP related stuff. Really good job!

  • @ilyaslabukarov5959
    @ilyaslabukarov5959 ปีที่แล้ว +6

    Thank you so much!
    You are literally changing the world into a better place!

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

      That's great to hear, thank you 💙

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

    I’m loving this. Writing tests is the major skill I’m trying to build to have all the confidence I crave. Thanks 🙏

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

    You are the best programming teacher i ever had! Thank you so much!!!

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

    The best PHP unit testing lessons out there. Thank you!
    You got a new subscriber.

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

      Welcome aboard, thank you 💙

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

    Great video, great content and good example for writing solid PHP tests.

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

    Awesome video! Very clear and to the point 👌

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

    Gio you are a great teacher. No need to increase the speed on these vids. Well done.

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

    Other issues related to my personal life have forced me to be a lot slower in my advancement through these courses, but I believe they would be sorted and allow me to continue to advance at a better pace. Testing sure is advanced stuff. I'm delighted to be having all these exposures. Thanks a lot Gio, even for the extra help you give personally. God bless

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

      You're welcome. Hope everything is ok 💙

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

      @@ProgramWithGio yeah. I should be back to pace before the end of the week.

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

    You're just so on point. Well done

  • @user-zh2oz9fe4m
    @user-zh2oz9fe4m 11 หลายเดือนก่อน

    Excellent! Thanks for this extremely useful PHP series!

    • @ProgramWithGio
      @ProgramWithGio  11 หลายเดือนก่อน

      You're very welcome

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

    So smoooooooooooth ... Amazing content. Keep going Gio

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

    You're awesome , thanks a lot for this amazing content :)

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

    very impressive great Gio 💕❤️

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

    Thank you so much! 🙌🏻

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

    Thank you so much!

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

    Superb videos!! 💥

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

    Your tutorials are proofs why php is most used language

  • @NeverCodeAlone
    @NeverCodeAlone 9 หลายเดือนก่อน

    Very nice video...thx a lot.

  • @danabooysen4672
    @danabooysen4672 5 หลายเดือนก่อน

    This channel is offering quality material worth your time. Thank you Gio. The only drawback since the content is mostly training related all topics are rushed through and hard to follow along especially when learning something new. The speach is way to fast and it help to playback slower in order to follow. Jumping between different screens quickly is also adding to the problem. But otherwise good material.

    • @ProgramWithGio
      @ProgramWithGio  5 หลายเดือนก่อน +1

      I appreciate the feedback, thank you

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

    Great video, thanks

  • @AMoktar
    @AMoktar 9 หลายเดือนก่อน

    Awesome ❤

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

    great content

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

    Thank you so much

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

    thank you very much

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

    TY so much

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

    great video

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

    Thank you.

  • @AlirezaSalehi-xz3ch
    @AlirezaSalehi-xz3ch 2 ปีที่แล้ว

    thanks a lot

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

    Hi Gio, I'm trying to learn PHP from your guide and so far it's going great, thank you! I tried to include a stylesheet and it doesn't seem to work though. I found that some people fixed it by adding "include /etc/nginx/mime.types;" into the nginx.conf location part, but that doesn't solve it for me. Any idea how this could be fixed? Thank you again!

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

      Hey, how are you including the stylesheets? DM me on Twitter with screenshot & I'll help you troubleshoot it

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

    What software do you suggest to improve my typing speed? Thank you for the video

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

      I haven't used any software, just code & practice 🙂

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

    Thank you for making this video!! I'm currently trying to do this and whenever I "extends TestCase", it gives me this error "Undefined type 'PHPUnit\Framework\TestCase'.". Are you able to tell me what it is wrong?

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

      Have you set up autoloading properly in composer.json? DM me on Twitter and send me a screenshot of your composer.json and the test class and I can take a look.

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

    Hello! I have a question. Our code is a mix of procedural and functional. Still, I want to have unit testing for my code. Is it possible to use PHPUnit for testing the functions? All of the examples given in the videos I watched are used for OOP and I don't know if I have to change something for PHPUnit to work.

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

      Hello! You could use PHPUnit to test procedural code. You may need some additional setup within the setup method but it's doable. Depending on what the function is or how complex it is, it might not be that hard to actually write tests for it. You could use include/requires if you are not using namespaces but I would recommend starting converting to OOP when possible.

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

      @@ProgramWithGio Thanks Gio! I really like to explore and practice OOP but we don't have much time to implement OOP and MVC to our project since we have little knowledge about it. Thanks again!

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

      @@nuvia1484 Makes sense. You're welcome

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

    why do we use
    parent::setUp();
    in the setUp function?
    what the point? I thought we use it if our class extends other parent custom class?

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

      In this specific example yes there is no need because its empty in the parent class. The parent::setUp() call was generated by IDE automatically when I overrode the method. That being said, it does not hurt to call the parent when overriding methods unless you specifically dont want to call it because in some cases it may contain crucial setup procedures needed for testing.

  • @RichardBlezer
    @RichardBlezer 2 หลายเดือนก่อน

    There is a deprecation waring for annotations /** @test */ . In the future (php unit 12) php attributes should be used. These look like this: #[test]

  • @jordanbicanic9343
    @jordanbicanic9343 7 หลายเดือนก่อน

    I noticed that you run compose to install phpunit directly in docker image. Is that necessary? I have composer installed globally

    • @ProgramWithGio
      @ProgramWithGio  7 หลายเดือนก่อน

      Depends on your setup, in some cases you may not need it but I prefer to have it available in container

  • @fpl_god
    @fpl_god 10 หลายเดือนก่อน

    PHP Storm seems better. Which good IDE i can use for PHP for free?

    • @ProgramWithGio
      @ProgramWithGio  10 หลายเดือนก่อน

      I hear vscode is good, not a full fledged IDE but pretty good for free with plugins

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

    Hey Gio, I've got a weird problem. After installing phpunit with composer and building the app I do get the PHPUnit folder with the files within the vendor directory, but there is an issue with vendor/bin. The explorer in VS Code doesn't see any phpunit files in there, and when I manually go there using the file explorer I see two empty files without extensions. They seem to be broken because I cannot even open them from there. Reinstalling phpunit with composer doesn't change anything. Do you reckon what could be the issue?

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

      Hello 👋. That is strange, have you tried deleting vendors directory and running composer install after?

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

      Bro mine is same

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

      There is no extension but the file works and opens juat fine

  • @Armando-px8hi
    @Armando-px8hi 11 หลายเดือนก่อน

    Gio I have some problems bro, so after downloading the phpunit in the vendor folder it creates only sebastian folder and nothing else. What can be the problem?

    • @Armando-px8hi
      @Armando-px8hi 11 หลายเดือนก่อน

      I just solved it GIO, in xampp I had the extension=zip in comments after uncommenting it, it helped. Thanks!

    • @ProgramWithGio
      @ProgramWithGio  11 หลายเดือนก่อน +1

      Awesome, glad you got it working, good job

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

    For anyone that may face a hurdle with class dependencies not being picked up properly when you run phpunit, make sure you include the autoload object within your composer, which Gio talked about in this video: th-cam.com/video/rqzYdHdyMH0/w-d-xo.html. I had skipped that video and jumped straight into this one, and couldn't figure out why my classes weren't able to be found when running tests.

  • @user-mo3cw6go7c
    @user-mo3cw6go7c ปีที่แล้ว

    ❤❤❤❤

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

    what operating system you use?

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

      For recording windows, otherwise linux

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

      @@ProgramWithGio what linux distro is your favorite?

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

      I've been using Ubuntu

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

    if i dont named test functions beginning with test, phpunit dont find it.

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

      You can add @test annotation to it and then it will work

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

      @@ProgramWithGio thanks, now it's working, I had capitalized the annotation first letter.

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

    Can i get this sourcecode ?

  • @carnaqe1154
    @carnaqe1154 8 หลายเดือนก่อน

    i personally prefer TDD

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

    Let's see, make a site and see

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

      umm, see what?

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

      @@ProgramWithGio blog site creation with php

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

      @@kunduz2652 we are not building that in this series.

  • @omaryahia
    @omaryahia 9 หลายเดือนก่อน

    this is a little condensed for me 😐
    I need to break it down slowly
    multiple things are happening and new definitions are presented

    • @ProgramWithGio
      @ProgramWithGio  9 หลายเดือนก่อน +1

      Yup, third section is more challenging for sure, so take your time

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

    Really great content! But in my opinion, very difficult to listen to. The whole video series follows a melancholy tone of reading the text, without a dot or comma, as if everything was read in one breath, which makes it difficult for me as a listener to follow your video tutorials. If you use audio editing programs where you eject parts without voice, to reduce the length of the recording, then you get a robotic audio recording. Maybe my English is not that good, but that is my honest opinion and constructive suggestion to change for the next tutorials.

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

      Thank you for feedback. English isn't my native language so that combined with me speaking fast can be a factor. Also yes I've done wrong audio editing on some videos so that is something I'm gonna get better at 👍. That being said though I don't think "entire series" are like that, just few videos in my opinion. Changing playback speed on TH-cam might help a little bit.

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

      @@ProgramWithGio Thank you so much!!! 👍

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

    Gio your tutorials are amazing. Tiny request, is there away to rename them with numbers? I am struggling to find the videos when I need them immediately. Please try. Great work. I love them.

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

      Thank you. Check the description of the video, there is a link to the outline repo which lists all the videos in order with their numbers, titles & links. Hope that helps

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

      @@ProgramWithGio ❤

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

    In my testing (timestamp 23:44), PHPUnit requires the "routeNotFoundCases" method to be static. Is it because i am using PHP 8.1.12?

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

      Did you add @dataProvider routeNotFoundCases to your test method? github.com/ggelashvili/learnphptherightway-project/blob/3.1/tests/Unit/RouterTest.php check this out and compare to your version

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

      @@ProgramWithGio I checked out the code and mine are the same. This is the message i get "Data Provider method \Tests\DataProviders\RouterDataProvider::routeNotFoundCases() is not static"

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

      @@truthteachers can you send me screenshot of your entire class? Can send it on Twitter DM

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

    Bro, for vscode in Windows 10, the command line for initiating phpunit is "php phpunit --version".

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

      Depends how its installed, maybe on your side its installed globally & the executable is part of the system's PATH variable. Or maybe its just an alias to `vendor/bin/phpunit`.

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

      @@ProgramWithGio Its ok. We have lots of problems with TH-cam courses. Most trainers use either the Mac or Linux server and we use XAMPP on windows which works well with VPS servers running CPanel. We try and figure it out or give up on the course and move on. Hehehe..

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

      @@truthteachers XAMPP shouldn't be used in production to be honest. And the OS shouldn't really matter, you can use WSL in Windows and have Linux subsystem. I'm not sure I understand what the issue is with TH-cam courses or this specific course. I use Windows in the series with WSL but we use Docker instead of XAMPP, XAMPP we used in 1st section