Skip to content

Commit

Permalink
Merge branch '7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 16, 2018
2 parents abe0668 + de4d7c3 commit 590b470
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 16 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-7.2.md
Expand Up @@ -2,6 +2,12 @@

All notable changes of the PHPUnit 7.2 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [7.2.5] - 2018-MM-DD

### Fixed

* Fixed [#3160](https://github.com/sebastianbergmann/phpunit/issues/3160): TeamCity logfile writer broken on Windows

## [7.2.4] - 2018-06-05

### Fixed
Expand Down Expand Up @@ -46,6 +52,7 @@ All notable changes of the PHPUnit 7.2 release series are documented in this fil

* Fixed [#3069](https://github.com/sebastianbergmann/phpunit/issues/3069): Method `ResultPrinter::printWaitPrompt()` seems to be unused

[7.2.5]: https://github.com/sebastianbergmann/phpunit/compare/7.2.4...7.2.5
[7.2.4]: https://github.com/sebastianbergmann/phpunit/compare/7.2.3...7.2.4
[7.2.3]: https://github.com/sebastianbergmann/phpunit/compare/7.2.2...7.2.3
[7.2.2]: https://github.com/sebastianbergmann/phpunit/compare/7.2.1...7.2.2
Expand Down
67 changes: 51 additions & 16 deletions src/Runner/TestSuiteSorter.php
Expand Up @@ -9,6 +9,7 @@
*/
namespace PHPUnit\Runner;

use PHPUnit\Framework\DataProviderTestSuite;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
Expand Down Expand Up @@ -62,11 +63,18 @@ private function sort(TestSuite $suite, int $order, bool $resolveDependencies):
$suite->setTests($this->randomize($suite->tests()));
}

if ($resolveDependencies && $suite->tests()[0] instanceof TestCase) {
if ($resolveDependencies && !($suite instanceof DataProviderTestSuite) && $this->suiteOnlyContainsTests($suite)) {
$suite->setTests($this->resolveDependencies($suite->tests()));
}
}

private function suiteOnlyContainsTests(TestSuite $suite): bool
{
return \array_reduce($suite->tests(), function ($carry, $test) {
return $carry && ($test instanceof TestCase || $test instanceof DataProviderTestSuite);
}, true);
}

private function reverse(array $tests): array
{
return \array_reverse($tests);
Expand All @@ -90,30 +98,21 @@ private function randomize(array $tests): array
* 3. If the test has dependencies but none left to do: mark done, start again from the top
* 4. When we reach the end add any leftover tests to the end. These will be marked 'skipped' during execution.
*
* @param Test[] $tests
* @param array<DataProviderTestSuite|TestCase> $tests
*
* @return Test[]
* @return array<DataProviderTestSuite|TestCase>
*/
private function resolveDependencies(array $tests): array
{
if (empty($tests)) {
return $tests;
}

$newTestOrder = [];
$i = 0;

do {
$todoNames = \array_merge(
\array_map(function (Test $t) {
return $t->getName();
}, $tests),
\array_map(function (Test $t) {
return \get_class($t) . '::' . $t->getName();
}, $tests)
);
$todoNames = \array_map(function ($test) {
return $this->getNormalizedTestName($test);
}, $tests);

if (!$tests[$i]->hasDependencies() || empty(\array_intersect($tests[$i]->getDependencies(), $todoNames))) {
if (!$tests[$i]->hasDependencies() || empty(\array_intersect($this->getNormalizedDependencyNames($tests[$i]), $todoNames))) {
$newTestOrder = \array_merge($newTestOrder, \array_splice($tests, $i, 1));
$i = 0;
} else {
Expand All @@ -123,4 +122,40 @@ private function resolveDependencies(array $tests): array

return \array_merge($newTestOrder, $tests);
}

/**
* @param DataProviderTestSuite|TestCase $test
*
* @return string Full test name as "TestSuiteClassName::testMethodName"
*/
private function getNormalizedTestName($test): string
{
if (\strpos($test->getName(), '::') !== false) {
return $test->getName();
}

return \get_class($test) . '::' . $test->getName();
}

/**
* @param DataProviderTestSuite|TestCase $test
*
* @return array<string> A list of full test names as "TestSuiteClassName::testMethodName"
*/
private function getNormalizedDependencyNames($test): array
{
if ($test instanceof DataProviderTestSuite) {
$testClass = \substr($test->getName(), 0, \strpos($test->getName(), '::'));
} else {
$testClass = \get_class($test);
}

$names = \array_map(function ($name) use ($testClass) {
return \strpos($name, '::') === false
? $testClass . '::' . $name
: $name;
}, $test->getDependencies());

return $names;
}
}
30 changes: 30 additions & 0 deletions tests/Regression/GitHub/3093/Issue3093Test.php
@@ -0,0 +1,30 @@
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Issue3093Test extends \PHPUnit\Framework\TestCase
{
public function someDataProvider(): array
{
return [['some values']];
}

public function testFirstWithoutDependencies(): void
{
self::assertTrue(true);
}

/**
* @depends testFirstWithoutDependencies
* @dataProvider someDataProvider
*/
public function testSecondThatDependsOnFirstAndDataprovider($value)
{
self::assertTrue(true);
}
}
19 changes: 19 additions & 0 deletions tests/Regression/GitHub/3093/issue-3093-test.phpt
@@ -0,0 +1,19 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/3093
--FILE--
<?php
$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--reverse-order';
$_SERVER['argv'][3] = '--resolve-dependencies';
$_SERVER['argv'][4] = __DIR__ . '/Issue3093Test.php';

require __DIR__ . '/../../../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

.. 2 / 2 (100%)

Time: %s, Memory: %s

OK (2 tests, 2 assertions)

0 comments on commit 590b470

Please sign in to comment.