title: How to Determine if PHPUnit Tests are Running?
body: <p>I currently have a problem that I have to work around in legacy code to get our interaction with a PHP Extension to work properly (<a href="https://web.archive.org/web/20130305040907/http://stackoverflow.com/questions/10235283/phpunit-singleton-testing-or-skeleton-test-creation-fails-with-error" rel="noreferrer">Singleton Testing Question</a>).</p>
  
  <p>As such, I do not want to execute this code when running our normal production code with the application.  Therefore, I need to check in regular PHP code if the code being executed is being executed as part of a test or not.</p>
  
  <p>Any suggestions on how to determine this?  I thought about a defined variable tied to the presence of the test files themselves (we do not ship the tests to customers) but our developers need the Extension to work normally, while the CI server needs to run the tests.</p>
  
  <p>Would a Global set in the PHPUnit.xml file be recommended?  Other thoughts?</p>