PHP Unit Testing with PHPUnit

  • Overview
  • Curriculum
  • Instructor
  • Review

About This Course

Unit test your PHP code using the PHPUnit testing framework: find bugs quickly and early, and improve your code quality.

If you are a PHP developer and you want to learn how to write better code, with fewer bugs, you will need to know how to write unit tests.

Learn how to unit test your PHP code using the PHPUnit testing framework.

  • Learn what unit tests are

  • Learn how to write unit tests using PHPUnit

  • Build a test suite for PHP functions and classes

  • Make test methods dependent on each other

  • Use test doubles: mocks and stubs, including how to use Mockery

  • Learn how and why you should use dependency injection

  • Learn test-driven development (TDD)

  • Learn how to test protected and private methods and properties (and whether you actually should or not!)

  • Learn how to test abstract classes

A skill that will enable you to write higher quality code, in a shorter time, with better documentation and fewer bugs.

Learning how to write unit tests for your code will make you write better code. With automated tests, you can find bugs more easily, and if you break something you'll notice straight away.

Many experienced developers write unit tests for their code. It's a repeatable way of checking that the code works as intended, and also serves as documentation. Many popular PHP projects are unit tested, such as WordPress and Moodle, and if you use frameworks such as Laravel or Symfony, these provide tight integration with the PHPUnit testing framework.

Content and Overview

How do you currently test your code? Maybe you run your code in a browser, use var_dump a lot and so on. The problem with this is that you only tend to test new code - you don't go back and test old code. What if you add some new code that breaks the old code?

With automated unit tests, you have more control. If your new code breaks something, you'll notice straight away. You can fix bugs more easily, thereby reducing development time.

Tests are also a form of documentation, just like comments: they serve to show why the code has been written that way.

  • Suitable for all PHP developers, you'll start by learning the basics of unit testing PHP code, including how to use assertions.

  • Then you'll learn how to test functions and classes, and how to configure the PHPUnit framework.

  • Next you'll learn how to use test dependencies, fixtures and how to test for exceptions.

  • You'll also see how test doubles work - mock objects and stub methods.

  • Then you'll learn how to write code using test-driven development - writing the tests first, then the code.

  • You'll also learn how to test protected and private class methods and properties, and whether this is actually a good idea or not.

  • Testing static methods is covered in detail, including several methods for dealing with static dependencies.

When you complete the course you'll be able to write unit tests for your existing PHP code, and develop new code using test-driven development.

Complete with all the code shown in the lectures, you'll be able to work alongside the instructor and will receive a verifiable certificate of completion upon finishing the course.

Also, at all times throughout the course you have access to the instructor in the Q&A section to ask for help with any topic related to the course.

Enrol now and add unit testing to your PHP skillset!

  • Write automated tests for your functions and classes

  • Write better code with less bugs, in less time

  • Develop code using test-driven development

Course Curriculum

Instructor

Profile photo of Dave Hollingworth
Dave Hollingworth

Hi, I'm Dave Hollingworth. I'm an IT trainer and web application developer. I've been programming for over thirty years, and teaching IT since 1999.    I've developed enterprise-level applications on platforms ranging from mainframes to mobiles: from my first web application, a quotes system created for a major insurance company back in 1999 - the first of its type in the...

Review
4.9 course rating
4K ratings
ui-avatar of Angel Acatecatl
Angel A.
5.0
6 months ago

It was amazing, I learn more about the PHP unit test and how it goes when you build a quality code.

  • Helpful
  • Not helpful
ui-avatar of Jason Murray
Jason M.
3.0
6 months ago

Good information but very dated. Course is assuming PHPUnit 7.x, and current version is 11.x which deprecates methods. Spent a good amount of time translating to V11 best practices. Additionally using PHP 7.x, I'd love to see this updated to 8.x to show better use of type hinting and best practices.

  • Helpful
  • Not helpful
ui-avatar of Parvesh Wadhwa
Parvesh W.
5.0
7 months ago

Great Course

  • Helpful
  • Not helpful
ui-avatar of Balakrishnan S
Balakrishnan S.
5.0
7 months ago

Nice

  • Helpful
  • Not helpful
ui-avatar of Pierre-Alexandre Dhery
Pierre-alexandre D.
4.5
7 months ago

Très bien expliqué jusqu'ici avec des exemples que je trouve proche du code que j'utilise au quotidien dans le milieu professionnel

  • Helpful
  • Not helpful
ui-avatar of Pranav Thakur
Pranav T.
3.0
8 months ago

good but not explain completelly

  • Helpful
  • Not helpful
ui-avatar of Alex Hampton
Alex H.
3.5
8 months ago

Overall it was a great course. However a lot of the information is deprecated now.

  • Helpful
  • Not helpful
ui-avatar of Training 2
Training 2.
4.5
9 months ago

Good Lesson

  • Helpful
  • Not helpful
ui-avatar of Edu
Edu
4.5
9 months ago

Until now everything goes smoothly. The course is even applicable to Docker version of PHP, which makes things even better. I ran with small issues, but those were errors on my end.

  • Helpful
  • Not helpful
ui-avatar of Oleksandr S.
Oleksandr S.
4.0
10 months ago

Very useful course, the information is presented clearly and accessibly. I would like to see approaches to using test databases in this course, especially if the project has several databases and hundreds of tables in each. There are already some useful discussions on this topic in the Q&A section, but it would be nice to make at least one video dedicated to this topic.

  • Helpful
  • Not helpful
Leave A Reply

Your email address will not be published. Required fields are marked *

Ratings

Courses You May Like

Lorem ipsum dolor sit amet elit
Show More Courses