diff --git a/src/PHPCensor/Builder.php b/src/PHPCensor/Builder.php index c46838d5..40280acf 100644 --- a/src/PHPCensor/Builder.php +++ b/src/PHPCensor/Builder.php @@ -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); diff --git a/src/PHPCensor/Model/Base/ProjectBase.php b/src/PHPCensor/Model/Base/ProjectBase.php index 09096d01..e0eff10c 100644 --- a/src/PHPCensor/Model/Base/ProjectBase.php +++ b/src/PHPCensor/Model/Base/ProjectBase.php @@ -292,7 +292,7 @@ class ProjectBase extends Model */ public function getBuildConfig() { - $rtn = $this->data['build_config']; + $rtn = $this->data['build_config']; return $rtn; } diff --git a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php b/src/PHPCensor/Plugin/Option/PhpUnitOptions.php index 4387da1c..50a684cd 100644 --- a/src/PHPCensor/Plugin/Option/PhpUnitOptions.php +++ b/src/PHPCensor/Plugin/Option/PhpUnitOptions.php @@ -1,4 +1,5 @@ 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; } } diff --git a/src/PHPCensor/Plugin/PhpUnit.php b/src/PHPCensor/Plugin/PhpUnit.php index ca8c5bc2..666ae0ff 100644 --- a/src/PHPCensor/Plugin/PhpUnit.php +++ b/src/PHPCensor/Plugin/PhpUnit.php @@ -1,4 +1,5 @@ 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); } diff --git a/src/PHPCensor/Plugin/Util/PhpUnitResult.php b/src/PHPCensor/Plugin/Util/PhpUnitResult.php index 76303d40..a8264e21 100644 --- a/src/PHPCensor/Plugin/Util/PhpUnitResult.php +++ b/src/PHPCensor/Plugin/Util/PhpUnitResult.php @@ -1,4 +1,5 @@ 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]); } } diff --git a/tests/PHPCensor/Plugin/PhpUnitTest.php b/tests/PHPCensor/Plugin/PhpUnitTest.php index d9dfbf47..5882eaf6 100644 --- a/tests/PHPCensor/Plugin/PhpUnitTest.php +++ b/tests/PHPCensor/Plugin/PhpUnitTest.php @@ -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(); diff --git a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php index c9e1dab3..cd5e0851 100644 --- a/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php +++ b/tests/PHPCensor/Plugin/Util/PhpUnitResultTest.php @@ -1,4 +1,5 @@ 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(); } }