doRun() public method

public doRun ( PHPUnit_Framework_Test $suite, array $arguments = [], boolean $exit = true ) : PHPUnit_Framework_TestResult
$suite PHPUnit_Framework_Test
$arguments array
$exit boolean
return PHPUnit_Framework_TestResult
 public static function dispatch($arguments = array())
 {
     $GLOBALS['__PHPUNIT_BOOTSTRAP'] = dirname(__FILE__) . '/templates/AgaviBootstrap.tpl.php';
     $suites = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.testing_dir') . '/config/suites.xml'));
     $master_suite = new AgaviTestSuite('Master');
     if (!empty($arguments['include-suite'])) {
         $names = explode(',', $arguments['include-suite']);
         unset($arguments['include-suite']);
         foreach ($names as $name) {
             if (empty($suites[$name])) {
                 throw new InvalidArgumentException(sprintf('Invalid suite name %1$s.', $name));
             }
             $master_suite->addTest(self::createSuite($name, $suites[$name]));
         }
     } else {
         $excludes = array();
         if (!empty($arguments['exclude-suite'])) {
             $excludes = explode(',', $arguments['exclude-suite']);
             unset($arguments['exclude-suite']);
         }
         foreach ($suites as $name => $suite) {
             if (!in_array($name, $excludes)) {
                 $master_suite->addTest(self::createSuite($name, $suite));
             }
         }
     }
     $runner = new PHPUnit_TextUI_TestRunner();
     $runner->doRun($master_suite, $arguments);
 }
Exemplo n.º 2
0
 public function main()
 {
     if (!is_dir(realpath($this->testdirectory))) {
         throw new BuildException("NativePHPUnitTask requires a Test Directory path given, '" . $this->testdirectory . "' given.");
     }
     set_include_path(realpath($this->testdirectory) . PATH_SEPARATOR . get_include_path());
     $printer = new NativePhpunitPrinter();
     $arguments = array('configuration' => $this->configuration, 'coverageClover' => $this->coverageClover, 'junitLogfile' => $this->junitlogfile, 'printer' => $printer);
     require_once "PHPUnit/TextUI/TestRunner.php";
     $runner = new PHPUnit_TextUI_TestRunner();
     $suite = $runner->getTest($this->test, $this->testfile, true);
     try {
         $result = $runner->doRun($suite, $arguments);
         /* @var $result PHPUnit_Framework_TestResult */
         if ($this->haltonfailure && $result->failureCount() > 0 || $this->haltonerror && $result->errorCount() > 0) {
             throw new BuildException("PHPUnit: " . $result->failureCount() . " Failures and " . $result->errorCount() . " Errors, " . "last failure message: " . $printer->getMessages());
         }
         $this->log("PHPUnit Success: " . count($result->passed()) . " tests passed, no " . "failures (" . $result->skippedCount() . " skipped, " . $result->notImplementedCount() . " not implemented)");
         // Hudson for example doesn't like the backslash in class names
         if (file_exists($this->coverageClover)) {
             $this->log("Generated Clover Coverage XML to: " . $this->coverageClover);
             $content = file_get_contents($this->coverageClover);
             $content = str_replace("\\", ".", $content);
             file_put_contents($this->coverageClover, $content);
             unset($content);
         }
     } catch (\Exception $e) {
         throw new BuildException("NativePhpunitTask failed: " . $e->getMessage());
     }
 }
Exemplo n.º 3
0
 /**
  * Uses a random test suite to randomize the given test suite, and in case that no printer
  * has been selected, uses printer that shows the random seed used to randomize.
  * 
  * @param  PHPUnit_Framework_Test $suite     TestSuite to execute
  * @param  array                  $arguments Arguments to use
  */
 public function doRun(\PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['order'])) {
         $this->addPrinter($arguments);
         $randomizer = new Randomizer();
         $randomizer->randomizeTestSuite($suite, $arguments['seed']);
     }
     return parent::doRun($suite, $arguments);
 }
 protected function execute($arguments = array(), $options = array())
 {
     //    $initTask = new sfPhpunitInitTask($this->dispatcher, $this->formatter);
     //    $initTask->run();
     chdir(sfConfig::get('sf_root_dir'));
     shell_exec('./symfony phpunit:init');
     $path = $arguments['test'];
     sfBasePhpunitTestSuite::setProjectConfiguration($this->configuration);
     $runner = new PHPUnit_TextUI_TestRunner();
     $runner->doRun(sfPhpunitSuiteLoader::factory($path)->getSuite());
 }
 /**
  * @param  PHPUnit_Framework_Test|ReflectionClass $test
  * @param  array                               $arguments
  * @return PHPUnit_Framework_TestResult
  * @throws PHPUnit_Framework_Exception
  */
 public static function run($test, array $arguments = array())
 {
     if ($test instanceof ReflectionClass) {
         $test = new PHPUnit_Framework_TestSuite($test);
     }
     if ($test instanceof PHPUnit_Framework_Test) {
         $aTestRunner = new PHPUnit_TextUI_TestRunner();
         return $aTestRunner->doRun($test, $arguments);
     } else {
         throw new PHPUnit_Framework_Exception('No test case or test suite found.');
     }
 }
