L
L
LB7772014-08-27 20:20:18
JavaScript
LB777, 2014-08-27 20:20:18

How to properly configure PHPStorm7 for PHPUnit?

I have PHPStorm 7 and want to learn PHPUnit testing. Never encountered any testing before and PHPStorm recently purchased.
The computer has Windows 7 and the Open Server server platform installed.
There are a lot of ways to install PHPUnit via PEAR in RuNet, but when running any test, PHPUnit reports that it will be supported via PEAR only until December 31, 2014 and therefore you need to install it via Composer or PHAR.
Open Server already has Composer and so I installed PHPUnit locally (in my project folder). Checked, everything works.
After that I decided to set up PHPStorm. But from the examples on the Internet I did not understand anything and it did not work.
If I understood correctly, then PHPUnit could not be installed at all, but download phpunit.phar and specify it in the PHPStorm settings (File>Settings>PHP>PHPUnit>Path to phpunit.phar)
Please tell us what and how to configure in PHPStorm7 for PHPUnit using the example of two files Money.php and MoneyTest.php from phpunit.de/getting-started.html .
And what should be in autoload.php and how to write it correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Lissitzky, 2014-08-28
@LB777

Indeed - it's easiest with a .phar file in a specific project.
Set the PHPUnit version to 3.7.XX. With the fourth version in PHPStorm 7, there is still a bug with running tests (in PHPStorm 8 EAP, it seems to have been fixed). Everything works manually from the console, but from PHPStorm it swears.
How to start:
1. Create a project structure, as in the link you gave:

|-src
|   |-autoload.php
|   |-Money.php
|
|-tests
    |-MoneyTest.php

In the autoload.php file, you need to include the files that you are going to test.
<?php
require_once __DIR__ . '/Money.php';

2. Set up the PHPUnit configuration:
Run -> Edit Configurations...
In the upper left part of the window that appears, click the green plus and set up the configuration:
- set Test Scope to 'Directory' and specify the path to the tests folder
- click on the wrench and set the path to phpunit.phar (if you have a PHPUnit folder locally, then include it in File -> Settings -> ProjectSettings -> PHP ... Include Paths, and then switch to Load From Include Path in the PHPUnit settings).
- we also point the default bootstrap file to our autoload.php, where we connect the classes that we will actually test (we indicated where the tests themselves are for PHPUnit at the beginning).
- Click Apply -> Apply -> OK
Everything, now next to the created configuration on the PHPStorm panel there is a green arrow for running tests. We press, and if everything is correct, we get a green stripe.
Those. the configuration process consists of three steps:
1. specify where PHPUnit lies
2. indicate where the tests lie
3. indicate where the test class loader lies.
Look like that's it.

N
ndu_spb, 2015-04-10
@ndu_spb

A small addition, do not forget to specify the php interpreterfff03503734f43d5b1c690222bdefcfb.png

U
Uncle_Bill, 2017-03-11
@Uncle_Bill

To complete the picture: PHPUnit support in PhpStorm .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question