4

Does anyone have a verified method to configure PhpStorm 10.x to run unit tests in CakePHP 3.x?

edit: after @ndm's answer I fixed my PhpStorm configuration, adding "phpunit.xml.dist" to PHPUnit > Test Runner: Checked Default configuration file.

now I have different error

/Applications/MAMP/bin/php/php5.6.10/bin/php /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/phpunit --configuration /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/phpunit.xml.dist /Applications/MAMP/htdocs/sites/my_app --teamcity

Testing started at 12:29 ...
PHP Warning: require(/Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/../vendor/autoload.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/bootstrap.php on line 3
PHP Fatal error:  require(): Failed opening required '/Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/../vendor/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.10/lib/php') in /Applications/MAMP/htdocs/sites/my_app/vendor/phpunit/phpunit/tests/bootstrap.php on line 3

Process finished with exit code 255

In Run Config, PHPUnit: Test Runner -> Test Scope -> Directory:

/Applications/MAMP/htdocs/sites/my_app/src
Zbigniew Ledwoń
  • 682
  • 1
  • 6
  • 19
  • 1
    There's nothing unusual that would need to be done (set the PHP interpreter, set the autoloader and phpunit config file to use). You maybe you want to explain what exactly you are having problems with. – ndm Jan 13 '16 at 08:19
  • I'm getting this error: PHP Fatal error: Trait 'Aura\Framework\Test\WiringAssertionsTrait' not found – Zbigniew Ledwoń Jan 13 '16 at 14:35
  • Well, without additional information, like a stacktrace, how you are running the tests, and how you have configured PhpStorm, it's pretty hard to tell what's wrong. – ndm Jan 14 '16 at 08:28
  • I added some more details. – Zbigniew Ledwoń Jan 14 '16 at 20:22
  • 1
    Why do you point to the apps root directory? This will cause all sub-folders to be inspected for tests, including all dependencies. – ndm Jan 15 '16 at 08:43
  • Oh, right. I changed it to 'Application/MAMP/htdocs/sites/my_app/src'. But I still have this error caused by '... bootstrap.php line 3' - 'require __DIR__ . "/../vendor/autoload.php";' - still have no idea what I'm doing wrong – Zbigniew Ledwoń Jan 15 '16 at 09:42

1 Answers1

6

Without trying to solve your specific error, here's how I have configured PhpStorm.

In Languages & Frameworks > PHP

  • > Interpreter: Pointing to a local PHP executable

  • > PHPUnit > PHPUnit Library: Checked Use custom autoloader, pointing to vendor/autoload.php in the app folder.

  • > PHPUnit > Test Runner: Checked Default configuration file, pointing to phpunit.xml.dist in the app folder.

* All paths should be absolute ones!

And that's all, running tests via the file/folder/code context menus Run ... command works just fine.

ndm
  • 59,784
  • 9
  • 71
  • 110
  • 1
    Without adding the bootstrap file it does not work for me. If I add the tests/bootstrap file than it seems it uses default datasource not test datasource. Am I missing something? – rrd Jan 31 '16 at 17:27
  • @rrd Adding it where? In the test runner configuration? Sounds like possibly the current working directory is incorrect, but I can't do much more than guessing. – ndm Feb 03 '16 at 09:52
  • @rrd I am having the exact same issue right now, did you ever resolve it? – lordphnx May 07 '17 at 16:57
  • @lordphnx Yes I managed to get it work, but unfortunately I can not remember what was the solution. – rrd May 08 '17 at 08:43
  • @rrd: Did you add phpunit.xml.dist to your TestRunner? In my case when I didn't add it tests would run with default datasource. When I added phpunit.xml.dist it will correctly take the test_default datasource. – Seb Jan 17 '18 at 17:13