/** * JBZooPHPUnit_Coverage constructor. * @SuppressWarnings(PHPMD.Superglobals) */ public function __construct() { if (Env::hasXdebug() && isset($_REQUEST['jbzoo-phpunit'])) { $cmsType = $_REQUEST['jbzoo-phpunit-type']; $testName = $_REQUEST['jbzoo-phpunit-test']; $this->_covRoot = realpath(__DIR__ . '/../..'); $this->_covDir = realpath($this->_covRoot . '/src'); $this->_covHash = implode('_', [md5(serialize($_REQUEST)), mt_rand(0, 100000000)]); $this->_covResult = realpath($this->_covRoot . '/build/coverage_cov') . '/' . $cmsType . '-' . $testName . '.cov'; $covFilter = new PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_covDir); $this->_coverage = new PHP_CodeCoverage(null, $covFilter); } }
/** * CovCatcher constructor. * @param string $testName * @param array $options * @throws Exception */ public function __construct($testName = null, array $options = array()) { if (!class_exists('\\JBZoo\\Data\\Data')) { throw new Exception('jbzoo/data required for CovCatcher'); } if (!class_exists('\\JBZoo\\Utils\\Env')) { throw new Exception('jbzoo/utils required for CovCatcher'); } $this->_initConfig($options); $this->_hash = $this->_getPrefix($testName) . '_' . md5(serialize($this->_config->getArrayCopy()) . '|' . $testName); if (Env::hasXdebug()) { $covFilter = new \PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_config->get('src')); $this->_coverage = new \PHP_CodeCoverage(null, $covFilter); } }
public function testInclude() { $catcher = new CovCatcher(null, array('src' => PROJECT_TESTS . '/fixtures/includes', 'xml' => true, 'cov' => true, 'html' => true)); ob_start(); $return = $catcher->includeFile(PROJECT_TESTS . '/fixtures/includes/cov-catcher.php'); $echo = ob_get_contents(); ob_end_clean(); isSame(5, $return); isSame('Some text message', $echo); unset($catcher); // call destructor if (Env::hasXdebug()) { isDir(PROJECT_BUILD . '/coverage_cov'); isDir(PROJECT_BUILD . '/coverage_html'); isDir(PROJECT_BUILD . '/coverage_xml'); } }
/** * @covers JBZoo\Utils\Env::hasXdebug * @uses JBZoo\Utils\Env::isHHVM * @uses JBZoo\Utils\Env::isPHP */ public function testXdebugCanBeDetected() { $this->assertInternalType('boolean', Env::hasXdebug()); }