tests() public method

Returns the tests as an enumeration.
public tests ( ) : array
return array
 public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
 {
     $suiteName = $suite->getName();
     if (-1 === $this->state) {
         echo "Testing {$suiteName}\n";
         $this->state = 0;
         if (!class_exists('Doctrine\\Common\\Annotations\\AnnotationRegistry', false) && class_exists('Doctrine\\Common\\Annotations\\AnnotationRegistry')) {
             AnnotationRegistry::registerLoader('class_exists');
         }
         if ($this->skippedFile = getenv('SYMFONY_PHPUNIT_SKIPPED_TESTS')) {
             $this->state = 1;
             if (file_exists($this->skippedFile)) {
                 $this->state = 2;
                 if (!($this->wasSkipped = (require $this->skippedFile))) {
                     echo "All tests already ran successfully.\n";
                     $suite->setTests(array());
                 }
             }
         }
         foreach ($suite->tests() as $test) {
             if ($test instanceof \PHPUnit_Framework_TestSuite && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) {
                 ClockMock::register($test->getName());
             }
         }
     } elseif (2 === $this->state) {
         $skipped = array();
         foreach ($suite->tests() as $test) {
             if (!$test instanceof \PHPUnit_Framework_TestCase || isset($this->wasSkipped[$suiteName]['*']) || isset($this->wasSkipped[$suiteName][$test->getName()])) {
                 $skipped[] = $test;
             }
         }
         $suite->setTests($skipped);
     }
 }
 /**
  * Mark tests skipped
  *
  * @param TestCase $test
  * @param array $errors
  * @todo Mark tests skipped, unfortunately tests are skipped by invoking exceptions from the tests.
  */
 private function markTestsSkipped(TestCase $test, array $errors)
 {
     list($identifier, $className, $testName) = $this->storage->getTestIdentifiers($test);
     if ($this->mergeMode === self::MERGE_MODE_ERROR_AND_SKIP && count($errors) > 0 && count($this->suite->tests()) > count($errors) && $this->storage->getRecording(array(StorageInterface::STATUS_PASSED), $identifier)) {
         // mark test skipped. quite hard, cause skipped tests are handled through exceptions
     }
 }
 private function browserOnAllTests(PHPUnit_Framework_TestSuite $suite, array $browser)
 {
     foreach ($suite->tests() as $test) {
         if ($test instanceof PHPUnit_Framework_TestSuite) {
             $this->browserOnAllTests($test, $browser);
         } else {
             $test->setupSpecificBrowser($browser);
         }
     }
 }
 public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
 {
     $this->suiteLevel++;
     $this->currentSuiteName = $suite->getName();
     if ($this->suiteLevel == 1 + $this->rootSuiteNestingLevel) {
         $this->rootSuiteName = $suite->getName();
         $suites = $suite->tests();
         $filtered = $this->filterSuites($suites);
         $suite->setTests($filtered);
     }
 }
 protected function _getTests(PHPUnit_Framework_TestSuite $suite)
 {
     $tests = array();
     foreach ($suite->tests() as $test) {
         if ($test instanceof PHPUnit_Framework_TestSuite) {
             $tests = array_merge($tests, $this->_getTests($test));
         } else {
             $tests[] = $test;
         }
     }
     return $tests;
 }
 protected function extractSuite(\PHPUnit_Framework_TestSuite $suite)
 {
     $testList = $suite->tests();
     foreach ($testList as $test) {
         if ($test instanceof \PHPUnit_Framework_TestSuite) {
             $this->extractSuite($test);
         } else {
             $ref = new \ReflectionClass($test);
             self::addFile($ref);
         }
     }
 }
 /**
  * Clear test method properties after each test suite
  *
  * @param  PHPUnit_Framework_TestSuite $suite
  */
 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     $tests = $suite->tests();
     foreach ($tests as $test) {
         $reflectionClass = new ReflectionClass($test);
         $properties = $reflectionClass->getProperties();
         foreach ($properties as $property) {
             $property->setAccessible(true);
             $value = $property->getValue($test);
             if (is_object($value) && method_exists($value, '__destruct')) {
                 $value->__destruct();
             }
             $property->setValue($test, null);
         }
     }
 }
 private function sortTestSuite(TestSuite $suite)
 {
     $tests = $suite->tests();
     $testsOrderResult = array(static::SORT_NONE, null);
     foreach ($tests as $test) {
         if ($test instanceof TestCase && Util::getInvisibleProperty($test, 'dependencies', 'hasDependencies')) {
             return $testsOrderResult;
         }
     }
     $orderedTests = new SegmentedQueue($tests);
     $orderedTests->setMergeMode($this->mergeMode);
     foreach ($tests as $position => $test) {
         list($testOrderResult, $time) = $this->sortTest($test, $position, $orderedTests);
         if ($testsOrderResult[0] < $testOrderResult) {
             $testsOrderResult = array($testOrderResult, $time);
         }
     }
     $groups = Util::getInvisibleProperty($suite, 'groups', 'getGroupDetails');
     $groupsOrderResult = array(static::SORT_NONE, null);
     foreach ($groups as $groupName => $group) {
         $groupOrderResult = array(static::SORT_NONE, null);
         $orderedGroup = new SegmentedQueue($group);
         $orderedGroup->setMergeMode($this->mergeMode);
         foreach ($group as $position => $test) {
             list($testOrderResult, $time) = $this->sortTest($test, $position, $orderedGroup);
             if ($groupOrderResult[0] < $testOrderResult) {
                 $groupOrderResult = array($testOrderResult, $time);
             }
         }
         if ($groupOrderResult[0] > static::SORT_NONE) {
             $groups[$groupName] = iterator_to_array($orderedGroup);
             if ($groupsOrderResult[0] < $groupOrderResult[0]) {
                 $groupsOrderResult = $groupOrderResult;
             }
         }
     }
     if ($testsOrderResult[0] > static::SORT_NONE) {
         Util::setInvisibleProperty($suite, 'tests', iterator_to_array($orderedTests), 'setTests');
     }
     if ($groupsOrderResult) {
         Util::setInvisibleProperty($suite, 'groups', $groups, 'setGroupDetails');
     }
     return $testsOrderResult[0] > $groupsOrderResult[0] ? $testsOrderResult : $groupsOrderResult;
 }
 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     foreach ($suite->tests() as $test) {
         if ($test instanceof PHPUnit_Framework_TestSuite) {
             return false;
         }
     }
     $sb = "Testsuite: " . $suite->getName() . "\n";
     $sb .= "Tests run: " . $this->getRunCount();
     $sb .= ", Failures: " . $this->getFailureCount();
     $sb .= ", Errors: " . $this->getErrorCount();
     $sb .= ", Incomplete: " . $this->getIncompleteCount();
     $sb .= ", Skipped: " . $this->getSkippedCount();
     $sb .= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n";
     if ($this->out != NULL) {
         $this->out->write($sb);
         $this->out->write($this->inner);
     }
     parent::endTestSuite($suite);
 }
