Project

General

Profile

Download (4.04 KB) Statistics
| Branch: | Tag: | Revision:
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 whowever 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

    
79
Running PHPUnit tests via the phpunitRunner.php script (DEPRECATED)
80
---------------------------------------------------------------
81

    
82
*This has only been preseved since it could be useful for running test suites from the commandline or in the CI server.*
83

    
84
 what we are now trying to achieve with the eclipse launcher configuration is in principle
85
 to run the following command:
86

    
87
  /usr/bin/php52/php /usr/bin/php52/phpunit --verbose --bootstrap bootstrap.php
88

    
89
therefore we provide the script phpunitRunner.php which will execute phpUnit.
90
In order to configure it properly you need to supply some environment variables.
91

    
92
  DRUPAL_ROOT - path to the root of your Drupal installation, that is dataportal installation.
93
  XDEBUG_CONFIG - must be set to 'idekey=ECLIPSE_DBGP'
94
  SITE_BASE_PATH - set this variable to the base path of the dataportal website you want to use for testing, eg: /flora-malesiana
95

    
96

    
97
Create a new php run configuration which executes phpunitRunner.php and configure the above named
98
environment variables in the "Environment" tab.
99
In the "PhpScriptArgument" tab set the following:
100

    
101
  	--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/}
102

    
103

    
104

    
105

    
(2-2/10)