FREELessons: 13Length: 1.3 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

3.1 PHPUnit

In this lesson we’ll take a look at the PHPUnit testing framework. We’ll explore its features and basic installation instructions so that we can work with it in the next section.

Related Links

3.1 PHPUnit

Now that we've learned a couple of different testing development processes that we can follow, let's examine several popular PHP testing frameworks. These frameworks are fully featured with a lot of different helpful methods to help make testing your PHP applications a breeze. So, this section of the course will give you a brief overview of them, their benefits and how to install them. In the next section, we'll take a look at each one in action, writing various different types of tests. So, let's start with PHP Unit. I'll switch into Firefox. And here is the PHP Unit website. You can visit them at PHP unit dot DE. And, as I said, this is a fully featured testing framework. It offers you tons of features that you can use for testing. It's pretty easy to use. It allows you to write clean tests, and gives you great test feedback via the command line test runner. So, you can easily run your tests with simple commands in the terminal. Now, we'll learning more about using PHP Unit in the next section, but feel free to go ahead and browse around and view the documentation if you'd like to get a head start. Otherwise, let's get PHP Unit installed and ready to use for later in the course. Now, there are many different ways that you can install PHP Unit. If we click on the Download button, you can see there's various different downloads here. You click on Get Started, you can see some other information here for getting started with PHP unit. You can also use composer or pair. I'm going to be using composer. So, with composer, all we have to do is add a couple of lines into a composer dot Jason file. If you don't have a composer dot Jason file for your project, all you have to do is create a new one. And I'll show you how to do that now. Let's switch into our text editor and inside of the same PHP Testing Basics folder that we've been using, I'll create a new file. Let's save this as composer dot Jason and let's add in the following code. This simply requires PHP unit as a dependency in our application for development purposes. We don't even have to manage it. Composer will take care of all of that for us. Now, we just need to run composer to install it. Let's save our composer dot Jason file. I'll switch in to my terminal. And I'll change directories into sites. PHP Testing Basics. And let's run the composer install command. There we go. As you can see, composer has finished. Of course, mine was loaded in from cache as I already had it installed previously. Now, to make sure the installation was successful, let's run the following command. PHP bender slash bin slash PHP unit. And if you see a list of options for the PHP unit command, like you're seeing here on my screen, then you're good to go. PHP unit is installed and ready to use. Let's now move on and examine another PHP testing framework that we'll use later called, Codeception. I'll see you there.

Back to the top