7

My tools:

  • Instance generated with buildkit - civibuild: $ civibuild create dmaster --url http://d47.localhost --admin-pass mypass
  • Mac OS + PHPStorm 8.0.4 + MAMP (/Applications/MAMP/bin/php/php5.6.10/bin/php)

I've been close to getting this to work a number of times - but still coming up short. I've looked at Eileen's: https://wiki.civicrm.org/confluence/display/CRMDOC/Tests+in+phpstorm and at Tim's How can I use Xdebug with CiviCRM unit tests? - but something is always slightly different.

UPDATE - after buildkit and phpstorm updates -> I’ve posted new slides in the answer below!

1

2 Answers 2

9

Here are the steps/complete set of screenshots of a configuration that now works for me:

1) from command line ensure you can run buildkit -> civibuild

$ civibuild create dmaster --type drupal-demo --civi-ver master --url http://dmaster.localhost --admin-user myuser --admin-pass mypass

2) from command line ensure you can run tests - that all is working properly

karins-macbook-pro:civicrm sysadmin$ pwd /Applications/MAMP/htdocs/buildkit/build/dmaster/sites/all/modules/civicrm

$ cd /path/to/civicrm
$ env CIVICRM_UF=UnitTests phpunit4 ./tests/phpunit/CRM/AllTests.php

Installing dmastertes_7by9i schema

Installing dmastertes_7by9i database
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.

...............................................

.......
^X^C

3) Ensure you can fire up a http://d47.localhost/ in a browser and debug/set breakpoints anywhere in PHPStorm / step through code in your Drupal/CiviCRM code base - e.g.

enter image description here

4. PHPStorm: Preferences -> Languages & Frameworks -> PHP:

enter image description here

5. PHPStorm: Preferences -> Project: Directories:

enter image description here

6. PHPStorm: Preferences -> Language & Frameworks -> PHP -> PHPUnit:

enter image description here

7. PHPStorm: Run -> Edit Configurations -> Default -> PHP Unit:

enter image description here

8. Run the test by right clicking on the test itself:

enter image description here

9. Et voila:

enter image description here enter image description here

UPDATE JULY 2018 After updating buildkit:

cd ~/buildkit
git pull
./bin/civi-download-tools

I had to make some edits as some of the paths have changed. The edits I made are:

ad 4: enter image description here

ad 5: enter image description here

ad 7: note you want to Include parent environment variables enter image description here

And we're up and running again: enter image description here

UPDATE AUGUST 2020 After updating buildkit and PHPStorm -> here's the new screenshots!

enter image description here enter image description here enter image description here enter image description here enter image description here

Running a test via the command line also using phpunit5 now:

karins-MBP:civicrm sysadmin$ env CIVICRM_UF=UnitTests phpunit5 --filter testSubmitWithTax ./tests/phpunit/CRM/Member/Form/MembershipRenewalTest
Parsing schema description /Applications/MAMP/htdocs/buildkit/build/dmaster/web/sites/all/modules/civicrm/xml/schema/Schema.xml
Extracting database information
Extracting table information
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
.                                                                   1 / 1 (100%)
Installing dmastercivi_rb7eb database
Time: 9.92 seconds, Memory: 58.50MB
OK (1 test, 18 assertions)
0
0

Having a wild guess - are you setting

define('CIVICRM_UF', 'Drupal');

somewhere in your civicrm.setting file (I know we do)?

4
  • This is a buildkit - civibuild: $ civibuild create dmaster --url d47.localhost --admin-pass mypass Jan 2, 2017 at 15:30
  • 1
    So this didn't work for me, until I updated the composer version of phpunit shipped with buildkit to 4.8.21 and used that in phpstorm. Then everything worked beautifully! Aug 10, 2017 at 21:52
  • How old is your buildkit? 😀 Sep 26, 2017 at 16:51
  • checking versions: karins-macbook-pro:buildkit sysadmin$ phpunit4 --version PHPUnit 4.8.21 by Sebastian Bergmann and contributors. Aug 1, 2018 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.