From 2914e3a87d83444a1e943f4c696d48c0d3b7eb7e Mon Sep 17 00:00:00 2001 From: meadsteve Date: Thu, 16 May 2013 10:52:33 +0100 Subject: [PATCH] Added a unit test case for the PHPUnit plugin. It's not fully comprehensive but good to get these started. --- Tests/PHPCI/Plugin/PHPUnitTest.php | 123 +++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Tests/PHPCI/Plugin/PHPUnitTest.php diff --git a/Tests/PHPCI/Plugin/PHPUnitTest.php b/Tests/PHPCI/Plugin/PHPUnitTest.php new file mode 100644 index 00000000..b4cec846 --- /dev/null +++ b/Tests/PHPCI/Plugin/PHPUnitTest.php @@ -0,0 +1,123 @@ +mockCiBuilder = $this->getMock( + '\PHPCI\Builder', + array(), + array(), + "mockBuilder", + false + ); + $this->mockCiBuilder->buildPath = "/"; + + $this->loadPhpUnitWithOptions(); + } + + protected function loadPhpUnitWithOptions($arrOptions = array()) + { + $this->testedPhpUnit = new PHPUnit($this->mockCiBuilder, $arrOptions); + } + + /** + * @covers PHPUnit::execute + */ + public function testExecute_ReturnsTrueWithoutArgs() + { + $returnValue = $this->testedPhpUnit->execute(); + $expectedReturn = true; + + $this->assertEquals($expectedReturn, $returnValue); + } + + /** + * @covers PHPUnit::execute + * @covers PHPUnit::runDir + */ + public function testExecute_CallsExecuteCommandOnceWhenGivenStringDirectory() + { + chdir('/'); + + $this->loadPhpUnitWithOptions(array( + 'directory' => "Fake/Test/Path" + )); + + $this->mockCiBuilder->expects($this->once())->method("executeCommand"); + + $returnValue = $this->testedPhpUnit->execute(); + } + + /** + * @covers PHPUnit::execute + * @covers PHPUnit::runConfigFile + */ + public function testExecute_CallsExecuteCommandOnceWhenGivenStringConfig() + { + chdir('/'); + + $this->loadPhpUnitWithOptions(array( + 'config' => "Fake/Test/config.xml" + )); + + $this->mockCiBuilder->expects($this->once())->method("executeCommand"); + + $returnValue = $this->testedPhpUnit->execute(); + } + + /** + * @covers PHPUnit::execute + * @covers PHPUnit::runDir + */ + public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayDirectory() + { + chdir('/'); + + $this->loadPhpUnitWithOptions(array( + 'directory' => array(0, 1) + )); + + $this->mockCiBuilder->expects($this->at(0))->method("executeCommand"); + $this->mockCiBuilder->expects($this->at(1))->method("executeCommand"); + + $returnValue = $this->testedPhpUnit->execute(); + } + + /** + * @covers PHPUnit::execute + * @covers PHPUnit::runConfigFile + */ + public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayConfig() + { + chdir('/'); + + $this->loadPhpUnitWithOptions(array( + 'config' => array(0, 1) + )); + + $this->mockCiBuilder->expects($this->at(0))->method("executeCommand"); + $this->mockCiBuilder->expects($this->at(1))->method("executeCommand"); + + $returnValue = $this->testedPhpUnit->execute(); + } + +} \ No newline at end of file