public function execute(InputInterface $input, OutputInterface $output) { $options = $input->getOptions(); if ($input->getArgument('test')) { $options['steps'] = true; } $suite = $input->getArgument('suite'); $test = $input->getArgument('test'); $codecept = new \Codeception\Codecept((array) $options); $suites = $suite ? array($suite) : \Codeception\Configuration::suites(); $output->writeln(\Codeception\Codecept::versionString() . "\nPowered by " . \PHPUnit_Runner_Version::getVersionString()); if ($suite and $test) { $codecept->runSuite($suite, $test); } if (!$test) { foreach ($suites as $suite) { $codecept->runSuite($suite); } } $codecept->printResult(); if (!$input->getOption('no-exit')) { if ($codecept->getResult()->failureCount() or $codecept->getResult()->errorCount()) { exit(1); } } }
public function setUp() { if (version_compare('3.6.0', PHPUnit_Runner_Version::id()) == 1) { $this->markTestSkipped('The tested class is not compatible with current version of PHPUnit.'); } $this->constraint = new Phake_PHPUnit_VerifierResultConstraintV3d6(); }
/** * Should run tests in browser * @param null $filterClass */ public function runAction($filterClass = null) { // Make sure PHPUnit is autoloaded require_once 'PHPUnit/Autoload.php'; set_time_limit(3600); $version = \PHPUnit_Runner_Version::id(); $kernel_dir = $this->container->getParameter('kernel.root_dir'); chdir($kernel_dir); // This will force the printer class to be autoloaded by Symfony, before PHPUnit tries to (and does not) find it $printerClass = 'Goutte\\DoodleBundle\\Tools\\PHPUnit\\HtmlResultPrinter'; if (!class_exists($printerClass)) { $printerClass = false; } $argv = array(); $argv[] = 'phpunit'; if ($filterClass) { $argv[] = '--filter'; $argv[] = $filterClass; } if (version_compare($version, "3.6.0") >= 0) { if ($printerClass) { $argv[] = '--printer'; $argv[] = $printerClass; } $_SERVER['argv'] = $argv; \PHPUnit_TextUI_Command::main(true); } else { ob_end_clean(); echo '<pre>'; $_SERVER['argv'] = $argv; \PHPUnit_TextUI_Command::main(false); echo '</pre>'; exit; } }
/** * @param PHPUnit_Framework_TestResult $result */ public function process(PHPUnit_Framework_TestResult $result, $minLines = 5, $minMatches = 70) { $codeCoverage = $result->getCodeCoverageInformation(); $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage); $files = array_keys($summary); $metrics = new PHPUnit_Util_Metrics_Project($files, $summary, TRUE, $minLines, $minMatches); $document = new DOMDocument('1.0', 'UTF-8'); $document->formatOutput = TRUE; $cpd = $document->createElement('pmd-cpd'); $cpd->setAttribute('version', 'PHPUnit ' . PHPUnit_Runner_Version::id()); $document->appendChild($cpd); foreach ($metrics->getDuplicates() as $duplicate) { $xmlDuplication = $cpd->appendChild($document->createElement('duplication')); $xmlDuplication->setAttribute('lines', $duplicate['numLines']); $xmlDuplication->setAttribute('tokens', $duplicate['numTokens']); $xmlFile = $xmlDuplication->appendChild($document->createElement('file')); $xmlFile->setAttribute('path', $duplicate['fileA']->getPath()); $xmlFile->setAttribute('line', $duplicate['firstLineA']); $xmlFile = $xmlDuplication->appendChild($document->createElement('file')); $xmlFile->setAttribute('path', $duplicate['fileB']->getPath()); $xmlFile->setAttribute('line', $duplicate['firstLineB']); $xmlDuplication->appendChild($document->createElement('codefragment', PHPUnit_Util_XML::prepareString(join('', array_slice($duplicate['fileA']->getLines(), $duplicate['firstLineA'] - 1, $duplicate['numLines']))))); } $this->write($document->saveXML()); $this->flush(); }
public static function checkVersion() { try { // For PHPUnit < 3.7 if (is_file('PHPUnit/Runner/Version.php') && is_readable('PHPUnit/Runner/Version.php')) { include_once 'PHPUnit/Runner/Version.php'; $actualVersion = PHPUnit_Runner_Version::id(); } elseif (method_exists('PHPUnit_Runner_Version', 'id')) { $actualVersion = PHPUnit_Runner_Version::id(); } else { // PHPUnit probably is not installed. throw new Exception(); } if (version_compare($actualVersion, self::$phpUnitMinimumVersion) < 0) { echo "\n Zurmo tests are not working with PHPUnit {$actualVersion} \n"; echo "PHPUnit version must be equal and higher then PHPUnit " . self::$phpUnitMinimumVersion . " and "; echo "lower then " . self::$phpUnitMaximumVersion . "\n"; echo "Please upgrade your PHPUnit version \n\n"; exit; } if (version_compare($actualVersion, self::$phpUnitMaximumVersion) >= 0) { echo "\n Zurmo tests are not working with PHPUnit {$actualVersion} \n"; echo "PHPUnit version must be equal and higher then PHPUnit " . self::$phpUnitMinimumVersion . " and "; echo "lower then " . self::$phpUnitMaximumVersion . "\n"; echo "Please downgrade your PHPUnit version \n\n"; exit; } return; } catch (Exception $e) { echo "You must install PHPUnit, before running tests"; exit; } }
/** * Initialize Task. * This method includes any necessary PHPUnit2 libraries and triggers * appropriate error if they cannot be found. This is not done in header * because we may want this class to be loaded w/o triggering an error. */ function init() { if (version_compare(PHP_VERSION, '5.0.3') < 0) { throw new BuildException("PHPUnit2Task requires PHP version >= 5.0.3.", $this->getLocation()); } /** * Determine PHPUnit version number */ @(include_once 'PHPUnit/Runner/Version.php'); @(include_once 'PHPUnit2/Runner/Version.php'); if (class_exists('PHPUnit_Runner_Version')) { $version = PHPUnit_Runner_Version::id(); } elseif (class_exists('PHPUnit2_Runner_Version')) { $version = PHPUnit2_Runner_Version::id(); } else { throw new BuildException("PHPUnit task depends on PHPUnit 2 or 3 package being installed.", $this->getLocation()); } if (version_compare($version, "3.0.0") >= 0) { PHPUnitUtil::$installedVersion = 3; if (version_compare($version, "3.2.0") >= 0) { PHPUnitUtil::$installedMinorVersion = 2; } } else { PHPUnitUtil::$installedVersion = 2; } /** * Other dependencies that should only be loaded when class is actually used. */ require_once 'phing/tasks/ext/phpunit/PHPUnitTestRunner.php'; require_once 'phing/tasks/ext/phpunit/BatchTest.php'; require_once 'phing/tasks/ext/phpunit/FormatterElement.php'; /** * Add some defaults to the PHPUnit filter */ if (PHPUnitUtil::$installedVersion == 3) { require_once 'PHPUnit/Framework.php'; require_once 'PHPUnit/Util/Filter.php'; // point PHPUnit_MAIN_METHOD define to non-existing method if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'PHPUnitTask::undefined'); } PHPUnit_Util_Filter::addFileToFilter('PHPUnitTask.php', 'PHING'); PHPUnit_Util_Filter::addFileToFilter('PHPUnitTestRunner.php', 'PHING'); PHPUnit_Util_Filter::addFileToFilter('phing/Task.php', 'PHING'); PHPUnit_Util_Filter::addFileToFilter('phing/Target.php', 'PHING'); PHPUnit_Util_Filter::addFileToFilter('phing/Project.php', 'PHING'); PHPUnit_Util_Filter::addFileToFilter('phing/Phing.php', 'PHING'); PHPUnit_Util_Filter::addFileToFilter('phing.php', 'PHING'); } else { require_once 'PHPUnit2/Framework.php'; require_once 'PHPUnit2/Util/Filter.php'; PHPUnit2_Util_Filter::addFileToFilter('PHPUnitTask.php'); PHPUnit2_Util_Filter::addFileToFilter('PHPUnitTestRunner.php'); PHPUnit2_Util_Filter::addFileToFilter('phing/Task.php'); PHPUnit2_Util_Filter::addFileToFilter('phing/Target.php'); PHPUnit2_Util_Filter::addFileToFilter('phing/Project.php'); PHPUnit2_Util_Filter::addFileToFilter('phing/Phing.php'); PHPUnit2_Util_Filter::addFileToFilter('phing.php'); } }
/** * @param $funcName * @throws \BadMethodCallException */ protected function validateCallable($funcName) { if (!is_callable([self::ASSERT_CLASS, $funcName])) { $m = $funcName . ' is not found in ' . self::ASSERT_CLASS . '. your phpunit version is ' . \PHPUnit_Runner_Version::id(); throw new \BadMethodCallException($m); } }
/** * Initialize Task. * This method includes any necessary PHPUnit libraries and triggers * appropriate error if they cannot be found. This is not done in header * because we may want this class to be loaded w/o triggering an error. */ public function init() { /** * Determine PHPUnit version number */ @(include_once 'PHPUnit/Runner/Version.php'); if (!class_exists('PHPUnit_Runner_Version')) { throw new BuildException("PHPUnitTask requires PHPUnit to be installed", $this->getLocation()); } $version = PHPUnit_Runner_Version::id(); if (version_compare($version, '3.6.0') < 0) { throw new BuildException("PHPUnitTask requires PHPUnit version >= 3.6.0", $this->getLocation()); } /** * Other dependencies that should only be loaded when class is actually used. */ require_once 'phing/tasks/ext/phpunit/PHPUnitTestRunner.php'; require_once 'phing/tasks/ext/phpunit/BatchTest.php'; require_once 'phing/tasks/ext/phpunit/FormatterElement.php'; /** * point PHPUnit_MAIN_METHOD define to non-existing method */ if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'PHPUnitTask::undefined'); } }
/** * Initialize Task. * This method includes any necessary PHPUnit2 libraries and triggers * appropriate error if they cannot be found. This is not done in header * because we may want this class to be loaded w/o triggering an error. */ public function init() { if (version_compare(PHP_VERSION, '5.0.3') < 0) { throw new BuildException("PHPUnitTask requires PHP version >= 5.0.3", $this->getLocation()); } /** * Determine PHPUnit version number */ @(include_once 'PHPUnit/Runner/Version.php'); $version = PHPUnit_Runner_Version::id(); if (version_compare($version, '3.2.0') < 0) { throw new BuildException("PHPUnitTask requires PHPUnit version >= 3.2.0", $this->getLocation()); } /** * Other dependencies that should only be loaded when class is actually used. */ require_once 'phing/tasks/ext/phpunit/PHPUnitTestRunner.php'; require_once 'phing/tasks/ext/phpunit/BatchTest.php'; require_once 'phing/tasks/ext/phpunit/FormatterElement.php'; /** * Add some defaults to the PHPUnit filter */ $pwd = dirname(__FILE__); require_once 'PHPUnit/Framework.php'; require_once 'PHPUnit/Util/Filter.php'; // point PHPUnit_MAIN_METHOD define to non-existing method if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'PHPUnitTask::undefined'); } $path = realpath($pwd . '/../../../'); PHPUnit_Util_Filter::addDirectoryToFilter($path); }
/** * Get PHPUnit version * @return string */ protected static function getPhpUnitVersion() { if (method_exists('\\PHPUnit_Runner_Version', 'id')) { return \PHPUnit_Runner_Version::id(); } return \PHPUnit_Runner_Version::VERSION; }
public static function get_test_config() { $config = array(); if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>=')) { $config = array_merge($config, array('dbms' => 'sqlite', 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', 'dbport' => '', 'dbname' => '', 'dbuser' => '', 'dbpasswd' => '')); } if (isset($_SERVER['PHPBB_TEST_CONFIG'])) { // Could be an absolute path $test_config = $_SERVER['PHPBB_TEST_CONFIG']; } else { $test_config = dirname(__FILE__) . '/../test_config.php'; } if (file_exists($test_config)) { include $test_config; $config = array_merge($config, array('dbms' => $dbms, 'dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, 'dbuser' => $dbuser, 'dbpasswd' => $dbpasswd, 'custom_dsn' => isset($custom_dsn) ? $custom_dsn : '')); if (isset($phpbb_functional_url)) { $config['phpbb_functional_url'] = $phpbb_functional_url; } } if (isset($_SERVER['PHPBB_TEST_DBMS'])) { $config = array_merge($config, array('dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', 'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '', 'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '', 'custom_dsn' => isset($_SERVER['PHPBB_TEST_CUSTOM_DSN']) ? $_SERVER['PHPBB_TEST_CUSTOM_DSN'] : '')); } if (isset($_SERVER['PHPBB_FUNCTIONAL_URL'])) { $config = array_merge($config, array('phpbb_functional_url' => isset($_SERVER['PHPBB_FUNCTIONAL_URL']) ? $_SERVER['PHPBB_FUNCTIONAL_URL'] : '')); } return $config; }
public function testAdapterRunsPhpunitCommandWithAlltestsFileTarget() { $adapter = new \Mutateme\Adapter\Phpunit(); $options = array('src' => dirname(__FILE__) . '/_files/phpunit2', 'tests' => dirname(__FILE__) . '/_files/phpunit2', 'base' => dirname(__FILE__) . '/_files/phpunit2', 'options' => 'AllMyTests.php'); ob_start(); $adapter->execute($options, true); $this->assertStringStartsWith(\PHPUnit_Runner_Version::getVersionString(), ob_get_clean()); }
/** * @test */ public function if_configuration_values_are_invalid_it_matches_when_exception_message_is_right_according_to_regexp() { $constraint = new ConfigurationValuesAreInvalidConstraint(new ConfigurationWithRequiredValue(), '/required[_]{1}value/', true); if (version_compare(\PHPUnit_Runner_Version::id(), '4.2.0', '<')) { $this->setExpectedException('\\InvalidArgumentException', 'does not support matching exception messages by regular expression'); } $this->assertTrue($constraint->evaluate(array(array()), '', true)); }
/** * Creates a predefined environment using the default environment * * Extending classes that have their own setUp() should call * parent::setUp() */ public function setUp() { if (self::$_assert_type_compatability === NULL) { self::$_assert_type_compatability = version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '<='); } $this->_helpers = new Kohana_Unittest_Helpers(); $this->setEnvironment($this->environmentDefault); }
private function getConstraint() { if (version_compare('3.6.0', PHPUnit_Runner_Version::id()) == 1) { return new Phake_PHPUnit_VerifierResultConstraint(); } else { return new Phake_PHPUnit_VerifierResultConstraintV3d6(); } }
/** * Returns the current version of PHPUnit. * * @return string */ public static function id() { if (self::$version === NULL) { $version = new SebastianBergmann\Version('3.8', __DIR__); self::$version = $version->getVersion(); } return self::$version; }
public function prepare() { if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0beta1', '>=')) { require_once 'PHPUnit/Autoload.php'; } else { require_once 'PHPUnit/Framework.php'; } }
/** * InvalidIfRefererDoesNotMatchHost * * @return void */ public function testInvalidIfRefererDoesNotMatchHost() { $GLOBALS['_SERVER']['HTTP_USER_AGENT'] = 'PHPUnit/' . \PHPUnit_Runner_Version::id(); $GLOBALS['_SERVER']['HTTP_REFERER'] = 'http://example.org'; $GLOBALS['_SERVER']['HTTP_HOST'] = 'http://foo.bar'; $validationResult = $this->sut->validate($this->contactMock); $this->assertEquals(1400451586, $validationResult->getFirstError()->getCode()); }
/** * Overridden function to cover differences between PHPUnit 3.5 and 3.6. * Intentionally made final so people have to use match() from now on. * match() should be abstract really, but isn't, the usual PHPUnit quality... * * @param mixed The item to evaluate. * @param string Additional information about the test (3.6+). * @param bool Whether to return a result or throw an exception (3.6+). * * @author David Zülke <*****@*****.**> * @since 1.0.7 */ public function evaluate($other, $description = '', $returnResult = false) { if (version_compare(PHPUnit_Runner_Version::id(), '3.6', '<')) { return $this->matches($other); } else { return parent::evaluate($other, $description, $returnResult); } }
public function testAdapterRunsPhpunitCommandWithAlltestsFileTarget() { $runner = m::mock('\\Mutagenesis\\Runner\\Base'); $runner->shouldReceive('getOptions')->andReturn(array('src' => dirname(__FILE__) . '/_files/phpunit2', 'tests' => dirname(__FILE__) . '/_files/phpunit2', 'base' => dirname(__FILE__) . '/_files/phpunit2', 'cache' => sys_get_temp_dir(), 'clioptions' => array(), 'constraint' => 'AllTests.php')); $runner->shouldReceive(array('getBootstrap' => null, 'getTimeout' => 1200)); $adapter = new \Mutagenesis\Adapter\Phpunit(); $result = $adapter->runTests($runner, true, true); $this->assertStringStartsWith(\PHPUnit_Runner_Version::getVersionString(), $result[1]['stdout']); }
public static function assertType($x, $y) { #global $phpunit_version; if (version_compare(PHPUnit_Runner_Version::id(), '3.5') < 0) { return PHPUnit_Framework_TestCase::assertType($x, $y); } else { return PHPUnit_Framework_TestCase::assertInternalType($x, $y); } }
public function setUp() { error_reporting(E_ALL | E_STRICT); $_SERVER['REQUEST_URI'] = ''; $this->router = new Zend_Controller_RewriteRouter(); $this->router->setRewriteBase('/'); $this->dispatcher = new Zend_Controller_Dispacher_Mock(); $this->version = version_compare(PHPUnit_Runner_Version::id(), '3.0.0alpha11') >= 0 ? 3 : 2; }
public function get_phpunit_version($as_string = false) { $ver = PHPUnit_Runner_Version::id(); if (!$as_string) { $ver_array = explode('.', $ver); $ver_array[0] .= '.'; $ver = (double) implode('', $ver_array); } return $ver; }
public function testThrow2() { if (!method_exists('PHPUnit_Runner_Version', 'id') || version_compare(\PHPUnit_Runner_Version::id(), '5.2.0', '<')) { $this->setExpectedException('\\Exception', 'error'); } else { $this->expectException('\\Exception', 'error'); } $t = new \Test\TryTest(); $t->testThrow2(); }
protected function getProductManager($qbCallback) { if (version_compare(\PHPUnit_Runner_Version::id(), '5.0.0', '>=')) { $this->markTestSkipped('Not compatible with PHPUnit 5.'); } $em = EntityManagerMockFactory::create($this, $qbCallback, array('sku', 'slug', 'name')); $registry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $registry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($em)); return new ProductManager('Sonata\\PageBundle\\Entity\\BaseProduct', $registry); }
public function testgetPostalXWindow() { if (headers_sent() || version_compare(PHPUnit_Runner_Version::id(), '3.3.0', '<')) { $this->markTestSkipped('phpunit version < 3.3.0 cant cope with headers'); } ob_start(); $this->_uit->getPostalXWindow(); $html = ob_get_clean(); $this->assertGreaterThan(100, strlen($html)); }
/** * Creates a predefined environment using the default environment * * Extending classes that have their own setUp() should call * parent::setUp() */ public function setUp() { if (self::$_assert_type_compatability === NULL) { if (!class_exists('PHPUnit_Runner_Version')) { require_once 'PHPUnit/Runner/Version.php'; } self::$_assert_type_compatability = version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '<='); } $this->_helpers = new Unittest_Helpers(); $this->setEnvironment($this->environmentDefault); }
public function formattedToNumberProvider() { if (!extension_loaded('intl')) { if (version_compare(\PHPUnit_Runner_Version::id(), '3.8.0-dev') === 1) { $this->markTestSkipped('ext/intl not enabled'); } else { return array(array()); } } return array(array('en_US', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE, '1,234,567.891', 1234567.891), array('de_DE', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE, '1.234.567,891', 1234567.891), array('ru_RU', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE, '1 234 567,891', 1234567.891)); }
/** * Returns the current version of PHPUnit. * * @return string */ public static function id() { if (self::$pharVersion !== null) { return self::$pharVersion; } if (self::$version === null) { $version = new SebastianBergmann\Version('4.8.12', dirname(dirname(__DIR__))); self::$version = $version->getVersion(); } return self::$version; }
public function basicProvider() { if (!extension_loaded('intl')) { if (version_compare(\PHPUnit_Runner_Version::id(), '3.8.0-dev') === 1) { $this->markTestSkipped('ext/intl not enabled'); } else { return array(array()); } } return array(array('May 30, 2013', true, array('locale' => 'en', 'dateType' => \IntlDateFormatter::MEDIUM, 'timeType' => \IntlDateFormatter::NONE)), array('30.Mai.2013', true, array('locale' => 'de', 'dateType' => \IntlDateFormatter::MEDIUM, 'timeType' => \IntlDateFormatter::NONE)), array('30 Mei 2013', true, array('locale' => 'nl', 'dateType' => \IntlDateFormatter::MEDIUM, 'timeType' => \IntlDateFormatter::NONE)), array('May 38, 2013', false, array('locale' => 'en', 'dateType' => \IntlDateFormatter::FULL, 'timeType' => \IntlDateFormatter::NONE)), array('Dienstag, 28. Mai 2013', true, array('locale' => 'de', 'dateType' => \IntlDateFormatter::FULL, 'timeType' => \IntlDateFormatter::NONE)), array('Maandag 28 Mei 2013', true, array('locale' => 'nl', 'dateType' => \IntlDateFormatter::FULL, 'timeType' => \IntlDateFormatter::NONE)), array('0:00', true, array('locale' => 'nl', 'dateType' => \IntlDateFormatter::NONE, 'timeType' => \IntlDateFormatter::SHORT)), array('01:01', true, array('locale' => 'nl', 'dateType' => \IntlDateFormatter::NONE, 'timeType' => \IntlDateFormatter::SHORT)), array('01:01:01', true, array('locale' => 'nl', 'dateType' => \IntlDateFormatter::NONE, 'timeType' => \IntlDateFormatter::MEDIUM)), array('01:01:01 +2', true, array('locale' => 'nl', 'dateType' => \IntlDateFormatter::NONE, 'timeType' => \IntlDateFormatter::LONG)), array('03:30:42 am +2', true, array('locale' => 'en', 'dateType' => \IntlDateFormatter::NONE, 'timeType' => \IntlDateFormatter::LONG))); }