Exemplo n.º 6
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array				  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(\PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof \PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new ResultPrinter(NULL, !$arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     // supress the version string if we're not verbose
     if (!$arguments['verbose']) {
         self::$versionStringPrinted = true;
     }
     return parent::doRun($suite, $arguments);
 }
Exemplo n.º 7
0
 public function run(rex_test_locator $locator, $colors = false)
 {
     $suite = new PHPUnit_Framework_TestSuite();
     // disable backup of globals, since we have some rex_sql objectes referenced from variables in global space.
     // PDOStatements are not allowed to be serialized
     $suite->setBackupGlobals(false);
     $suite->addTestFiles($locator->getIterator());
     rex_error_handler::unregister();
     $runner = new PHPUnit_TextUI_TestRunner();
     $backtrace = debug_backtrace(false);
     array_unshift($backtrace, ['file' => __FILE__, 'line' => __LINE__ + 3]);
     $runner->setPrinter(new rex_tests_result_printer($backtrace, $colors));
     $result = $runner->doRun($suite);
     rex_error_handler::register();
     return $result;
 }
Exemplo n.º 8
0
 /**
  * Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager
  *
  * @param PHPUnit_Framework_Test $suite
  * @param array $arguments
  * @return void
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     if (isset($arguments['printer'])) {
         self::$versionStringPrinted = true;
     }
     $fixture = $this->_getFixtureManager($arguments);
     foreach ($suite->getIterator() as $test) {
         if ($test instanceof CakeTestCase) {
             $fixture->fixturize($test);
             $test->fixtureManager = $fixture;
         }
     }
     $return = parent::doRun($suite, $arguments);
     $fixture->shutdown();
     return $return;
 }
Exemplo n.º 9
0
Arquivo: run.php Projeto: jo-m/ecamp3
 private static function runTest(PHPUnit_Framework_TestSuite $test, $arguments)
 {
     $test->setName('eCamp UnitTests');
     global $doConvertErrorToExceptions;
     $doConvertErrorToExceptions = true;
     // Create a xml listener object
     $listener = new PHPUnit_Util_Log_JUnit();
     // Create TestResult object and pass the xml listener to it
     $testResult = new PHPUnit_Framework_TestResult();
     $testResult->addListener($listener);
     $arguments['printer'] = new SilentTestListener();
     $runner = new PHPUnit_TextUI_TestRunner();
     $runner->doRun($test, $arguments);
     // Run the TestSuite
     $result = $test->run($testResult);
     // Get the results from the listener
     $xml_result = $listener->getXML();
     return $xml_result;
     $doConvertErrorToExceptions = false;
 }
Exemplo n.º 10
0
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $handlesArguments = $arguments;
     $this->handleConfiguration($handlesArguments);
     $this->_retryOnError = $handlesArguments['retryOnError'];
     if (!$handlesArguments['noProgress'] && file_exists('/www/testtimes')) {
         $expectedTimes = array();
         $unknownTimes = 0;
         $tests = $suite->getFilteredTests($handlesArguments['filter'], $handlesArguments['groups'], $handlesArguments['excludeGroups']);
         foreach ($tests as $test) {
             $app = Kwf_Registry::get('config')->application->id;
             $f = "/www/testtimes/{$app}/{$test->toString()}";
             if (isset($expectedTimes[$test->toString()])) {
                 throw new Kwf_Exception("same test exists twice?!");
             }
             if (file_exists($f)) {
                 $expectedTimes[$test->toString()] = (double) file_get_contents($f);
             } else {
                 if ($test instanceof PHPUnit_Extensions_SeleniumTestCase) {
                     $expectedTimes[$test->toString()] = 15;
                 } else {
                     $expectedTimes[$test->toString()] = 1;
                 }
                 $unknownTimes++;
             }
         }
         if (!$expectedTimes || $unknownTimes / count($expectedTimes) > 0.2) {
             $expectedTimes = array();
         }
         $printer = new Kwf_Test_ProgressResultPrinter($expectedTimes, null, $handlesArguments['verbose'], true);
         $this->setPrinter($printer);
     } else {
         if ($handlesArguments['verbose']) {
             $printer = new Kwf_Test_VerboseResultPrinter(null, true);
             $this->setPrinter($printer);
         }
     }
     return parent::doRun($suite, $arguments);
 }
Exemplo n.º 11
0
 /**
  * Run the tests 
  *
  * @param	array		$arguments		arguments, options, for the PHPUnit::TestRunner 
  */
 public function runHtml($arguments = array())
 {
     try {
         echo '<pre>';
         $runner = new PHPUnit_TextUI_TestRunner();
         $result = $runner->doRun($this->suite, $arguments);
         if (isset($arguments['reportDirectory'])) {
             echo 'Code covarage reports can be found ';
             echo '<a href="', str_replace(TESTS_ROOT . DS, '', $arguments['reportDirectory']), '">here</a>.';
         }
         echo '</pre>';
     } catch (Exception $e) {
         throw new RuntimeException("Could not create and run test suite: {$e->getMessage()}");
     }
     if ($result->wasSuccessful()) {
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     } else {
         if ($result->errorCount() > 0) {
             exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
         } else {
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     }
 }
 /** Initialize the PHPUnit test runner and run tests.
  *
  * @param string[] $options
  *
  * @return void
  */
 private function _doRunTests(array $options)
 {
     if (empty($options['plugin'])) {
         $basedir = null;
     } else {
         try {
             /* @var $config sfPluginConfiguration */
             /** @noinspection PhpUndefinedMethodInspection */
             $config = $this->configuration->getPluginConfiguration($options['plugin']);
         } catch (InvalidArgumentException $e) {
             throw new sfException(sprintf('Plugin "%s" does not exist or is not enabled.', $options['plugin']));
         }
         $basedir = implode(DIRECTORY_SEPARATOR, array($config->getRootDir(), 'test', ''));
         unset($options['plugin']);
     }
     if ($files = $this->_findTestFiles($this->_type, (array) $this->_paths, $basedir)) {
         /** @noinspection PhpIncludeInspection */
         require_once 'PHPUnit' . DIRECTORY_SEPARATOR . 'TextUI' . DIRECTORY_SEPARATOR . 'TestRunner.php';
         $Runner = new PHPUnit_TextUI_TestRunner();
         $Suite = new PHPUnit_Framework_TestSuite(ucfirst($this->name) . ' Tests');
         $Suite->addTestFiles($files);
         /* Inject the command application controller so that it is accessible to
          *  test cases.
          */
         Test_Case::setController($this->commandApplication);
         /* Ignition... */
         try {
             $Runner->doRun($Suite, $options);
         } catch (PHPUnit_Framework_Exception $e) {
             $this->logSection('phpunit', $e->getMessage());
         }
     } else {
         $this->logSection('phpunit', 'No tests found.');
     }
 }
Exemplo n.º 13
0
#!/usr/bin/env php
<?php 
chdir(__DIR__);
$returnStatus = null;
passthru('composer install', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}
require 'vendor/autoload.php';
$phpcsCLI = new PHP_CodeSniffer_CLI();
$phpcsArguments = ['standard' => ['PSR1'], 'files' => ['src', 'tests', 'build.php'], 'warningSeverity' => 0];
$phpcsViolations = $phpcsCLI->process($phpcsArguments);
if ($phpcsViolations > 0) {
    exit(1);
}
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
$phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration];
$testRunner = new PHPUnit_TextUI_TestRunner();
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
if (!$result->wasSuccessful()) {
    exit(1);
}
$cloverCoverage = new PHP_CodeCoverage_Report_Clover();
file_put_contents('clover.xml', $cloverCoverage->process($result->getCodeCoverage()));
$coverageFactory = new PHP_CodeCoverage_Report_Factory();
$coverageReport = $coverageFactory->create($result->getCodeCoverage());
if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) {
    file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
    exit(1);
}
echo "Code coverage was 100%\n";
Exemplo n.º 14
0
        echo "-> running standalone test units {$entry}\n";
        try {
            $suite = createTestSuiteForFile($entry);
            $runner = new PHPUnit_TextUI_TestRunner();
            $runner->doRun($suite);
        } catch (Exception $e) {
            echo "Exception during execution of {$entry}: " . $e->getMessage() . "\n\n";
        }
    }
    exit(0);
}
$alltests = new PHPUnit_Framework_TestSuite();
foreach (new DirectoryIterator(dirname(__FILE__)) as $f) {
    if ($f->isDot() || !$f->isFile()) {
        continue;
    }
    if (preg_match('/(.*?Test).php$/', $f->getFileName())) {
        $alltests->addTestSuite(createTestSuiteForFile($f->getPathName()));
    }
}
$runner = new PHPUnit_TextUI_TestRunner();
$runner->doRun($alltests);
function createTestSuiteForFile($path)
{
    require_once $path;
    $classname = basename($path, '.php');
    if (version_compare(PHP_VERSION, '5.3', '>=') && __NAMESPACE__) {
        $classname = __NAMESPACE__ . '\\' . $classname;
    }
    return new PHPUnit_Framework_TestSuite($classname);
}
Exemplo n.º 15
0
+----------------------------------------------------------------------+
|                                                                      |
| Licensed under the Apache License, Version 2.0 (the "License"); you  |
| may not use this file except in compliance with the License. You may |
| obtain a copy of the License at                                      |
| http://www.apache.org/licenses/LICENSE-2.0                           |
|                                                                      |
| Unless required by applicable law or agreed to in writing, software  |
| distributed under the License is distributed on an "AS IS" BASIS,    |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
| implied. See the License for the specific language governing         |
| permissions and limitations under the License.                       |
+----------------------------------------------------------------------+
| Author: Matthew Peters                                               |
+----------------------------------------------------------------------+
*/
/**********************************************************
* Get a TestRunner
**********************************************************/
require_once "PHPUnit/TextUI/TestRunner.php";
$aTestRunner = new PHPUnit_TextUI_TestRunner();
/**********************************************************
* Get our test suite
/**********************************************************/
require_once 'TestSuite.php';
$suite = SCA_TestSuite::suite();
/**********************************************************
* Run it
/**********************************************************/
$result = $aTestRunner->doRun($suite);
Exemplo n.º 16
0
 /**
  */
 public static function main($exit = TRUE)
 {
     $arguments = self::handleArguments();
     $runner = new PHPUnit_TextUI_TestRunner();
     if (is_object($arguments['test']) && $arguments['test'] instanceof PHPUnit_Framework_Test) {
         $suite = $arguments['test'];
     } else {
         $suite = $runner->getTest($arguments['test'], $arguments['testFile'], $arguments['syntaxCheck']);
     }
     if ($suite->testAt(0) instanceof PHPUnit_Framework_Warning && strpos($suite->testAt(0)->getMessage(), 'No tests found in class') !== FALSE) {
         require_once 'PHPUnit/Util/Skeleton/Test.php';
         if (isset($arguments['bootstrap'])) {
             require_once $arguments['bootstrap'];
         }
         $skeleton = new PHPUnit_Util_Skeleton_Test($arguments['test'], $arguments['testFile']);
         $result = $skeleton->generate(TRUE);
         if (!$result['incomplete']) {
             eval(str_replace(array('<?php', '?>'), '', $result['code']));
             $suite = new PHPUnit_Framework_TestSuite($arguments['test'] . 'Test');
         }
     }
     if ($arguments['listGroups']) {
         PHPUnit_TextUI_TestRunner::printVersionString();
         print "Available test group(s):\n";
         foreach ($suite->getGroups() as $group) {
             print " - {$group}\n";
         }
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     }
     try {
         $result = $runner->doRun($suite, $arguments);
     } catch (Exception $e) {
         throw new RuntimeException('Could not create and run test suite: ' . $e->getMessage());
     }
     if ($exit) {
         if ($result->wasSuccessful()) {
             exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
         } else {
             if ($result->errorCount() > 0) {
                 exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
             } else {
                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
             }
         }
     }
 }
