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 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());
 }
Пример #3
0
 public function __construct($runId = null, $ranAt = null)
 {
     $this->runId = $runId ?: Util::createRunId();
     $this->ranAt = $ranAt ?: microtime(true);
 }
 public function testSetInvalidProperty()
 {
     $this->setExpectedException('PHPUnit\\Runner\\CleverAndSmart\\Exception\\PropertyReflectionException', 'Property "invalidProperty" does not exist in hierarchy PHPUnit\\Runner\\CleverAndSmart\\Unit\\Child < PHPUnit\\Runner\\CleverAndSmart\\Unit\\Mother');
     Util::setInvisibleProperty(new Child(), 'invalidProperty', 'value');
 }