Answers.Body: <p>Agree with JohnFF and JonG that it's good to look at buildkit/<code>civibuild</code> for this. If you review the main page for the test suite (<a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Testing" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/Testing</a>), you'll notice a common theme -- all the tests should work out of the box on new builds if you use <code>civibuild</code>. (They need to -- because the <code>civicrm.org</code> test infrastructure runs on <code>civibuild</code>.) A manual installation requires more work.</p>
  
  <p>In this case, the instructions you've come across in <a href="https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO" rel="nofollow">Setting up your personal testing sandbox HOWTO</a> are out-of-date -- those instructions apply from roughly v2.x - v4.6. The test-runner changed a bit in v4.7.</p>
  
  <p><strong>How it works in v4.6 and earlier</strong>: Civi included a fork of <code>phpunit</code> with several small patches, and the tests only worked if you used this fork of PHPUnit. This had several consequences like:</p>
  
  <ul>
  <li>Every developers' copy of CiviCRM required an extra config file under <code>test/phpunit/CiviTest</code>.</li>
  <li>Upgrading <code>phpunit</code> (eg to run in newer versions of PHP) was onerous.</li>
  <li>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.)</li>
  <li>Running a test in an IDE was... hard? impossible? (I never did it 4.6 or earlier.)</li>
  </ul>
  
  <p><strong>How it works in v4.7</strong>: 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 (<code>phpunit</code>, <code>codeception</code>, <code>behat</code>, etc) with any package (<code>civicrm-core</code>, <code>civicrm-drupal</code>, or an extension). A "Civi enabled test" is just a plain-old PHP script which includes a line like this:</p>
  
  <pre><code>eval(`cv php:boot`); // or...
  eval(`cv php:boot --test`); // or...
  eval(`cv php:boot --level=classloader`);
  </code></pre>
  
  <p>The <a href="https://github.com/civicrm/cv" rel="nofollow"><code>cv</code></a> tool is responsible for loading/booting CiviCRM in your test.</p>
  
  <p>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:</p>
  
  <ul>
  <li><a href="https://github.com/civicrm/org.civicrm.testapalooza" rel="nofollow">https://github.com/civicrm/org.civicrm.testapalooza</a></li>
  <li><a href="https://civicrm.org/blog/totten/developers-extension-testapalooza" rel="nofollow">https://civicrm.org/blog/totten/developers-extension-testapalooza</a></li>
  </ul>
  
  <p>If you haven't used <code>civibuild</code>, then pay particular attention to the README for <code>org.civicrm.testapalaooza</code> under "Setup: Option B: Manual".</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-27T01:47:47.553Z
Answers.Text: Also relevant: https://github.com/civicrm/civicrm-core/blob/master/tests/README.md
Answers.UserDisplayName: Tim Otten
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-27T01:46:07.050Z
Answers.LastActivityDate: 2016-08-27T01:46:07.050Z
Answers.UserDisplayName: Tim Otten
Answers.Body: <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-27T17:26:32.690Z
Answers.Text: Any steps in using buildkit?
Answers.UserDisplayName: Emeka Mbah
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-27T22:06:56.660Z
Answers.Text: @Digitlimit - I'm not sure what the question "Any steps in using buildkit?" is asking - but documentation for buildkit is here: https://buildkit.civicrm.org/#/welcome
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-27T22:09:53.853Z
Answers.Text: 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
Answers.UserDisplayName: Emeka Mbah
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-27T15:56:50.227Z
Answers.LastActivityDate: 2016-02-27T15:56:50.227Z
Answers.UserDisplayName: JohnFF
Body: <p>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.</p>
  <p>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</p>
  <p>Tutorial URL:
  <a href="https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO" rel="nofollow noreferrer">https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO</a></p>
  <p>I can't seem to be able to find these paths , mentioned below</p>
  <blockquote>
  <p><strong>Configure the PHP constant CIVICRM_DSN</strong>.   Database connection using PHP
  constant To define PHP constants for unit-testing, <strong>copy the file
  &quot;/tests/phpunit/CiviTest/civicrm.settings.local.php.txt&quot;</strong> to
  <strong>&quot;/tests/phpunit/CiviTest/civicrm.settings.local.php&quot;</strong>.
  Edit the file to include to include a line like this:</p>
  <p>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.)</p>
  <p>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.)</p>
  </blockquote>
  <p><a href="https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO" rel="nofollow noreferrer">https://wiki.civicrm.org/confluence/display/CRM/Setting+up+your+personal+testing+sandbox+HOWTO</a></p>
  <p>When I go to the root of my API extension and type :</p>
  <pre><code>civix test CRM_MyEntity_EntityAction 
  </code></pre>
  <p>I get error below which suggests I should read the tutorial above</p>
  <p><a href="https://i.sstatic.net/BPWJ4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BPWJ4.png" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-27T12:47:30.163Z
Comments.Text: Please can you post the error? Which "parts" are missing in 4.7?
Comments.UserDisplayName: JohnFF
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-27T13:55:56.510Z
Comments.Text: @JohnFF Please check updated question
Comments.UserDisplayName: Emeka Mbah
Tags: <extension><civicrm-home><civicrm-entity>
Title: API Extension PHPUnit Tests not working
ThreadText: # API Extension PHPUnit Tests not working
  
  (Asked by: username_0 on 2016-02-27)
  
  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
  
  **Tags:** extension, civicrm-home, civicrm-entity
  
  > **Comments:**
  > **username_1**: Please can you post the error? Which "parts" are missing in 4.7?  
  > **username_0**: @username_1 Please check updated question  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-08-27. Score: 1
  
  Agree with username_1 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:
  
  https://github.com/civicrm/org.civicrm.testapalooza
  https://civicrm.org/blog/totten/developers-extension-testapalooza
  
  If you haven't used civibuild, then pay particular attention to the README for org.civicrm.testapalaooza under "Setup: Option B: Manual".
  
  > **Comments:**
  > **username_2**: Also relevant: https://github.com/civicrm/civicrm-core/blob/master/tests/README.md  
  
  ---
  
  ### Answer by username_1 on 2016-02-27. Score: 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.
  
  > **Comments:**
  > **username_0**: Any steps in using buildkit?  
  > **username_3**: @Digitlimit - I'm not sure what the question "Any steps in using buildkit?" is asking - but documentation for buildkit is here: https://buildkit.civicrm.org/#/welcome  
  > **username_0**: 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  
  
  ---
  
  