Skip to content

Commit

Permalink
Merge pull request #121 from dimarick/master
Browse files Browse the repository at this point in the history
Add globbing support like a native phpunit
  • Loading branch information
julianseeger committed Nov 4, 2014
2 parents ac2a093 + 0cdbef1 commit 069a61e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
42 changes: 33 additions & 9 deletions src/ParaTest/Runners/PHPUnit/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ public function getSuites()
$nodes = $this->xml->xpath('//testsuite');
while(list(, $node) = each($nodes)) {
foreach ($node->directory as $dir) {
$suites[(string) $node['name']][] = new SuitePath(
$this->getSuitePath((string) $dir),
$dir->attributes()->suffix);
foreach ($this->getSuitePaths((string) $dir) as $path) {
$suites[(string)$node['name']][] = new SuitePath($path, $dir->attributes()->suffix);
}
}
}

return $suites;
}

Expand All @@ -99,19 +98,44 @@ public function getConfigDir()
}

/**
* Returns a suite path relative to the config file
* Returns a suite paths relative to the config file
*
* @param $path
* @return string
* @throws \RuntimeException
* @return array|string[]
*/
public function getSuitePath($path)
public function getSuitePaths($path)
{
$real = realpath($this->getConfigDir() . $path);
if($real) return $real;

if ($real !== false) {
return array($real);
}

if ($this->isGlobRequired($path)) {
$paths = array();
foreach (glob($this->getConfigDir() . $path, GLOB_ONLYDIR) as $path) {
if (($path = realpath($path)) !== false) {
$paths[] = $path;
}
}

return $paths;
}

throw new \RuntimeException("Suite path $path could not be found");
}

/**
* Returns true if path needs globbing (like a /path/*-to/string)
*
* @param string $path
* @return bool
*/
public function isGlobRequired($path)
{
return strpos($path, '*') !== false;
}

/**
* Converting the configuration to a string
* returns the configuration path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class SampleTest extends PHPUnit_FrameWork_TestCase
{
public function testCase()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class SecondSampleTest extends PHPUnit_FrameWork_TestCase
{
public function testCase()
{

}
}
18 changes: 18 additions & 0 deletions test/fixtures/phpunit-globbing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>./globbing-support-tests/some-*/</directory>
</testsuite>
</testsuites>
</phpunit>
11 changes: 11 additions & 0 deletions test/unit/ParaTest/Runners/PHPUnit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ public function test_getSuitesShouldReturnCorrectNumberOfSuites()
return $suites;
}

public function testGlobbingSupport()
{
$basePath = getcwd() . DS;
$configuration = new Configuration($this->fixture('phpunit-globbing.xml'));
/** @var SuitePath[][] $suites */
$suites = $configuration->getSuites();
$this->assertEquals($basePath . 'test' . DS . 'fixtures' . DS . 'globbing-support-tests' . DS . 'some-dir', $suites["ParaTest Fixtures"][0]->getPath());
$this->assertEquals($basePath . 'test' . DS . 'fixtures' . DS . 'globbing-support-tests' . DS . 'some-dir2', $suites["ParaTest Fixtures"][1]->getPath());
return $suites;
}

/**
* @depends test_getSuitesShouldReturnCorrectNumberOfSuites
*/
Expand Down

0 comments on commit 069a61e

Please sign in to comment.