Skip to content

Commit

Permalink
add possibility to use --testsuite with directories and not only file…
Browse files Browse the repository at this point in the history
…s (also supports mixing of files+directories)
  • Loading branch information
chbiel committed Jan 29, 2015
1 parent 841b5a9 commit 9f4570c
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 31 deletions.
5 changes: 5 additions & 0 deletions src/ParaTest/Runners/PHPUnit/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public function getSuites()
return $suites;
}

public function getTestsuiteItems()
{

}

/**
* @param string $suiteName
*
Expand Down
7 changes: 5 additions & 2 deletions src/ParaTest/Runners/PHPUnit/SuiteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ public function load($path = '')
foreach ($configuration->getSuiteFiles($this->options->testsuite) as $file) {
$this->loadFile($file);
}
if (!$this->files) {
throw new \RuntimeException("You provided a testsuite but the testsuite does not contain any <file>'s");
foreach ($configuration->getSuites() as $suite) {
foreach ($suite as $suitePath) {
$this->loadPath($suitePath);
}
}
$this->files = array_unique($this->files); // remove duplicates
} elseif ($suites = $configuration->getSuites()) {
foreach ($suites as $suite) {
foreach ($suite as $suitePath) {
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/phpunit-files-dirs-mix-duplicates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="ParaTest Fixtures">
<directory>./passing-tests/</directory>
<file>./passing-tests/TestOfUnits.php</file>
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
20 changes: 20 additions & 0 deletions test/fixtures/phpunit-files-dirs-mix.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="ParaTest Fixtures">
<directory>./failing-tests/</directory>
<file>./passing-tests/TestOfUnits.php</file>
<file>./passing-tests/GroupsTest.php</file>
</testsuite>
</testsuites>
</phpunit>
93 changes: 64 additions & 29 deletions test/unit/ParaTest/Runners/PHPUnit/SuiteLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function testLoadBarePathWithNoPathAndNoConfiguration()
$loader->load();
}

public function testLoadTestsuiteFileFromConfig() {
public function testLoadTestsuiteFileFromConfig()
{
$options = new Options(
array('configuration' => $this->fixture('phpunit-file.xml'), 'testsuite' => 'ParaTest Fixtures')
);
Expand All @@ -54,7 +55,8 @@ public function testLoadTestsuiteFileFromConfig() {
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteFilesFromConfig() {
public function testLoadTestsuiteFilesFromConfig()
{
$options = new Options(
array('configuration' => $this->fixture('phpunit-multifile.xml'), 'testsuite' => 'ParaTest Fixtures')
);
Expand All @@ -66,16 +68,49 @@ public function testLoadTestsuiteFilesFromConfig() {
$this->assertEquals($expected, sizeof($files));
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage You provided a testsuite but the testsuite does not contain any <file>'s
*/
public function testLoadTestsuiteWithoutFiles() {
$options = new Options(
array('configuration' => $this->fixture('phpunit-passing.xml'), 'testsuite' => 'ParaTest Fixtures')
);
public function testLoadTestsuiteWithDirectory()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-passing.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'passing-tests'));
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithDirectories()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-multidir.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'passing-tests')) +
sizeof($this->findTests(FIXTURES . DS . 'failing-tests'));
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithFilesDirsMixed()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-files-dirs-mix.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'failing-tests')) + 2;
$this->assertEquals($expected, sizeof($files));
}

public function testLoadTestsuiteWithDuplicateFilesDirMixed()
{
$options = new Options(array('configuration' => $this->fixture('phpunit-files-dirs-mix-duplicates.xml'), 'testsuite' => 'ParaTest Fixtures'));
$loader = new SuiteLoader($options);
$loader->load();
$files = $this->getObjectValue($loader, 'files');

$expected = sizeof($this->findTests(FIXTURES . DS . 'passing-tests')) + 1;
$this->assertEquals($expected, sizeof($files));
}

public function testLoadSuiteFromConfig()
Expand Down Expand Up @@ -119,6 +154,15 @@ public function testLoadFileGetsPathOfFile()
$this->assertEquals($path, array_shift($paths));
}

protected function getLoadedPaths($path, $loader=null)
{
$loader = $loader ?: new SuiteLoader();
$loader->load($path);
$loaded = $this->getObjectValue($loader, 'loadedSuites');
$paths = array_keys($loaded);
return $paths;
}

public function testLoadFileShouldLoadFileWhereNameDoesNotEndInTest()
{
$path = $this->fixture('passing-tests/TestOfUnits.php');
Expand Down Expand Up @@ -154,6 +198,16 @@ public function testFirstParallelSuiteHasCorrectFunctions($paraSuites)
$this->assertEquals('testAddition', $functions[4]->getName());
}

private function suiteByPath($path, array $paraSuites)
{
foreach ($paraSuites as $completePath => $suite) {
if (strstr($completePath, $path)) {
return $suite;
}
}
throw new \RuntimeException("Suite $path not found.");
}

/**
* @depends testLoadDirGetsPathOfAllTestsWithKeys
*/
Expand Down Expand Up @@ -197,23 +251,4 @@ public function testExecutableTestsForFunctionalModeUse()
$testMethodName = $this->getObjectValue($testMethod, 'name');
$this->assertEquals($testMethodName, 'testTwoA|testTwoBDependsOnA');
}

protected function getLoadedPaths($path, $loader=null)
{
$loader = $loader ?: new SuiteLoader();
$loader->load($path);
$loaded = $this->getObjectValue($loader, 'loadedSuites');
$paths = array_keys($loaded);
return $paths;
}

private function suiteByPath($path, array $paraSuites)
{
foreach ($paraSuites as $completePath => $suite) {
if (strstr($completePath, $path)) {
return $suite;
}
}
throw new \RuntimeException("Suite $path not found.");
}
}

0 comments on commit 9f4570c

Please sign in to comment.