PhpUnit Testing With PhpStorm

Configure PHP Interpreter

The first thing that we need to do is to make sure the an interpreter has been set up.
Navigate to your preferences(settings). On mac this is located under phpstorm => preferences in the menu.
The php version should be listed for the interpreter. If not, click the "..." next to the dropdown and input the path to your php executable.

Configure Test Settings

Click the dropdown in the upper right corner of the window
Click "Edit Configuration"
Click the + Sign
Click PHPUnit

Enter  a name for this configuration. I called it "phpunit mylib"
Next we have to select the type of test we'll be doing. There are several options to choose from.
We could run a test on an entire directory, a specific class, specific method or by using the phpunit.xml  In this case, I'll be running the test cases on all phpunit classes in phpunit/mytest/Test.

Configure PHP Unit

There are several ways to configure PhpUnit.
Load from include path
Use custom autoloader
Path to phpunit.phar

Method #1 - Use Custom Autoloader

If we used composer to install phpunit. We can use it to load phpunit.
I ran composer the following composer.json file.(more information on composer)
    "require": {
    "require-dev": {
        "phpunit/phpunit": "*"
Composer downloads phpunit to vendor/phpunit and an autoloader to vendor/autoloader.php
Select "Use custom autoloader" select the path to vendor/autoloader.php

Method #2 - Load From Include Path

If the phpunit library was download via another method and was added to your php include_path. You can select "Load From Include Path".


Cookbook Category: 

Add new comment