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