1
|
Running PHPUnit tests in PHPStorm
|
2
|
============================================
|
3
|
|
4
|
Author: Andreas Kohlbecker, 2012–2020
|
5
|
|
6
|
|
7
|
**Official PhPStorm documentation on PHPUnit tests:**
|
8
|
|
9
|
* https://www.jetbrains.com/help/phpstorm/using-phpunit-framework.html
|
10
|
* https://www.jetbrains.com/help/phpstorm/php-test-frameworks.html
|
11
|
* https://www.jetbrains.com/help/phpstorm/using-the-composer-dependency-manager.html
|
12
|
* https://www.jetbrains.com/help/phpstorm/php-interpreters.html
|
13
|
|
14
|
|
15
|
/usr/bin/php /home/andreas/workspaces/cdm/cdm-dataportal/vendor/phpunit/phpunit/phpunit --configuration /home/andreas/workspaces/cdm/cdm-dataportal/modules/cdm_dataportal/test/phpUnit/phpUnit.xml StatisticalValuesTests /home/andreas/workspaces/cdm/cdm-dataportal/modules/cdm_dataportal/test/phpUnit/src/unit/statistical_values_tests.php
|
16
|
|
17
|
|
18
|
|
19
|
Install PHPUnit
|
20
|
----------------------------------------------
|
21
|
|
22
|
In Debian based Linux distros PHPUnit usually can be installed by
|
23
|
|
24
|
apt-get install phpunit
|
25
|
|
26
|
the recommended way for installing phpUnit is the installation via [Composer](https://getcomposer.org/)
|
27
|
the state of the art dependency manager for PHP.
|
28
|
|
29
|
apt-get install composer
|
30
|
|
31
|
The `cdm-dataportal` project contains a `composer.json` file which sets *phpunit version 8* as dependency for this project.
|
32
|
PHPStorm should detect this configuration file. You can check this by opening the settings page **Language&Frameworks > PHP > Composer**
|
33
|
which shoould look like:
|
34
|
|
35
|
![](phpStorm-composer-configuration.png)
|
36
|
|
37
|
**NOTE:** You may also want to install PHP_CodeCoverage by adding the dependency to `composer.json`.
|
38
|
|
39
|
|
40
|
|
41
|
Install XDebug
|
42
|
----------------------------------------------
|
43
|
|
44
|
|
45
|
xdebug can easily be installed via pecl:
|
46
|
|
47
|
pecl install xdebug
|
48
|
|
49
|
at the end of the output pecl shows:
|
50
|
|
51
|
...
|
52
|
Build process completed successfully
|
53
|
Installing '/usr/lib/php5/20121212/xdebug.so'
|
54
|
|
55
|
|
56
|
After successful installation the XDebug extension binary will be located for example in `/usr/lib/php/*/xdebug.so`.
|
57
|
In order to make XDebug available to the PHP CLI you need to set this location in the settings page **File > Settings >
|
58
|
Languages and Frameworks > PHP** as *Debugger extension*:
|
59
|
|
60
|
![](phpStorm-php-cli-configuration.png)
|
61
|
|
62
|
|
63
|
Configure PHPUnit in PHPStorm
|
64
|
-----------------------------------------------
|
65
|
|
66
|
PHPStorm should have autodetected the PHPUnit installed via Composer already
|
67
|
Open the settings page **File > Settings > Languages and Frameworks > PHP > Test Frameworks** make sure the option
|
68
|
"*Use Composer Autoloader*" is checked and set `modules/cdm_dataportal/test/phpUnit/phpUnit.xml` as *Default configuration file*.
|
69
|
|
70
|
![](phpStorm-phpunit-configuration.png)
|
71
|
|
72
|
|
73
|
Running PHPUnit tests in PHPStorm
|
74
|
---------------------------------------------------------------
|
75
|
|
76
|
Simply right click on a test file and choose *Run 'TestFile' (PHPUnit)* in the context menu.
|
77
|
|
78
|
Running PHPUnit tests in from the commandline
|
79
|
---------------------------------------------------------------
|
80
|
|
81
|
navigate into the project folder and ...
|
82
|
|
83
|
To run the test suite:
|
84
|
|
85
|
~~~
|
86
|
php vendor/phpunit/phpunit/phpunit --configuration modules/cdm_dataportal/test/phpUnit/phpUnit.xml
|
87
|
~~~
|
88
|
|
89
|
To execute a single test class
|
90
|
~~~
|
91
|
php vendor/phpunit/phpunit/phpunit --configuration modules/cdm_dataportal/test/phpUnit/phpUnit.xml modules/cdm_dataportal/test/phpUnit/src/unit/StatisticalValuesTest.php
|
92
|
~~~
|
93
|
|
94
|
Running PHPUnit integration tests via the phpunitRunner.php script (DEPRECATED)
|
95
|
---------------------------------------------------------------
|
96
|
|
97
|
*This has only been preserved since it could be useful for running test suites from the commandline or in the CI server.*
|
98
|
|
99
|
what we are now trying to achieve with the eclipse launcher configuration is in principle
|
100
|
to run the following command:
|
101
|
|
102
|
/usr/bin/php52/php /usr/bin/php52/phpunit --verbose --bootstrap bootstrap.php
|
103
|
|
104
|
therefore we provide the script phpunitRunner.php which will execute phpUnit.
|
105
|
In order to configure it properly you need to supply some environment variables.
|
106
|
|
107
|
DRUPAL_ROOT - path to the root of your Drupal installation, that is dataportal installation.
|
108
|
XDEBUG_CONFIG - must be set to 'idekey=ECLIPSE_DBGP'
|
109
|
SITE_BASE_PATH - set this variable to the base path of the dataportal website you want to use for testing, eg: /flora-malesiana
|
110
|
|
111
|
|
112
|
Create a new php run configuration which executes phpunitRunner.php and configure the above named
|
113
|
environment variables in the "Environment" tab.
|
114
|
In the "PhpScriptArgument" tab set the following:
|
115
|
|
116
|
--stderr --configuration ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml} ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/src/}
|
117
|
|
118
|
|
119
|
|
120
|
|