Testing PHP - Up and running with PHPUnit

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

КОМЕНТАРІ • 76

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

    This is GOLD.
    BTW:
    If you have received such an error:
    Class 'ExampleAssertionsTest' could not be found in '/home/$USER/projects/phpunit-demo/tests/ExampleAssertionsTest.php'.
    You need to perform two steps:
    1) Make sure your composer.json looks like that:
    {
    "require-dev": {
    "phpunit/phpunit": "^9.5"
    },
    "autoload-dev": {
    "psr-4": {
    "": "tests/"
    }
    }
    }
    2) composer dump-autoload
    Enjoy.

  • @KingDynamiteHD
    @KingDynamiteHD 2 роки тому +5

    This is a great video, I'm doing a software developer apprenticeship, and this video saved me with learning unit testing, thank you sir!

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

      Great stuff...also check out the full course. A link is in the description.

  • @nomanhanafi6461
    @nomanhanafi6461 Рік тому +3

    This is great Gary, I am happy how you gradually incorporated things, many people start with a lot of bloatwares and make things harder for beginners to understand

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

      Cheers Noman I appreciate that and I'm glad that it helped!
      I've got a full testing course at garyclarke.tech if you want to take things even further

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

    This tutorial was so peaceful with the birds chirping in the background. Thank you! 😄🙏🏻

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

      Thanks Dawid...it wasn't actually intentional...I was just using the wrong type of mic so all the background noise was picked up!

  • @ovuokeaghwotu2389
    @ovuokeaghwotu2389 3 роки тому +6

    I wish I could like this video multiple times as this is an excellent demonstration and introduction to TDD in PHP. Your explanation is clear and easy to grasp and you also explained the WHYs of every step.
    Thank you for making this available to us!

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

    Hey Gary, just wanted to let you know that you are getting me through my exams! Thank you so much for that :)

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

    Nice Tutorial.
    Please make a tutorial series on CQRS, Microservices & DDD and how to implement them in Symfony.
    Thanks.

    • @GaryClarkeTech
      @GaryClarkeTech  3 роки тому

      Thanks for the suggestions Abdul..much appreciated. I'll see what I can do!

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

    Clean 'n lean explanation. Congrats !!!

  • @authorspirit
    @authorspirit 3 роки тому

    Save time in reading docs. Thank you

  • @puneetchauhan6178
    @puneetchauhan6178 3 роки тому

    best explanation for unit test, thanks Gary

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

    Thank you for this awesome Video!

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

    Hello Gray, i love your course, and i want to but the full course at your website,
    but the problem is that i only have paypal as a payment method, is there a solution please? thanks :)

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

      Hi Grayaa...it's a pain. The site is hosted on Teachable which only allows me to take PayPal payments if the course price is in USD but I set the course price in euros because that is the currency that most of my followers use. I don't have a solution atm but I'll work on it.

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

    Great. Thanks for your effort.

  • @AkanshaSaxena
    @AkanshaSaxena 3 роки тому

    Great video, nicely explained all the important topics with great examples. Thank you :)

  • @ИванОтрубов
    @ИванОтрубов 3 роки тому +1

    Hi Gary! Very good explanation but could you explain where i should to do that? I am trying to open new project in my inteleji IDEA and i set phpunit library thru composer there.
    But i can not figure it out where how you did it and why you have phpunit-demo package from the beginning

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

      phpunit-demo is just the name of the folder I created for the project.
      All you need to do is create a new folder, open that with your IDE, then install phpunit into that folder.

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

    Instead of having to learn all those assertions (AssertEquals, AssertSame, AssertIsFloat, assertGreaterThan, assertLessThan, etc), why doesn't phpUnit just use PHP logic? Inside of each testCase method, you should be able to do your own logic and return true or false. Like this:
    if ($string1 == $string2) {return true;}

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

      because of better output debug feedback (echoing assertion values for example)

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

    Nice tutorial. Thanks because I found out something new.

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

    めっちゃわかりやすい

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

    nice video 💪🏼

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

    Thanks a lot for the useful tutorial

  • @secretsayanTravels
    @secretsayanTravels 3 роки тому

    Thanks You Gary

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

    Thanks

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

    Hey, I was wondering if you can mock functions that are not in classes? I can’t find any clues to that topic …

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

      You could try something like this I guess:
      bestofphp.com/repo/php-mock-php-mock-php-testing
      But I think a better way would be to wrap classes and methods around the functions and use those wrappers instead because they can be mocked.

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

      @@GaryClarkeTech thank you for the quick answer. I got a finished project where I have to write tests. It’s kinda hard to rewrite everything in a class

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

      @@ayayayayaka37 Yes...legacy code is hard to make testable. I've been there many times 😭

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

    Thanks Amazing.

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

    very helpful thank u sir

  • @Dr.D0s
    @Dr.D0s 3 роки тому

    😈 Amazing 😈 very helpful 😈 thank you 😈

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

    Hi may i ask how to test private/protected methods?

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

      You can use Reflection like so:
      $class = new ReflectionClass('MyClass');
      $method = $class->getMethod($name);
      $method->setAccessible(true);
      But some consider to be a bit of a hack. 'Best practice' is to test only a class's public interface.

  • @DanielK48
    @DanielK48 3 роки тому

    Great content! Can you tell us the theme that you are using? It looks very nice.

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

      Thanks Daniel. It's actually all custom colors which I set myself...I think I just picked one of the built in dark themes as a start point.
      I show how to do it in this PHPStorm recording > ua-cam.com/video/nva_En6MPf8/v-deo.html

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

      @@GaryClarkeTech Looks nice. I was just watching that same video as you replied :D Keep up the awesome work :)

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

    By the way, do you have any testing tutorial where you show how to setup a test database which gets built and torned down with each test and such? If one wants to test db-related code.

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

      Yes but it's in a Symfony tutorial rather than just a plain PHP tutorial (ua-cam.com/video/TOa7JGbRwvk/v-deo.html)
      I may demo how to do this in plain PHP in the Beyond The Basics course which I am working on.

    • @dawid_dahl
      @dawid_dahl 3 роки тому

      @@GaryClarkeTech Awesome, thanks!

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

      That would be a great addition. I am looking for such a thing (haven't managed yet to get it done via fixtures, so now I just import an sql-dump every time I start my tests. Not sure if this the best way to do it.

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

    I get this error unfortunately Undefined type 'PHPUnit\Framework\TestCase'. Any idea what could be wrong ?

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

    Hey Gary , thanks for this simple explanation tutorial for testing . I have defined the Class which i want to test its functions but when i create new test class with extends PHPUnit\Framework\TestCase it returns me that error : Error: Class 'PHPUnit\Framework\TestCase' not found in O:\xampp\htdocs\Jmeter_\Page_login\tests\tests.php on line 7

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

      Have you composer installed it? And is it working for any other test classes?

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

    Hi, Gary! Thank you for such a good demonstration! Your Udemy link isn't working. Please could you update the link? I want to buy this course.

    • @GaryClarkeTech
      @GaryClarkeTech  3 роки тому

      Hi..I'm not sure why it didn't work but I've pasted it in again. Here it is for your convenience:
      www.udemy.com/course/the-complete-object-oriented-php-developer-course/?referralCode=F2C53858029119CC9F39

    • @ivanglushkov7921
      @ivanglushkov7921 3 роки тому

      @@GaryClarkeTech Thank you! It works now!

  • @andreychiglintcew5024
    @andreychiglintcew5024 3 роки тому

    Great! Thx

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

    Could you please tell me which IDE are you using?

  • @pawecyrklaf4729
    @pawecyrklaf4729 3 роки тому

    Amazing :D

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

    I watched this video to understand Mocking and when he get there Unfortunately you started coping and passting and talking faster whitout explaining anyway thx

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

      Thanks Naseem..this is genuinely my favourite kind of feedback because it helps me improve my content (much more useful than a downthumb!). Thanks for watching and I'll cover mocking again some time soon.