Exemplo n.º 17
0
$options = array('coverage-html' => null, 'filter' => null, 'exclude-group' => null, 'group' => null, 'verbose' => false);
$options = array_merge($options, getopt('', array('help', 'filter:', 'coverage-html:', 'exclude-group:', 'group:', 'verbose')));
$help = array_key_exists('help', $options);
if ($help) {
    echo $usage;
    exit;
}
$config = array();
$groups = $options['group'] ? explode(',', $options['group']) : null;
$args = array('reportDirectory' => $options['coverage-html'], 'coverageHtml' => $options['coverage-html'], 'filter' => $options['filter'], 'excludeGroups' => explode(',', $options['exclude-group']), 'groups' => $groups, 'strict' => true, 'processIsolation' => false, 'backupGlobals' => false, 'backupStaticAttributes' => false, 'convertErrorsToExceptions' => true, 'convertNoticesToExceptions' => true, 'convertWarningsToExceptions' => true, 'addUncoveredFilesFromWhitelist' => true, 'processUncoveredFilesFromWhitelist' => true, 'verbose' => true);
$suite = new PHPUnit_Framework_TestSuite();
suite_add_dir($suite, $basePath . '/test/');
$filter = new PHP_CodeCoverage_Filter();
$filter->addDirectoryToWhitelist($basePath . '/lib/', '.php');
$runner = new PHPUnit_TextUI_TestRunner(null, $filter);
$runner->doRun($suite, $args);
function suite_add_dir($suite, $dir)
{
    $iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY);
    foreach ($iter as $item) {
        foreach (require_tests($item) as $class) {
            $suite->addTest(new PHPUnit_Framework_TestSuite($class));
        }
    }
}
function require_tests($file)
{
    static $cache = array();
    if (!preg_match("/Test\\.php\$/", $file)) {
        return array();
    }
Exemplo n.º 18
0
<?php

$basePath = __DIR__;
$testPath = __DIR__ . '/test';
require $basePath . '/vendor/autoload.php';
require $testPath . '/lib/TestCase.php';
require $testPath . '/lib/LanguageAgnosticTest.php';
require $testPath . '/lib/PythonPortedTest.php';
$options = array('filter' => null);
$options = array_merge($options, getopt('', array('filter:')));
$pyTestFile = $basePath . '/py/testcases.docopt';
if (!file_exists($pyTestFile)) {
    die("Please ensure you have loaded the git submodules\n");
}
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTest(new PHPUnit_Framework_TestSuite('Docopt\\Test\\PythonPortedTest'));
$suite->addTest(Docopt\Test\LanguageAgnosticTest::createSuite($pyTestFile));
$runner = new PHPUnit_TextUI_TestRunner();
$runner->doRun($suite, array('filter' => $options['filter'], 'strict' => true));
 /**
  * @return PHPUnit_Framework_TestResult
  */
 protected function runTests($suite)
 {
     $arguments = sfConfig::get('sf_phpunit_arguments', array());
     $runner = new PHPUnit_TextUI_TestRunner();
     return $runner->doRun($suite, $arguments);
 }
 private static function runTest(PHPUnit_Framework_TestSuite $test, $filename, $arguments)
 {
     set_exception_handler(null);
     try {
         if (isset($arguments['loader'])) {
             $runner = new PHPUnit_TextUI_TestRunner($arguments['loader']);
         } else {
             $runner = new PHPUnit_TextUI_TestRunner();
         }
         $arguments['printer'] = new SimpleTestListener($filename);
         $result = $runner->doRun($test, $arguments);
     } catch (Exception $e) {
         myExceptionHandler($e);
     }
     restore_exception_handler();
 }
Exemplo n.º 21
0
 /**
  * Dispatch the test run.
  *
  * @param      array An array of arguments configuring PHPUnit behavior.
  * @param      bool  Whether exit() should be called with an appropriate shell
  *                   exit status to indicate success or failures/errors.
  *
  * @return     PHPUnit_Framework_TestResult The PHPUnit result object.
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @author     David Zülke <*****@*****.**>
  * @since      1.0.0
  * @deprecated 1.1.0 Use AgaviPhpUnitCli
  */
 public static function dispatch($arguments = array(), $exit = true)
 {
     $suites = (include AgaviConfigCache::checkConfig(AgaviConfig::get('core.testing_dir') . '/config/suites.xml'));
     $master_suite = new AgaviTestSuite('Master');
     if (!empty($arguments['include-suite'])) {
         $names = explode(',', $arguments['include-suite']);
         unset($arguments['include-suite']);
         foreach ($names as $name) {
             if (empty($suites[$name])) {
                 throw new InvalidArgumentException(sprintf('Invalid suite name %1$s.', $name));
             }
             $master_suite->addTest(self::createSuite($name, $suites[$name]));
         }
     } else {
         $excludes = array();
         if (!empty($arguments['exclude-suite'])) {
             $excludes = explode(',', $arguments['exclude-suite']);
             unset($arguments['exclude-suite']);
         }
         foreach ($suites as $name => $suite) {
             if (!in_array($name, $excludes)) {
                 $master_suite->addTest(self::createSuite($name, $suite));
             }
         }
     }
     if (version_compare(PHPUnit_Runner_Version::id(), '3.6', '<')) {
         // PHP_CodeCoverage_Filter is a singleton
         $runner = new PHPUnit_TextUI_TestRunner();
     } else {
         // PHP_CodeCoverage_Filter instance must be passed to the test runner
         $runner = new PHPUnit_TextUI_TestRunner(null, self::$codeCoverageFilter);
     }
     $result = $runner->doRun($master_suite, $arguments);
     if ($exit) {
         // bai
         exit(self::getExitStatus($result));
     } else {
         // return result so calling code can use it
         return $result;
     }
 }
<?php

require_once 'AllTestPhpUnit.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
$runner = new PHPUnit_TextUI_TestRunner();
$suite = AllTestPhpUnit::suite();
$result = $runner->doRun($suite);
// Check that we are still E_STRICT
if (error_reporting() !== (E_ALL | E_STRICT)) {
    echo "Warning: E_STRICT compliance was turned off during tests.\n";
}
 /**
  * @access public
  * @static
  */
 public static function main()
 {
     $arguments = self::handleArguments();
     $runner = new PHPUnit_TextUI_TestRunner();
     if (is_object($arguments['test']) && $arguments['test'] instanceof PHPUnit_Framework_Test) {
         $suite = $arguments['test'];
     } else {
         $suite = $runner->getTest($arguments['test'], $arguments['testFile'], $arguments['syntaxCheck']);
     }
     if ($suite->testAt(0) instanceof PHPUnit_Framework_Warning && strpos($suite->testAt(0)->getMessage(), 'No tests found in class') !== FALSE) {
         $skeleton = new PHPUnit_Util_Skeleton($arguments['test'], $arguments['testFile']);
         $result = $skeleton->generate(TRUE);
         if (!$result['incomplete']) {
             eval(str_replace(array('<?php', '?>'), '', $result['code']));
             $suite = new PHPUnit_Framework_TestSuite($arguments['test'] . 'Test');
         }
     }
     try {
         $result = $runner->doRun($suite, $arguments);
     } catch (Exception $e) {
         throw new RuntimeException('Could not create and run test suite: ' . $e->getMessage());
     }
     if ($result->wasSuccessful()) {
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     } else {
         if ($result->errorCount() > 0) {
             exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
         } else {
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     }
 }
Exemplo n.º 24
0
 public function execute($config_group = 'default')
 {
     ini_set('memory_limit', '512M');
     $this->_get_phpunit_options($config_group);
     require_once Kohana::find_file('vendor', 'PHPUnit/Util/Filter');
     require_once Kohana::find_file('vendor', 'PHPUnit/Framework/TestSuite');
     require_once Kohana::find_file('vendor', 'PHPUnit/TextUI/TestRunner');
     $this->_whitelist();
     $this->_blacklist();
     // We want all warnings so PHPUnit can take care of them.
     error_reporting(E_ALL | E_STRICT);
     // Hand control of errors and exceptions to PHPUnit
     restore_exception_handler();
     restore_error_handler();
     // Turn off the output biffer.
     ob_end_flush();
     //define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');
     $this->_get_test_suite();
     $arguments = $this->_phpunit_options;
     $runner = new PHPUnit_TextUI_TestRunner();
     if (is_object($arguments['test']) and $arguments['test'] instanceof PHPUnit_Framework_Test) {
         $suite = $arguments['test'];
     } else {
         $suite = $runner->getTest($arguments['test'], $arguments['testFile'], $arguments['syntaxCheck']);
     }
     if ($suite->testAt(0) instanceof PHPUnit_Framework_Warning and strpos($suite->testAt(0)->getMessage(), 'No tests found in class') !== FALSE) {
         $message = $suite->testAt(0)->getMessage();
         $start = strpos($message, '"') + 1;
         $end = strpos($message, '"', $start);
         $className = substr($message, $start, $end - $start);
         require Kohana::find_file('vendor', 'PHPUnit/Util/Skeleton/Test');
         $skeleton = new PHPUnit_Util_Skeleton_Test($className, $arguments['testFile']);
         $result = $skeleton->generate(TRUE);
         if (!$result['incomplete']) {
             eval(str_replace(array('<?php', '?>'), '', $result['code']));
             $suite = new PHPUnit_Framework_TestSuite($arguments['test'] . 'Test');
         }
     }
     if ($arguments['listGroups']) {
         PHPUnit_TextUI_TestRunner::printVersionString();
         print "Available test group(s):\n";
         $groups = $suite->getGroups();
         sort($groups);
         foreach ($groups as $group) {
             print " - {$group}\n";
         }
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     }
     try {
         $result = $runner->doRun($suite, $arguments);
     } catch (Exception $e) {
         throw new RuntimeException('Could not create and run test suite: ' . $e->getMessage());
     }
     if ($result->wasSuccessful()) {
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     } else {
         if ($result->errorCount() > 0) {
             exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
         } else {
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     }
 }
Exemplo n.º 25
0
 /**
  * Runs a single test and waits until the user types RETURN.
  *
  * @param  PHPUnit_Framework_Test $suite
  */
 public static function runAndWait(PHPUnit_Framework_Test $suite)
 {
     $aTestRunner = new PHPUnit_TextUI_TestRunner();
     $aTestRunner->doRun($suite, array('wait' => TRUE));
 }
Exemplo n.º 26
0
$groups = $options['group'] ? explode(',', $options['group']) : null;
$args = array('reportDirectory' => $options['coverage-html'], 'filter' => $options['filter'], 'excludeGroups' => explode(',', $options['exclude-group']), 'groups' => $groups, 'strict' => true, 'processIsolation' => false, 'backupGlobals' => false, 'backupStaticAttributes' => false, 'convertErrorsToExceptions' => $throwOnError, 'convertNoticesToExceptions' => $throwOnError, 'convertWarningsToExceptions' => $throwOnError, 'addUncoveredFilesFromWhitelist' => true, 'processUncoveredFilesFromWhitelist' => true);
$masterSuite = new PHPUnit_Framework_TestSuite();
$suite = new PHPUnit_Framework_TestSuite();
suite_add_dir($suite, $testPath . '/lib/Unit/');
$masterSuite->addTest($suite);
$suite = new PHPUnit_Framework_TestSuite();
suite_add_dir($suite, $testPath . '/lib/FileSystem/');
$masterSuite->addTest($suite);
$suite = new PHPUnit_Framework_TestSuite();
suite_add_dir($suite, $testPath . '/lib/StreamWrapper/');
$masterSuite->addTest($suite);
$filter = new PHP_CodeCoverage_Filter();
$filter->addDirectoryToWhitelist($basePath . '/src/', '.php');
$runner = new PHPUnit_TextUI_TestRunner(null, $filter);
$runner->doRun($masterSuite, $args);
function suite_add_dir($suite, $dir)
{
    foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $item) {
        foreach (require_tests($item) as $class) {
            $suite->addTest(new PHPUnit_Framework_TestSuite($class));
        }
    }
}
function require_tests($file)
{
    static $cache = array();
    if (!preg_match("/Test\\.php\$/", $file)) {
        return array();
    }
    $file = realpath($file);
Exemplo n.º 27
0
 /**
  * @param array   $argv
  * @param boolean $exit
  */
 public function run(array $argv, $exit = TRUE)
 {
     $this->handleArguments($argv);
     $runner = new PHPUnit_TextUI_TestRunner($this->arguments['loader']);
     if (is_object($this->arguments['test']) && $this->arguments['test'] instanceof PHPUnit_Framework_Test) {
         $suite = $this->arguments['test'];
     } else {
         $suite = $runner->getTest($this->arguments['test'], $this->arguments['testFile'], $this->arguments['syntaxCheck']);
     }
     if (count($suite) == 0) {
         $skeleton = new PHPUnit_Util_Skeleton_Test($suite->getName(), $this->arguments['testFile']);
         $result = $skeleton->generate(TRUE);
         if (!$result['incomplete']) {
             eval(str_replace(array('<?php', '?>'), '', $result['code']));
             $suite = new PHPUnit_Framework_TestSuite($this->arguments['test'] . 'Test');
         }
     }
     if ($this->arguments['listGroups']) {
         PHPUnit_TextUI_TestRunner::printVersionString();
         print "Available test group(s):\n";
         $groups = $suite->getGroups();
         sort($groups);
         foreach ($groups as $group) {
             print " - {$group}\n";
         }
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     }
     unset($this->arguments['test']);
     unset($this->arguments['testFile']);
     try {
         $result = $runner->doRun($suite, $this->arguments);
     } catch (PHPUnit_Framework_Exception $e) {
         print $e->getMessage() . "\n";
     }
     if ($exit) {
         if (isset($result) && $result->wasSuccessful()) {
             exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
         } else {
             if (!isset($result) || $result->errorCount() > 0) {
                 exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
             } else {
                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
             }
         }
     }
 }
Exemplo n.º 28
0
 public function run()
 {
     if ($this->_noRun) {
         $message = sprintf('Unit test canceled');
         $this->_info($message);
         return;
     }
     $message = sprintf('Runnig unit test with options: isFile %d, isDir %d', $this->_isFile, $this->_isDir);
     $this->_info($message);
     // file test method
     if ($this->_isFile) {
         $message = sprintf('File enabled, search filename by class name (%s)', $this->_name);
         $this->_info($message);
         if (is_file($this->_name)) {
             $filename = $this->_name;
         } else {
             $filename = $this->getFilenameByClassName($this->_name);
         }
         $this->_addTest($filename);
     }
     if ($this->_isDir) {
         $message = sprintf('Dir enabled, search filename by name (%s)', $this->_name);
         $this->_info($message);
         $pieces = explode('_', $this->_name);
         $piecesCnt = count($pieces);
         $files = array();
         if ($piecesCnt > 1) {
             $message = sprintf('$piecesCnt more 1, search test by module name');
             $this->_info($message);
             $files = $this->getListFileListByModuleName($this->_name);
         } else {
             $message = sprintf('$piecesCnt equal 1, search test by lib name');
             $this->_info($message);
             $files = $this->getListFileListByLibName($this->_name);
         }
         $message = sprintf("Test file list: %s", print_r($files, true));
         $this->_info($message);
         if (!empty($files)) {
             $this->_testSuite->addTestFiles($files);
         }
     }
     $testCnt = $this->_testSuite->count();
     if ($testCnt) {
         $message = sprintf('Found (%d) tests', $testCnt);
         $this->_info($message);
         $processIsolation = isset($this->_opts['processIsolation']) ? $this->_opts['processIsolation'] : false;
         $runner = new PHPUnit_TextUI_TestRunner();
         $arguments = array('processIsolation' => $processIsolation, 'colors' => true, 'backupGlobals' => false);
         $runner->doRun($this->_testSuite, $arguments);
     } else {
         $message = sprintf('No tests');
         $this->_info($message);
     }
 }
Exemplo n.º 29
0
 /**
  * @param array   $argv
  * @param boolean $exit
  */
 public function run(array $argv, $exit = TRUE)
 {
     $this->handleArguments($argv);
     $runner = new PHPUnit_TextUI_TestRunner($this->arguments['loader']);
     if (is_object($this->arguments['test']) && $this->arguments['test'] instanceof PHPUnit_Framework_Test) {
         $suite = $this->arguments['test'];
     } else {
         $suite = $runner->getTest($this->arguments['test'], $this->arguments['testFile'], $this->arguments['syntaxCheck']);
     }
     if ($suite->testAt(0) instanceof PHPUnit_Framework_Warning && strpos($suite->testAt(0)->getMessage(), 'No tests found in class') !== FALSE) {
         $message = $suite->testAt(0)->getMessage();
         $start = strpos($message, '"') + 1;
         $end = strpos($message, '"', $start);
         $className = substr($message, $start, $end - $start);
         require_once PATH_TO_ROOT . '/test/PHPUnit/Util/Skeleton/Test.php';
         $skeleton = new PHPUnit_Util_Skeleton_Test($className, $this->arguments['testFile']);
         $result = $skeleton->generate(TRUE);
         if (!$result['incomplete']) {
             eval(str_replace(array('<?php', '?>'), '', $result['code']));
             $suite = new PHPUnit_Framework_TestSuite($this->arguments['test'] . 'Test');
         }
     }
     if ($this->arguments['listGroups']) {
         PHPUnit_TextUI_TestRunner::printVersionString();
         print "Available test group(s):\n";
         $groups = $suite->getGroups();
         sort($groups);
         foreach ($groups as $group) {
             print " - {$group}\n";
         }
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     }
     unset($this->arguments['test']);
     unset($this->arguments['testFile']);
     try {
         $result = $runner->doRun($suite, $this->arguments);
     } catch (PHPUnit_Framework_Exception $e) {
         print $e->getMessage() . "\n";
     }
     if ($exit) {
         if (isset($result) && $result->wasSuccessful()) {
             exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
         } else {
             if (!isset($result) || $result->errorCount() > 0) {
                 exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
             } else {
                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
             }
         }
     }
 }
Exemplo n.º 30
0
 /**
  * @access public
  * @static
  */
 public static function main()
 {
     self::_initConfiguration();
     self::_initSuitesAndTests();
     self::_initArguments();
     $runner = new PHPUnit_TextUI_TestRunner();
     $master_suite = new PHPUnit_Framework_TestSuite('Zend Framework');
     $loadable_suites = array();
     if (count(self::$_arguments['suite_filter']) > 0) {
         $first_pass = true;
         foreach (self::$_arguments['suite_filter'] as $suite_filter) {
             // if the suite filter is not valid class name (extranious char.) - continue
             if (!preg_match("/[a-z0-9\\-_.]/i", $suite_filter)) {
                 continue;
             }
             if ($suite_filter[0] != "@" && strpos($suite_filter, "#") === false) {
                 /**
                  * This block will parse all filters below the named suite (branch)
                  */
                 foreach (self::$_test_suites as $test_suite) {
                     if (strpos($test_suite, $suite_filter) !== false) {
                         $suite_config = ZFTestManager::getConfig($test_suite);
                         if (isset($suite_config['disabled']) && $suite_config['disabled'] == true) {
                             continue;
                         }
                         $loadable_suites[$test_suite] = null;
                     }
                 }
             } elseif ($suite_filter[0] == "@") {
                 /**
                  * This block will mark only
                  */
                 $suite_filter_base = ltrim($suite_filter, "@");
                 if (in_array($suite_filter_base, self::$_test_suites)) {
                     $loadable_suites[$suite_filter_base] = null;
                 } else {
                     continue;
                 }
                 // remove branches deeper than this one if they exist
                 foreach (self::$_test_suites as $test_suite_id => $test_suite) {
                     if (strpos($test_suite, $suite_filter_base) === 0) {
                         unset(self::$_test_suites[$test_suite_id]);
                     }
                 }
                 continue;
             } elseif (strpos($suite_filter, "#") !== false) {
                 list($suite_filter_base, $suite_filter_testcase) = split("#", $suite_filter);
                 if ($suite_filter_base != "" && $suite_filter_testcase != "") {
                     $loadable_suites[$suite_filter_base] = $suite_filter_testcase;
                 }
             }
         }
     } else {
         foreach (self::$_test_suites as $suite_name) {
             $suite_config = ZFTestManager::getConfig($suite_name);
             if (isset($suite_config['disabled']) && $suite_config['disabled'] == true) {
                 continue;
             }
             $loadable_suites[$suite_name] = null;
         }
     }
     foreach ($loadable_suites as $suite_name => $sub_suite) {
         $runner->getLoader()->load($suite_name . "_AllTests", str_replace("_", DIRECTORY_SEPARATOR, $suite_name) . DIRECTORY_SEPARATOR . "AllTests.php");
         $classname = $suite_name . "_AllTests";
         $master_suite->addTestSuite(call_user_func(array($classname, "suite"), $sub_suite));
     }
     if ($master_suite->testCount() == 0) {
         self::_printVersionString();
         echo "\nNo tests found in the current working directory.\n\n";
         exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
     }
     try {
         self::_printVersionString(false);
         $runner_parameters = array_merge(self::$_configuration['runner_parameters'], self::$_arguments['runner_parameters']);
         $result = $runner->doRun($master_suite, $runner_parameters);
     } catch (Exception $e) {
         throw new RuntimeException('Could not create and run test suite: ' . $e->getMessage());
     }
     if ($result->wasSuccessful()) {
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     } else {
         if ($result->errorCount() > 0) {
             exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
         } else {
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     }
 }