0

I am fairly new to Civicrm, I created a new API for an Entity which I would like to make a pull request for but however it seems preparing a test environment in Civicrm is quite difficult.

I have followed this tutorial but seems it's not for Civicrm 4.7 since some of the paths mentioned are not in Civicrm version 4.7

Tutorial URL: https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO

I can't seem to be able to find these paths , mentioned below

Configure the PHP constant CIVICRM_DSN. Database connection using PHP constant To define PHP constants for unit-testing, copy the file "/tests/phpunit/CiviTest/civicrm.settings.local.php.txt" to "/tests/phpunit/CiviTest/civicrm.settings.local.php". Edit the file to include to include a line like this:

define('CIVICRM_DSN', 'mysql://db_username:db_password@localhost/civicrm_tests_dev'); Configure the environment variable CIVICRM_TEST_DSN. (The format is the same as the CIVICRM_DSN above.)

Don't use this approach unless you already have a strong understanding of environment variables. Pass the MySQL details as command-line parameters each time you run the unit-tests. (This approach doesn't require updating any other files, but it's cumbersome to use when you regularly run unit-tests.)

https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO

When I go to the root of my API extension and type :

civix test CRM_MyEntity_EntityAction 

I get error below which suggests I should read the tutorial above

enter image description here

2
  • Please can you post the error? Which "parts" are missing in 4.7?
    – JohnFF
    Feb 27, 2016 at 12:47
  • @JohnFF Please check updated question
    – Emeka Mbah
    Feb 27, 2016 at 13:55

2 Answers 2

1

Agree with JohnFF and JonG that it's good to look at buildkit/civibuild for this. If you review the main page for the test suite (http://wiki.civicrm.org/confluence/display/CRMDOC/Testing), you'll notice a common theme -- all the tests should work out of the box on new builds if you use civibuild. (They need to -- because the civicrm.org test infrastructure runs on civibuild.) A manual installation requires more work.

In this case, the instructions you've come across in Setting up your personal testing sandbox HOWTO are out-of-date -- those instructions apply from roughly v2.x - v4.6. The test-runner changed a bit in v4.7.

How it works in v4.6 and earlier: Civi included a fork of phpunit with several small patches, and the tests only worked if you used this fork of PHPUnit. This had several consequences like:

  • Every developers' copy of CiviCRM required an extra config file under test/phpunit/CiviTest.
  • Upgrading phpunit (eg to run in newer versions of PHP) was onerous.
  • Running a test-class in an extension was pretty hard. You needed a way to link your test with the Civi installation. (The location varies depending on the CMS and configuration.)
  • Running a test in an IDE was... hard? impossible? (I never did it 4.6 or earlier.)

How it works in v4.7: Tests are no longer special programs with a strongly-prescribed structure. Instead, we've addressed the broader problem of how to load Civi in your CLI scripts. You can use any test-runner (phpunit, codeception, behat, etc) with any package (civicrm-core, civicrm-drupal, or an extension). A "Civi enabled test" is just a plain-old PHP script which includes a line like this:

eval(`cv php:boot`); // or...
eval(`cv php:boot --test`); // or...
eval(`cv php:boot --level=classloader`);

The cv tool is responsible for loading/booting CiviCRM in your test.

When designing tests, there are different types of tests... such as bare unit-tests, headless database tests, and end-to-end tests. For more discussion about these concepts, see:

If you haven't used civibuild, then pay particular attention to the README for org.civicrm.testapalaooza under "Setup: Option B: Manual".

1
0

Depending on how you installed civi, these test files may not have been included. How did you install it? If you use buildkit you get these. Otherwise feel free to download them from the github repo, but although I think I was able to successfully do that I remember it being fiddlesome.

3
  • Any steps in using buildkit?
    – Emeka Mbah
    Feb 27, 2016 at 17:26
  • @Digitlimit - I'm not sure what the question "Any steps in using buildkit?" is asking - but documentation for buildkit is here: buildkit.civicrm.org/#/welcome Feb 27, 2016 at 22:06
  • Thanks I have installed buildkit on ubuntu everything seems okay except this: Note: Please ensure that nginx.conf includes this directive: Include /home/embah/.amp/nginx.d/*.conf The location of nginx.conf varies, but it may be: /etc/nginx/nginx.conf You will need to restart nginx after adding the directive -- and again after creating any new sites. Nginx restart fails when I added the directive
    – Emeka Mbah
    Feb 27, 2016 at 22:09

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.