Example #10
0
    public function startTestSuite(\PHPUnit_Framework_TestSuite $mainSuite)
    {
        if (null !== self::$enabledPolyfills) {
            return;
        }
        self::$enabledPolyfills = false;
        foreach ($mainSuite->tests() as $suite) {
            $testClass = $suite->getName();
            if (!($tests = $suite->tests())) {
                continue;
            }
            if (!preg_match('/^(.+)\\\\Tests(\\\\.*)Test$/', $testClass, $m)) {
                $mainSuite->addTest(self::warning('Unknown naming convention for ' . $testClass));
                continue;
            }
            $testedClass = new \ReflectionClass($m[1] . $m[2]);
            $bootstrap = new \SplFileObject(dirname($testedClass->getFileName()) . '/bootstrap.php');
            $warnings = array();
            $defLine = null;
            foreach (new \RegexIterator($bootstrap, '/return p\\\\' . $testedClass->getShortName() . '::/') as $defLine) {
                if (!preg_match('/^\\s*function (?P<name>[^\\(]++)(?P<signature>\\([^\\)]*+\\)) \\{ (?<return>return p\\\\' . $testedClass->getShortName() . '::[^\\(]++)(?P<args>\\([^\\)]*+\\)); \\}$/', $defLine, $f)) {
                    $warnings[] = self::warning('Invalid line in bootstrap.php: ' . trim($defLine));
                    continue;
                }
                $testNamespace = substr($testClass, 0, strrpos($testClass, '\\'));
                if (function_exists($testNamespace . '\\' . $f['name'])) {
                    continue;
                }
                try {
                    $r = new \ReflectionFunction($f['name']);
                    if ($r->isUserDefined()) {
                        throw new \ReflectionException();
                    }
                    if (false !== strpos($f['signature'], '&')) {
                        $defLine = sprintf('return \\%s%s', $f['name'], $f['args']);
                    } else {
                        $defLine = sprintf("return \\call_user_func_array('%s', func_get_args())", $f['name']);
                    }
                } catch (\ReflectionException $e) {
                    $defLine = sprintf("throw new \\PHPUnit_Framework_SkippedTestError('Internal function not found: %s')", $f['name']);
                }
                eval(<<<EOPHP
namespace {$testNamespace};

use Symfony\\Polyfill\\Util\\TestListener;
use {$testedClass->getNamespaceName()} as p;

function {$f['name']}{$f['signature']}
{
    if ('{$testClass}' === TestListener::\$enabledPolyfills) {
        {$f['return']}{$f['args']};
    }

    {$defLine};
}
EOPHP
);
            }
            if (!$warnings && null === $defLine) {
                $warnings[] = new \PHPUnit_Framework_SkippedTestCase('No Polyfills found in bootstrap.php for ' . $testClass);
            } else {
                $mainSuite->addTest(new static($suite));
            }
        }
        foreach ($warnings as $w) {
            $mainSuite->addTest($w);
        }
    }
