Answers.Body: <p>The error message says <code>sh: 1: cv not found</code>, so the symptom here is that the <code>proc_open()</code> call is unable to find the executable <code>cv</code>.</p>
  
  <p>It looked like the place to check this should be <code>cv()</code> function in <a href="https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/CiviTest/bootstrap.php#L27" rel="nofollow noreferrer">tests/phpunit/CiviTest/bootstrap.php</a> ... but I wasn't able to get that to work.</p>
  
  <p>Having investigated, I suspect that this may be an issue in <code>\Civi\API\ExternalBatch</code>. <a href="https://github.com/civicrm/civicrm-core/blob/master/Civi/API/ExternalBatch.php#L45" rel="nofollow noreferrer">In that class's constructor</a>,</p>
  
  <pre><code>$this-&gt;env = $_ENV;
  </code></pre>
  
  <p>At this point in the tests, <code>$_ENV = ['CIVICRM_UF' =&gt; 'UnitTests']</code>. There is no path here, and the call to <code>cv</code> fails. Manually inserting a <code>PATH</code> into <code>$_ENV</code> here does restore the ability to call <code>cv</code>, but then fails with a further "malformed response" error, "Failed to determine INI file path.".</p>
  
  <p>This must be working on tests.civicrm.org, so perhaps it's a configuration issue that affects both our test environments?</p>
  
  <ul>
  <li><a href="https://github.com/civicrm/cv/issues/1" rel="nofollow noreferrer"><code>civicrm/cv#1</code> is this issue?</a></li>
  <li>Tim suggests it <a href="https://github.com/symfony/symfony/issues/18796" rel="nofollow noreferrer">may relate to Debian's default variables_order being GPCS no EGPCS</a></li>
  <li>Suggests: <a href="https://gist.github.com/totten/cf76679b4fabdae4c86e06f8c0988b23" rel="nofollow noreferrer">https://gist.github.com/totten/cf76679b4fabdae4c86e06f8c0988b23</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-15T22:18:52.493Z
Answers.LastActivityDate: 2016-12-19T01:18:45.680Z
Answers.LastEditDate: 2016-12-19T01:18:45.680Z
Answers.UserDisplayName: Chris Burgess
Body: <p>I'm QAing <a href="https://github.com/civicrm/civicrm-core/pull/9255" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/9255</a> and trying to run a couple of relevant test locally:</p>
  
  <pre><code>~/src/civicrm-buildkit/build/qa/sites/all/modules/civicrm$ tools/scripts/phpunit api_v3_JobProcessMailingTest --filter testConcurrency
  </code></pre>
  
  <p>I'm getting the following error output from each time the test uses CiviUnitTestCase::createExternalAPI to call the API:</p>
  
  <pre><code>[is_error] =&gt; 1
  [error_message] =&gt; External API returned malformed response.
  [trace] =&gt; Array
      (
          [code] =&gt; 127
          [stdout] =&gt; 
          [stderr] =&gt; sh: 1: cv: not found
  
      )
  </code></pre>
  
  <p>cv api Contact.get works as expected from the same directory.</p>
  
  <p>Any ideas on what to do next to debug? I get why the test wants to do things concurrently, but my eyes start glazing over (only a little!) when I start looking at civicrm/Civi/API/ExternalBatch.php and I'm hoping I might have overlooked something 'obvious'.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-15T20:58:26.983Z
Comments.Text: I tried doing a bit of troubleshooting, mainly in `tests/phpunit/CiviTest/bootstrap.php`, but I'm not convinced that's the right place.  In any case, this DOES work for me.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-12-17T17:55:52.333Z
Comments.Text: Hmm, [this SO answer](http://stackoverflow.com/questions/2717897/popen-fails-with-sh-command-not-found) was brought to us by the letter `^A`, which might be relevant (CiviCRM uses this character as a value separator). Asker closes with _"I would encourage anyone with a similar problem to look for hidden characters in the string used with popen()."_
Comments.UserDisplayName: Chris Burgess
Tags: <civimail><developer><testing>
Title: Can't accesss cv from CiviUnitTestCase::createExternalAPI in buildkit environment
ThreadText: # Can't accesss cv from CiviUnitTestCase::createExternalAPI in buildkit environment
  
  (Asked by: username_0 on 2016-12-15)
  
  I'm QAing https://github.com/civicrm/civicrm-core/pull/9255 and trying to run a couple of relevant test locally:
  ~/src/civicrm-buildkit/build/qa/sites/all/modules/civicrm$ tools/scripts/phpunit api_v3_JobProcessMailingTest --filter testConcurrency
  
  I'm getting the following error output from each time the test uses CiviUnitTestCase::createExternalAPI to call the API:
  [is_error] => 1
  [error_message] => External API returned malformed response.
  [trace] => Array
      (
          [code] => 127
          [stdout] => 
          [stderr] => sh: 1: cv: not found
  
      )
  
  cv api Contact.get works as expected from the same directory.
  Any ideas on what to do next to debug? I get why the test wants to do things concurrently, but my eyes start glazing over (only a little!) when I start looking at civicrm/Civi/API/ExternalBatch.php and I'm hoping I might have overlooked something 'obvious'.
  
  **Tags:** civimail, developer, testing
  
  > **Comments:**
  > **username_1**: I tried doing a bit of troubleshooting, mainly in `tests/phpunit/CiviTest/bootstrap.php`, but I'm not convinced that's the right place.  In any case, this DOES work for me.  
  > **username_2**: Hmm, [this SO answer](http://stackoverflow.com/questions/2717897/popen-fails-with-sh-command-not-found) was brought to us by the letter `^A`, which might be relevant (CiviCRM uses this character as a value separator). Asker closes with _"I would encourage anyone with a similar problem to look for hidden characters in the string used with popen()."_  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-12-15. Score: 2
  
  The error message says sh: 1: cv not found, so the symptom here is that the proc_open() call is unable to find the executable cv.
  It looked like the place to check this should be cv() function in tests/phpunit/CiviTest/bootstrap.php ... but I wasn't able to get that to work.
  Having investigated, I suspect that this may be an issue in \Civi\API\ExternalBatch. In that class's constructor,
  $this->env = $_ENV;
  
  At this point in the tests, $_ENV = ['CIVICRM_UF' => 'UnitTests']. There is no path here, and the call to cv fails. Manually inserting a PATH into $_ENV here does restore the ability to call cv, but then fails with a further "malformed response" error, "Failed to determine INI file path.".
  This must be working on tests.civicrm.org, so perhaps it's a configuration issue that affects both our test environments?
  
  civicrm/cv#1 is this issue?
  Tim suggests it may relate to Debian's default variables_order being GPCS no EGPCS
  Suggests: https://gist.github.com/totten/cf76679b4fabdae4c86e06f8c0988b23
  
  
  ---
  
  