New PHPUnit plugin fixes for PHP Censor

This commit is contained in:
Dmitry Khomutov 2017-01-05 20:01:53 +07:00
parent 881713747e
commit f3e8acc4bd
8 changed files with 45 additions and 61 deletions

View file

@ -106,7 +106,7 @@ class Builder implements LoggerAwareInterface
public function __construct(Build $build, LoggerInterface $logger = null)
{
$this->build = $build;
$this->store = Factory::getStore('Build');
$this->store = Factory::getStore('Build', 'PHPCensor');
$this->buildLogger = new BuildLogger($logger, $build);

View file

@ -292,7 +292,7 @@ class ProjectBase extends Model
*/
public function getBuildConfig()
{
$rtn = $this->data['build_config'];
$rtn = $this->data['build_config'];
return $rtn;
}

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
@ -7,7 +8,7 @@
* @link https://www.phptesting.org/
*/
namespace PHPCI\Plugin\Option;
namespace PHPCensor\Plugin\Option;
/**
* Class PhpUnitOptions validates and parse the option for the PhpUnitV2 plugin
@ -212,10 +213,10 @@ class PhpUnitOptions
*
* @return string[] path of files
*/
public function getConfigFiles($altPath = '')
public function getConfigFiles($altPath = null)
{
$configFiles = $this->getArgument('configuration');
if (empty($configFiles)) {
if (empty($configFiles) && $altPath) {
$configFile = self::findConfigFile($altPath);
if ($configFile) {
$configFiles[] = $configFile;
@ -262,7 +263,7 @@ class PhpUnitOptions
);
foreach ($files as $file) {
if (is_file($buildPath . $file)) {
if (file_exists($buildPath . $file)) {
return $file;
}
}

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
@ -7,15 +8,15 @@
* @link https://www.phptesting.org/
*/
namespace PHPCI\Plugin;
namespace PHPCensor\Plugin;
use PHPCI;
use PHPCI\Builder;
use PHPCI\Helper\Lang;
use PHPCI\Model\Build;
use PHPCI\Model\BuildError;
use PHPCI\Plugin\Option\PhpUnitOptions;
use PHPCI\Plugin\Util\PhpUnitResult;
use PHPCensor;
use PHPCensor\Builder;
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError;
use PHPCensor\Plugin\Option\PhpUnitOptions;
use PHPCensor\Plugin\Util\PhpUnitResult;
/**
* PHP Unit Plugin - A rewrite of the original PHP Unit plugin
@ -25,7 +26,7 @@ use PHPCI\Plugin\Util\PhpUnitResult;
* @package PHPCI
* @subpackage Plugins
*/
class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
{
protected $phpci;
protected $build;
@ -112,14 +113,8 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
{
$options = clone $this->options;
$buildPath = $this->build->getBuildPath() . DIRECTORY_SEPARATOR;
$currentPath = getcwd();
// Change the directory
chdir($buildPath);
// Save the results into a json file
$jsonFile = tempnam(dirname($buildPath), 'jLog_');
$jsonFile = tempnam(RUNTIME_DIR, 'jLog_');
$options->addArgument('log-json', $jsonFile);
// Removes any current configurations files
@ -129,9 +124,6 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
$cmd = $this->phpci->findBinary('phpunit') . ' %s "%s"';
$success = $this->phpci->executeCommand($cmd, $arguments, $directory);
// Change to che original path
chdir($currentPath);
$this->processResults($jsonFile);
return $success;
@ -146,18 +138,11 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
*/
protected function runConfigFile($configFile)
{
$options = clone $this->options;
$runFrom = $options->getRunFrom();
$options = clone $this->options;
$buildPath = $this->build->getBuildPath() . DIRECTORY_SEPARATOR;
if ($runFrom) {
$originalPath = getcwd();
// Change the directory
chdir($buildPath . $runFrom);
}
// Save the results into a json file
$jsonFile = tempnam($this->phpci->buildPath, 'jLog_');
$jsonFile = tempnam(RUNTIME_DIR, 'jLog_');
$options->addArgument('log-json', $jsonFile);
// Removes any current configurations files
@ -169,11 +154,6 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
$cmd = $this->phpci->findBinary('phpunit') . ' %s %s';
$success = $this->phpci->executeCommand($cmd, $arguments, $options->getTestsPath());
if (!empty($originalPath)) {
// Change to che original path
chdir($originalPath);
}
$this->processResults($jsonFile);
return $success;
@ -188,7 +168,8 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
*/
protected function processResults($jsonFile)
{
if (is_file($jsonFile)) {
var_dump('fuck!');
if (file_exists($jsonFile)) {
$parser = new PhpUnitResult($jsonFile, $this->build->getBuildPath());
$this->build->storeMeta('phpunit-data', $parser->parse()->getResults());
@ -200,7 +181,7 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
$this->phpci, 'php_unit', $error['message'], $severity, $error['file'], $error['line']
);
}
@unlink($jsonFile);
} else {
throw new \Exception('JSON output file does not exist: ' . $jsonFile);
}

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
@ -7,7 +8,7 @@
* @link https://www.phptesting.org/
*/
namespace PHPCI\Plugin\Util;
namespace PHPCensor\Plugin\Util;
/**
* Class PhpUnitResult parses the results for the PhpUnitV2 plugin

View file

@ -8,9 +8,9 @@
* @link https://www.phptesting.org/
*/
namespace Tests\PHPCI\Plugin;
namespace Tests\PHPCensor\Plugin;
use PHPCI\Plugin\Option\PhpUnitOptions;
use PHPCensor\Plugin\Option\PhpUnitOptions;
/**
* Unit test for the PHPUnitOptions parser
@ -124,8 +124,8 @@ class PhpUnitOptionsTest extends \PHPUnit_Framework_TestCase
$this->assertEmpty($options->getDirectories());
$this->assertEmpty($options->getConfigFiles());
$files = $options->getConfigFiles(PHPCI_DIR);
$files = $options->getConfigFiles(ROOT_DIR);
$this->assertFileExists(PHPCI_DIR . $files[0]);
$this->assertFileExists(ROOT_DIR . $files[0]);
}
}

View file

@ -8,7 +8,7 @@
* @link https://www.phptesting.org/
*/
namespace Tests\PHPCI\Plugin;
namespace Tests\PHPCensor\Plugin;
/**
* Unit test for the PHPUnit plugin.
@ -20,11 +20,11 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
public function testSingleConfigFile()
{
$options = array(
'config' => PHPCI_DIR . 'phpunit.xml'
'config' => ROOT_DIR . 'phpunit.xml'
);
$mockPlugin = $this->getPluginBuilder($options)->setMethods(array('runConfigFile'))->getMock();
$mockPlugin->expects($this->once())->method('runConfigFile')->with(PHPCI_DIR . 'phpunit.xml');
$mockPlugin->expects($this->once())->method('runConfigFile')->with(ROOT_DIR . 'phpunit.xml');
$mockPlugin->execute();
}
@ -33,14 +33,14 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
{
$options = array(
'config' => array(
PHPCI_DIR . 'phpunit1.xml',
PHPCI_DIR . 'phpunit2.xml',
ROOT_DIR . 'phpunit1.xml',
ROOT_DIR . 'phpunit2.xml',
)
);
$mockPlugin = $this->getPluginBuilder($options)->setMethods(array('runConfigFile'))->getMock();
$mockPlugin->expects($this->exactly(2))->method('runConfigFile')->withConsecutive(
array(PHPCI_DIR . 'phpunit1.xml'), array(PHPCI_DIR . 'phpunit2.xml')
array(ROOT_DIR . 'phpunit1.xml'), array(ROOT_DIR . 'phpunit2.xml')
);
$mockPlugin->execute();
@ -60,12 +60,12 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
->setMethods(array('addRecord'))
->getMock();
$mockBuild = $this->getMockBuilder('\PHPCI\Model\Build')->getMock();
$mockBuilder = $this->getMockBuilder('\PHPCI\Builder')
$mockBuild = $this->getMockBuilder('\PHPCensor\Model\Build')->getMock();
$mockBuilder = $this->getMockBuilder('\PHPCensor\Builder')
->setConstructorArgs(array($mockBuild, $loggerMock))
->setMethods(array('executeCommand'))->getMock();
return $this->getMockBuilder('PHPCI\Plugin\PhpUnitV2')->setConstructorArgs(
return $this->getMockBuilder('PHPCensor\Plugin\PhpUnit')->setConstructorArgs(
array($mockBuilder, $mockBuild, $options)
);
}
@ -102,7 +102,7 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
public function testProcessResultsFromConfig()
{
$options = array(
'config' => PHPCI_DIR . 'phpunit.xml'
'config' => ROOT_DIR . 'phpunit.xml'
);
$mockPlugin = $this->getPluginBuilder($options)->setMethods(array('processResults'))->getMock();
@ -114,7 +114,7 @@ class PhpUnitTest extends \PHPUnit_Framework_TestCase
public function testProcessResultsFromDir()
{
$options = array(
'directory' => PHPCI_DIR . 'Tests'
'directory' => ROOT_DIR . 'Tests'
);
$mockPlugin = $this->getPluginBuilder($options)->setMethods(array('processResults'))->getMock();

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
@ -7,9 +8,9 @@
* @link https://www.phptesting.org/
*/
namespace Tests\PHPCI\Plugin\Util;
namespace Tests\PHPCensor\Plugin\Util;
use PHPCI\Plugin\Util\PhpUnitResult;
use PHPCensor\Plugin\Util\PhpUnitResult;
/**
* Class PhpUnitResultTest parses the results for the PhpUnitV2 plugin
@ -23,7 +24,7 @@ class PhpUnitResultTest extends \PHPUnit_Framework_TestCase
public function testInitParse()
{
$buildPath = '/path/to/build';
$parser = new PhpUnitResult(PHPCI_DIR . 'Tests/PHPCI/Plugin/SampleFiles/phpunit_money.txt', $buildPath);
$parser = new PhpUnitResult(ROOT_DIR . 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt', $buildPath);
$output = $parser->parse()->getResults();
$errors = $parser->getErrors();
@ -49,7 +50,7 @@ class PhpUnitResultTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException('\Exception', 'Failed to parse the JSON output');
$buildPath = '/path/to/build';
$parser = new PhpUnitResult(PHPCI_DIR . 'Tests/PHPCI/Plugin/SampleFiles/invalid_format.txt', $buildPath);
$parser = new PhpUnitResult(ROOT_DIR . 'tests/PHPCensor/Plugin/SampleFiles/invalid_format.txt', $buildPath);
$parser->parse();
}
}