Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell if --debug or --verbose was passed to PHPUnit in a test?

Tags:

php

phpunit

I'm doing some overloading to PHPUnit's Selenium extension that uses the CaptureEntirePageScreenshotToString function, and I would like to only print the path to the screenshot as we go only when --verbose or --debug is passed in.

For instance, phpunit --debug ./tests

Then somewhere in my code I have (this is psudo code)

if (--debug)
  echo "Screenshot: /path/to/screenshot.png

Suggestions?

like image 478
General Redneck Avatar asked Sep 26 '12 21:09

General Redneck


1 Answers

There is no PHPUnit internal API to do this. The configuration object is not accessible through the test cases directly.

You can't use PHPUnit_Util_Configuration::getInstance() as thats only the wrapper for the xml config.

My suggestion would be to just use:

if(in_array('--debug', $_SERVER['argv'], true)) {
     //Insert your debug code here.
}

Relevant classes:

  • Command Parser
  • Test Runner
like image 139
edorian Avatar answered Oct 22 '22 08:10

edorian