merge similar run methods in PhpUnit
This commit is contained in:
parent
42d4b9f5ac
commit
a77b1115a0
|
@ -84,13 +84,13 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
|||
// Run any directories
|
||||
if (!empty($directories)) {
|
||||
foreach ($directories as $directory) {
|
||||
$success[] = $this->runDir($directory);
|
||||
$success[] = $this->runConfig($directory, null);
|
||||
}
|
||||
} else {
|
||||
// Run any config files
|
||||
if (!empty($xmlConfigFiles)) {
|
||||
foreach ($xmlConfigFiles as $configFile) {
|
||||
$success[] = $this->runConfigFile($configFile);
|
||||
$success[] = $this->runConfig($this->options->getTestsPath(), $configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,42 +99,14 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Run the PHPUnit tests in a specific directory or array of directories.
|
||||
* Run the tests defined in a PHPUnit config file or in a specific directory.
|
||||
*
|
||||
* @param $directory
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
protected function runDir($directory)
|
||||
{
|
||||
$options = clone $this->options;
|
||||
|
||||
$buildPath = $this->build->getBuildPath() . DIRECTORY_SEPARATOR;
|
||||
|
||||
// Save the results into a json file
|
||||
$jsonFile = @tempnam($buildPath, 'jLog_');
|
||||
$options->addArgument('log-json', $jsonFile);
|
||||
|
||||
// Removes any current configurations files
|
||||
$options->removeArgument('configuration');
|
||||
|
||||
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->findBinary('phpunit') . ' %s "%s"';
|
||||
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
|
||||
|
||||
$this->processResults($jsonFile);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the tests defined in a PHPUnit config file.
|
||||
*
|
||||
* @param $configFile
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
protected function runConfigFile($configFile)
|
||||
protected function runConfig($directory, $configFile)
|
||||
{
|
||||
$options = clone $this->options;
|
||||
$buildPath = $this->build->getBuildPath() . DIRECTORY_SEPARATOR;
|
||||
|
@ -145,12 +117,14 @@ class PhpUnit extends Plugin implements ZeroConfigPluginInterface
|
|||
|
||||
// Removes any current configurations files
|
||||
$options->removeArgument('configuration');
|
||||
// Only the add the configuration file been passed
|
||||
$options->addArgument('configuration', $buildPath . $configFile);
|
||||
if (null !== $configFile) {
|
||||
// Only the add the configuration file been passed
|
||||
$options->addArgument('configuration', $buildPath . $configFile);
|
||||
}
|
||||
|
||||
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->findBinary('phpunit') . ' %s %s';
|
||||
$success = $this->builder->executeCommand($cmd, $arguments, $options->getTestsPath());
|
||||
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
|
||||
|
||||
$this->processResults($jsonFile);
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
|
|||
'config' => ROOT_DIR . 'phpunit.xml'
|
||||
];
|
||||
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfigFile'])->getMock();
|
||||
$mockPlugin->expects($this->once())->method('runConfigFile')->with(ROOT_DIR . 'phpunit.xml');
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
|
||||
$mockPlugin->expects($this->once())->method('runConfig')->with(null, ROOT_DIR . 'phpunit.xml');
|
||||
|
||||
$mockPlugin->execute();
|
||||
}
|
||||
|
@ -30,9 +30,10 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
|
|||
]
|
||||
];
|
||||
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfigFile'])->getMock();
|
||||
$mockPlugin->expects($this->exactly(2))->method('runConfigFile')->withConsecutive(
|
||||
[ROOT_DIR . 'phpunit1.xml'], [ROOT_DIR . 'phpunit2.xml']
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
|
||||
$mockPlugin->expects($this->exactly(2))->method('runConfig')->withConsecutive(
|
||||
[null, ROOT_DIR . 'phpunit1.xml'],
|
||||
[null, ROOT_DIR . 'phpunit2.xml']
|
||||
);
|
||||
|
||||
$mockPlugin->execute();
|
||||
|
@ -68,8 +69,8 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
|
|||
'directory' => '/test/directory/one'
|
||||
];
|
||||
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runDir'])->getMock();
|
||||
$mockPlugin->expects($this->once())->method('runDir')->with('/test/directory/one');
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
|
||||
$mockPlugin->expects($this->once())->method('runConfig')->with('/test/directory/one', null);
|
||||
|
||||
$mockPlugin->execute();
|
||||
}
|
||||
|
@ -83,8 +84,8 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
|
|||
]
|
||||
];
|
||||
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runDir'])->getMock();
|
||||
$mockPlugin->expects($this->exactly(2))->method('runDir')->withConsecutive(
|
||||
$mockPlugin = $this->getPluginBuilder($options)->setMethods(['runConfig'])->getMock();
|
||||
$mockPlugin->expects($this->exactly(2))->method('runConfig')->withConsecutive(
|
||||
['/test/directory/one'], ['/test/directory/two']
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue