PHPUnit: Testing with a Bite

Buy Access

It's Friday night... it's stormy... the office is empty... and you're deploying fresh code to production. Suddenly, an alarm! What!? The fences are down!? The dinosaurs are escaping! Somehow, your beautiful code contained a bug! And as the raptors surround you, one thought keeps coming back: if only we had written tests.


In this tutorial, we're going to jump over the hurdle of learning how to test so you can save the day!

  • Basic unit testing
  • Test-Driven-Development: how to do it, when to do it!
  • Mocking and test doubles! Creating mocks in PHPUnit & Prophecy
  • Using data providers to run tests over and over again with different input
  • Running code before and after each test
  • Testing for exceptions
  • Handling the database in tests
  • Integration tests: testing with real objects
  • Functional testing!
  • Continuous Integration (CI): let the robots run your tests

So grab your keyboard, reboot the system, and start testing with us!

Your Guides

Andrew Marcinkevičius Ryan Weaver Leanna Pelham

Questions? Conversation?

  • 2018-10-23 daimmo

    Just came here after noticing a link in the Design Pattern course thread.

  • 2018-10-08 Victor Bocharsky

    Hey Chmlls,

    Good catch! Looks like this course wasn't added to any track, so it's our fault. We'll fix it soon. However, you can find ALL courses even those that mistakenly were not added to any track here:


  • 2018-10-07 Chmlls

    I love all your tutorials!
    One question, in which category is this course in? I found it by searching TDD but I didn't see it in any course.

    I'm wondering If I'm missing some other good tutorials that are not categorized.

  • 2018-08-09 weaverryan

    Hi again Irfan!

    Yep, this course is for you: the PHP dev who hasn't tested before. We *do* use Symfony in this tutorial. But, for many parts of it, it's not relevant. Unit testing is done the exact same way regardless of your framework. This is true because unit tests don't even touch your framework or know that it exists :). Later in the tutorial, when we talk about integration tests and functional tests, these *do* interact with your framework, and are Symfony-specific (though, the concepts apply to any framework).

    So, based on what you've told me so far, if you're excited to learn about testing, I think (hope) that you'll learn a ton with this tutorial :).


  • 2018-08-08 Irfan

    Hey Diego Aguiar
    Thank you very much for your reply. I am familiar with OOPHP but I never wrote automated test and secondly, I am not familiar with Symfony. I used Laravel few times for small projects. Having said, Do you think its a good idea to take this course ? Thanks in advance :)

  • 2018-05-14 weaverryan

    That's exactly why we have that feature :). Everyone has different knowledge and different English mastery. I also watch in fast forward on other sites too sometimes ;)

  • 2018-05-13 Coder

    good that there is a feature to run videos 1.25x or faster, using it really often :) without it, when you know lot of things, it would be boring waste of time. But I watch those at fast speed, maybe I will notice something what I do not know.

  • 2018-04-24 toporovvv

    Thank you for a wonderful course. One of the best on KnpU.

  • 2018-01-16 Scottie Gutman

    Once again you have created a wonderful tutorial that I enjoyed very much! Thank you and I love the humor.

  • 2017-12-01 Diego Aguiar

    Hey Irfan
    If you mean beginner to testing, then yes :)
    This course is not that complex, but at least you need to be familiar with PHP and OO concepts
    To your question "Are you guys using any PHP framework?", yes, we show you how to test with PHPUnit, it's a very good open source framework, and actually we use it here in KnpU.


  • 2017-11-30 Irfan

    Is this course for absolute beginner ? I never tested my code before. Are you guys using any PHP framework ?

  • 2017-11-10 Victor Bocharsky

    Hey Simon,

    Haha, no problem! I just explained our complex workflow a bit ;) On the other hand I totally understand you, it'd be cool to watch as many videos at once as you want and take a break when you want :)


  • 2017-11-10 Simon Carr

    Thanks Victor. It was not a criticism, just a question and your strategy serves everyone, like you say, I can just wait, but I think I will still watch them as they come out they are like a box of chocolates, you eat them as soon as you see them.

  • 2017-11-10 Victor Bocharsky

    Hey Simon,

    We want to deliver our content as soon as possible to our users, i.e. we publish new videos right after they are ready. It depends, but most of the time we are able to process 1 video per day. It's a complex process, we need to recode video, record audio, then make them both together and add some special effects like a cool animation, video notes, etc. So we *can* release an entire course at once, but then you need to wait a few weeks when we record and process all the videos in this course. But as I said, we chose a different strategy - release new videos as soon as they are ready. If you want to see the entire course in the same breath, take a break and return in a few weeks, I think to that time almost all the videos will be released. Thanks for understanding!


  • 2017-11-10 Simon Carr

    Is it normal that we get one video per day? or will we see a few all at once?

  • 2017-10-06 Wil Iglesias

    Great! Thanks weaverryan!

  • 2017-10-04 weaverryan

    Yo Wil Iglesias!

    Haha, well then I have good news :). We will finish our Ansistrano tutorial (over the next couple of weeks) and then PHPUnit will be right after that. So, I expect it to start being released this month!


  • 2017-10-04 Wil Iglesias

    Hi Ryan! When will the PHPUnit tutorial come out? Because it's just what I've been waiting for to improve my superpowers ;)

  • 2017-08-02 weaverryan

    Haha "the usual question" :). Yes indeed! I hope over the next few months we'll start to be able to give concrete estimates very early on - our process is actually quite solid and predictable these days (woo!).


  • 2017-08-02 Andrew M.

    I would give a rough guess that it should be published 1-3 months before the year ends (it's right now in coding stages), but there always might be some unplanned issues delaying it.

  • 2017-08-02 Victor Bocharsky

    Hey Mehdi,

    Sorry, we don't have any ETA because this course is on early planning stage yet, but you can track it here: or press "Notify me when course is available" and we'll email you ;)


  • 2017-08-01 Mehdi

    Hi, This is really what I need. let me be the first to ask the usual question :)
    any ETA yet?

  • 2017-08-01 Andriy Frankevych

    Yes! Just in time, I was waiting for this <3