PHP Unit Testing - PHPUnit Tutorial - Full PHP 8 Tutorial

  Рет қаралды 61,218

Program With Gio

Program With Gio

Күн бұрын

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.

Пікірлер: 121
@AnonymousDeveloper1
@AnonymousDeveloper1 Жыл бұрын
I need to dive into this channel because it seems to have quality PHP related stuff. Really good job!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 💙
@chrisodillman3355
@chrisodillman3355 Жыл бұрын
You are the best programming teacher i ever had! Thank you so much!!!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙌
@ahmedamshir3925
@ahmedamshir3925 2 жыл бұрын
Your content is very very great, you talk about things no one has mentioned before. Keep going Gio
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 🙏
@ilyaslabukarov5959
@ilyaslabukarov5959 Жыл бұрын
Thank you so much! You are literally changing the world into a better place!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
That's great to hear, thank you 💙
@josephajibodu2377
@josephajibodu2377 Жыл бұрын
I’m loving this. Writing tests is the major skill I’m trying to build to have all the confidence I crave. Thanks 🙏
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You got this! 💙
@sadhakbj
@sadhakbj 2 жыл бұрын
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 жыл бұрын
I'm really glad to hear that. Thank you 🙏
@hassan_codes
@hassan_codes Жыл бұрын
The best PHP unit testing lessons out there. Thank you! You got a new subscriber.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Welcome aboard, thank you 💙
@mwaas
@mwaas Жыл бұрын
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 Жыл бұрын
Thank you for kind words buddy 🙌
@federicobau8651
@federicobau8651 2 жыл бұрын
Great video, great content and good example for writing solid PHP tests.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 💙
@RandallNewman
@RandallNewman Жыл бұрын
Gio you are a great teacher. No need to increase the speed on these vids. Well done.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙌
@DanFletcher90
@DanFletcher90 2 жыл бұрын
Awesome video! Very clear and to the point 👌
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you Dan
@megamindsetsolutions7569
@megamindsetsolutions7569 2 жыл бұрын
You're just so on point. Well done
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 🙌
@user-zh2oz9fe4m
@user-zh2oz9fe4m 8 ай бұрын
Excellent! Thanks for this extremely useful PHP series!
@ProgramWithGio
@ProgramWithGio 8 ай бұрын
You're very welcome
@manto7
@manto7 2 жыл бұрын
So smoooooooooooth ... Amazing content. Keep going Gio
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 💙
@AMoktar
@AMoktar 7 ай бұрын
Awesome ❤
@ProgramWithGio
@ProgramWithGio 6 ай бұрын
Thanks 💙
@Zubbee
@Zubbee Жыл бұрын
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 Жыл бұрын
You're welcome. Hope everything is ok 💙
@Zubbee
@Zubbee Жыл бұрын
@@ProgramWithGio yeah. I should be back to pace before the end of the week.
@mahmoudibrahim9803
@mahmoudibrahim9803 2 жыл бұрын
You're awesome , thanks a lot for this amazing content :)
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 🙌
@dawid_dahl
@dawid_dahl 2 жыл бұрын
Thank you so much! 🙌🏻
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome
@abdallakaram5376
@abdallakaram5376 2 жыл бұрын
very impressive great Gio 💕❤️
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you
@DigitaSkills101
@DigitaSkills101 Жыл бұрын
Your tutorials are proofs why php is most used language
@ProgramWithGio
@ProgramWithGio Жыл бұрын
💙💙
@issaissifou3579
@issaissifou3579 Жыл бұрын
Thank you so much!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@ClawHammer23
@ClawHammer23 2 жыл бұрын
Great video, thanks
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you
@ClawHammer23
@ClawHammer23 2 жыл бұрын
@@ProgramWithGio No, thank you sir
@WhiteSiroi
@WhiteSiroi Жыл бұрын
thank you very much
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@tamnguyentat5639
@tamnguyentat5639 Жыл бұрын
TY so much
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@danabooysen4672
@danabooysen4672 2 ай бұрын
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 2 ай бұрын
I appreciate the feedback, thank you
@NeverCodeAlone
@NeverCodeAlone 6 ай бұрын
Very nice video...thx a lot.
@ProgramWithGio
@ProgramWithGio 6 ай бұрын
Thank you too!
@aruppaul1468
@aruppaul1468 2 жыл бұрын
great content
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thanks 🙌
@memack101
@memack101 Жыл бұрын
Thank you.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
💙
@marlonlima3370
@marlonlima3370 2 жыл бұрын
great video
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you
@AlirezaSalehi-xz3ch
@AlirezaSalehi-xz3ch 2 жыл бұрын
thanks a lot
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome 💙
@sushiiguess7403
@sushiiguess7403 Жыл бұрын
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 Жыл бұрын
Hey, how are you including the stylesheets? DM me on Twitter with screenshot & I'll help you troubleshoot it
@g7k993
@g7k993 2 жыл бұрын
What software do you suggest to improve my typing speed? Thank you for the video
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
I haven't used any software, just code & practice 🙂
@dietrichmccray795
@dietrichmccray795 2 жыл бұрын
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.
@keemkorn
@keemkorn 11 ай бұрын
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: kzbin.info/www/bejne/qKLdipd-md6AfpI. 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.
@Armando-px8hi
@Armando-px8hi 8 ай бұрын
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 8 ай бұрын
I just solved it GIO, in xampp I had the extension=zip in comments after uncommenting it, it helped. Thanks!
@ProgramWithGio
@ProgramWithGio 8 ай бұрын
Awesome, glad you got it working, good job
@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 жыл бұрын
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 жыл бұрын
@@nuvia1484 Makes sense. You're welcome
@vuejs1
@vuejs1 11 ай бұрын
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 11 ай бұрын
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.
@jordanbicanic9343
@jordanbicanic9343 4 ай бұрын
I noticed that you run compose to install phpunit directly in docker image. Is that necessary? I have composer installed globally
@ProgramWithGio
@ProgramWithGio 4 ай бұрын
Depends on your setup, in some cases you may not need it but I prefer to have it available in container
@user-mo3cw6go7c
@user-mo3cw6go7c Жыл бұрын
❤❤❤❤
@ProgramWithGio
@ProgramWithGio Жыл бұрын
💙💙
@fpl_god
@fpl_god 7 ай бұрын
PHP Storm seems better. Which good IDE i can use for PHP for free?
@ProgramWithGio
@ProgramWithGio 7 ай бұрын
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 Жыл бұрын
Bro mine is same
@DigitaSkills101
@DigitaSkills101 Жыл бұрын
There is no extension but the file works and opens juat fine
@louissardarescu6937
@louissardarescu6937 2 жыл бұрын
what operating system you use?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
For recording windows, otherwise linux
@louissardarescu6937
@louissardarescu6937 2 жыл бұрын
@@ProgramWithGio what linux distro is your favorite?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
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 жыл бұрын
@@ProgramWithGio thanks, now it's working, I had capitalized the annotation first letter.
@tamnguyentat5639
@tamnguyentat5639 Жыл бұрын
Can i get this sourcecode ?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Check description of the video
@carnaqe1154
@carnaqe1154 5 ай бұрын
i personally prefer TDD
@ProgramWithGio
@ProgramWithGio 5 ай бұрын
That's good 👍
@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 6 ай бұрын
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 6 ай бұрын
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 жыл бұрын
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 KZbin might help a little bit.
@tanjakahlo5255
@tanjakahlo5255 2 жыл бұрын
@@ProgramWithGio Thank you so much!!! 👍
@chooticharika
@chooticharika Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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 KZbin 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 Жыл бұрын
@@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 KZbin 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
@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
PHPUnit Tutorial Part 2 - Mocking - Full PHP 8 Tutorial
16:21
Program With Gio
Рет қаралды 29 М.
PHP Testing Tutorial: Test Doubles - PHPUnit Mocks and Stubs
51:15
Final muy inesperado 😨
01:00
Juan De Dios Pantoja
Рет қаралды 52 МЛН
Nonomen funny video😂😂😂 #magic
00:27
Nonomen ノノメン
Рет қаралды 15 МЛН
Ages 1 - 100 Decide Who Wins $250,000
40:02
MrBeast
Рет қаралды 121 МЛН
Test-Driven Development // Fun TDD Introduction with JavaScript
12:55
Testing PHP - Up and running with PHPUnit
30:42
Gary Clarke
Рет қаралды 49 М.
5 Types of Testing Software Every Developer Needs to Know!
6:24
PHP Test Doubles - Fakes, Stubs, and Mocks
50:53
Gary Clarke
Рет қаралды 3,4 М.
Big Tech AI Is A Lie
16:56
Tina Huang
Рет қаралды 44 М.
The Rust Survival Guide
12:34
Let's Get Rusty
Рет қаралды 120 М.
Final muy inesperado 😨
01:00
Juan De Dios Pantoja
Рет қаралды 52 МЛН