Example #11
0
 /**
  * Constructor.
  *
  * @param  PHPUnit_Framework_TestSuite $suite
  */
 public function __construct(PHPUnit_Framework_TestSuite $testSuite)
 {
     $this->tests = $testSuite->tests();
 }
 /**
  * Handler for 'endTestSuite' event
  *
  * @param \PHPUnit_Framework_TestSuite $suite
  */
 public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
 {
     $clearStatics = false;
     foreach ($suite->tests() as $test) {
         if ($test instanceof \Magento\TestFramework\TestCase\AbstractController) {
             $clearStatics = true;
             break;
         }
     }
     if ($clearStatics) {
         self::restoreStaticVariables();
     }
 }
 /**
  * @param \PHPUnit_Framework_TestSuite $testSuite
  * @param integer $filter
  * @since Method available since Release 3.0.3
  */
 protected function filterTests(\PHPUnit_Framework_TestSuite $testSuite, $filter)
 {
     $filteredTests = array();
     foreach ($testSuite->tests() as $test) {
         if ($test instanceof \PHPUnit_Framework_TestCase) {
             $testClassName = get_class($test);
             $testMethodName = $test->getName(false);
             if ($this->testTargetRepository->shouldTreatElementAsTest($testClassName, $filter == self::$FILTER_METHOD ? $testMethodName : null)) {
                 $filteredTests[] = $test;
             }
         } else {
             $this->filterTests($test, $filter);
             if (count($test) > 0) {
                 $filteredTests[] = $test;
             }
         }
     }
     $testSuiteClass = new \ReflectionClass($testSuite);
     $testsProperty = $testSuiteClass->getProperty('tests');
     $testsProperty->setAccessible(true);
     $testsProperty->setValue($testSuite, $filteredTests);
     $testsProperty->setAccessible(false);
     $numTestsProperty = $testSuiteClass->getProperty('numTests');
     $numTestsProperty->setAccessible(true);
     $numTestsProperty->setValue($testSuite, -1);
     $numTestsProperty->setAccessible(false);
     $groupsProperty = $testSuiteClass->getProperty('groups');
     $groupsProperty->setAccessible(true);
     $groups = $groupsProperty->getValue($testSuite);
     $groups = array_map(function ($tests) use($filteredTests) {
         return array_filter($tests, function ($test) use($filteredTests) {
             return in_array($test, $filteredTests, true);
         });
     }, $groups);
     $groupsProperty->setValue($testSuite, $groups);
     $groupsProperty->setAccessible(false);
 }
Example #14
0
 /**
  * Runs a testcase as given in the GET/POST variable "testCaseFile".
  *
  * @param PHPUnit_Framework_TestSuite $testSuiteWithAllTestCases suite with all test cases
  * @param PHPUnit_Framework_TestResult $testResult the test result (will be modified)
  *
  * @return void
  */
 protected function runTestCase(PHPUnit_Framework_TestSuite $testSuiteWithAllTestCases, PHPUnit_Framework_TestResult $testResult)
 {
     $testCaseFileName = $this->request->getAsString(Tx_Phpunit_Interface_Request::PARAMETER_KEY_TESTCASE);
     $this->testListener->setTestSuiteName($testCaseFileName);
     $suiteNameHasBeenDisplayed = FALSE;
     $totalNumberOfTestCases = 0;
     foreach ($testSuiteWithAllTestCases->tests() as $testCases) {
         foreach ($testCases->tests() as $test) {
             if ($test instanceof PHPUnit_Framework_TestSuite) {
                 list($testIdentifier, $unused) = explode('::', $test->getName());
             } else {
                 $testIdentifier = get_class($test);
             }
             if ($testIdentifier === $testCaseFileName) {
                 if ($test instanceof PHPUnit_Framework_TestSuite) {
                     $totalNumberOfTestCases += $test->count();
                 } else {
                     $totalNumberOfTestCases++;
                 }
             }
         }
     }
     $this->testListener->setTotalNumberOfTests($totalNumberOfTestCases);
     $this->renderProgressbar();
     foreach ($testSuiteWithAllTestCases->tests() as $testCases) {
         foreach ($testCases->tests() as $test) {
             if ($test instanceof PHPUnit_Framework_TestSuite) {
                 list($testIdentifier, $unused) = explode('::', $test->getName());
             } else {
                 $testIdentifier = get_class($test);
             }
             if ($testIdentifier === $testCaseFileName) {
                 if (!$suiteNameHasBeenDisplayed) {
                     $this->outputService->output('<h2 class="testSuiteName">Testsuite: ' . $testCaseFileName . '</h2>');
                     $suiteNameHasBeenDisplayed = TRUE;
                 }
                 $test->run($testResult);
             }
         }
     }
     if (!is_object($testResult)) {
         $this->outputService->output('<h2 class="hadError">Error</h2><p>The test <strong> ' . htmlspecialchars($this->request->getAsString(Tx_Phpunit_Interface_Request::PARAMETER_KEY_TEST)) . '</strong> could not be found.</p>');
         return;
     }
 }
    public function testMessageNameForTestWithDataProvider()
    {
        $theClass = new \ReflectionClass('\\PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest');
        $testSuite = new \PHPUnit_Framework_TestSuite($theClass);
        $tests = $testSuite->tests();
        $this->assertArrayHasKey(0, $tests);
        $this->assertInstanceOf('PHPUnit_Framework_TestSuite_DataProvider', $tests[0]);
        /* @var \PHPUnit_Framework_TestSuite_DataProvider $dataProviderTestSuite */
        $dataProviderTestSuite = $tests[0];
        $this->assertArrayHasKey(1, $tests);
        $this->assertInstanceOf('\\PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest', $tests[1]);
        /* @var DataProviderTest $simpleMethodTest*/
        $simpleMethodTest = $tests[1];
        $this->listener->startTestSuite($testSuite);
        $this->listener->startTestSuite($dataProviderTestSuite);
        foreach ($dataProviderTestSuite as $test) {
            $this->listener->startTest($test);
            $this->listener->endTest($test, 5);
        }
        $this->listener->endTestSuite($dataProviderTestSuite);
        $this->listener->startTest($simpleMethodTest);
        $this->listener->endTest($simpleMethodTest, 6);
        $this->listener->endTestSuite($testSuite);
        $expectedOutput = <<<EOS
##teamcity[testSuiteStarted name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testSuiteStarted name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest::testMethodWithDataProvider' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "two"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "two"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "three"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "three"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "four"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "four"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "five.one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "five.one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testSuiteFinished name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest::testMethodWithDataProvider' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testSimpleMethod' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='6000' name='testSimpleMethod' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testSuiteFinished name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']

EOS;
        $this->assertOutputSame($expectedOutput);
    }
 /**
  * @param \PHPUnit_Framework_TestSuite $testSuite
  * @param int                          $filter
  *
  * @since Method available since Release 3.0.3
  */
 protected function filterTests(\PHPUnit_Framework_TestSuite $testSuite, $filter)
 {
     $filteredTests = array();
     foreach ($testSuite->tests() as $test) {
         if ($test instanceof \PHPUnit_Framework_WarningTestCase && preg_match('/^No tests found in class "([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)"\\.$/', $test->getMessage(), $matches)) {
             $testClassName = $matches[1];
             if ($this->testTargetRepository->shouldTreatElementAsTest($testClassName, null)) {
                 $filteredTests[] = $test;
             }
         } elseif ($test instanceof \PHPUnit_Framework_TestCase) {
             $testClassName = get_class($test);
             $testMethodName = $test->getName(false);
             if ($this->testTargetRepository->shouldTreatElementAsTest($testClassName, $filter == self::$FILTER_METHOD ? $testMethodName : null)) {
                 $filteredTests[] = $test;
             }
         } elseif ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
             list($testClassName, $testMethodName) = explode('::', $test->getName());
             if ($this->testTargetRepository->shouldTreatElementAsTest($testClassName, $filter == self::$FILTER_METHOD ? $testMethodName : null)) {
                 $filteredTests[] = $test;
             }
         } else {
             $this->filterTests($test, $filter);
             if (count($test) > 0) {
                 $filteredTests[] = $test;
             }
         }
     }
     $testSuiteClass = new \ReflectionClass($testSuite);
     $testsProperty = $testSuiteClass->getProperty('tests');
     $testsProperty->setAccessible(true);
     $testsProperty->setValue($testSuite, $filteredTests);
     $testsProperty->setAccessible(false);
     $numTestsProperty = $testSuiteClass->getProperty('numTests');
     $numTestsProperty->setAccessible(true);
     $numTestsProperty->setValue($testSuite, -1);
     $numTestsProperty->setAccessible(false);
     $groupsProperty = $testSuiteClass->getProperty('groups');
     $groupsProperty->setAccessible(true);
     $groups = $groupsProperty->getValue($testSuite);
     $groups = array_map(function ($tests) use($filteredTests) {
         return array_filter($tests, function ($test) use($filteredTests) {
             return in_array($test, $filteredTests, true);
         });
     }, $groups);
     $groupsProperty->setValue($testSuite, $groups);
     $groupsProperty->setAccessible(false);
 }
 public function testNestedSortingGroups()
 {
     $suite1 = new TestSuite('suite1', 'suite1');
     $suite2 = new TestSuite('suite2', 'suite2');
     $suite2->addTest(new Test('test3'), array('g1'));
     $suite1->addTestSuite($suite2);
     $suite1->addTest(new Test('test1'), array('g1'));
     $suite1->addTest(new Test('test2'), array('g1'));
     $suite1->addTest(new Test('test4'), array('g1'));
     $suite1->addTest(new Test('test5'), array('g1'));
     $tests = $suite1->tests();
     $tests0 = $tests[0]->tests();
     $this->assertSame('suite2', $tests[0]->getName());
     $this->assertSame('test3', $tests0[0]->getName());
     $this->assertSame('test1', $tests[1]->getName());
     $this->assertSame('test2', $tests[2]->getName());
     $this->assertSame('test4', $tests[3]->getName());
     $this->assertSame('test5', $tests[4]->getName());
     $groupDetails = Util::getInvisibleProperty($suite1, 'groups', 'getGroupDetails');
     $tests = $groupDetails['g1'];
     $tests0 = $tests[0]->tests();
     $this->assertSame('suite2', $tests[0]->getName());
     $this->assertSame('test3', $tests0[0]->getName());
     $this->assertSame('test1', $tests[1]->getName());
     $this->assertSame('test2', $tests[2]->getName());
     $this->assertSame('test4', $tests[3]->getName());
     $this->assertSame('test5', $tests[4]->getName());
     $sorter = new PrioritySorter(array(array('class' => 'PHPUnit\\Runner\\CleverAndSmart\\Unit\\Test', 'test' => 'test2')));
     $sorter->sort($suite1);
     $tests = $suite1->tests();
     $tests1 = $tests[1]->tests();
     $this->assertSame('test2', $tests[0]->getName());
     $this->assertSame('suite2', $tests[1]->getName());
     $this->assertSame('test3', $tests1[0]->getName());
     $this->assertSame('test1', $tests[2]->getName());
     $this->assertSame('test4', $tests[3]->getName());
     $this->assertSame('test5', $tests[4]->getName());
     $groupDetails = Util::getInvisibleProperty($suite1, 'groups', 'getGroupDetails');
     $tests = $groupDetails['g1'];
     $tests1 = $tests[1]->tests();
     $this->assertSame('test2', $tests[0]->getName());
     $this->assertSame('suite2', $tests[1]->getName());
     $this->assertSame('test3', $tests1[0]->getName());
     $this->assertSame('test1', $tests[2]->getName());
     $this->assertSame('test4', $tests[3]->getName());
     $this->assertSame('test5', $tests[4]->getName());
 }
Example #18
0
 public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
 {
     $byInterface = $this->indexTestsByInterface($suite->tests());
     $this->validateGroups($byInterface);
     $this->autoboot($byInterface);
 }