tests/GameOfLife/GameOfLifeTest.php
/**
     * Checks whether the initialize() function works as expected.
     *
     * @param array $_optionParserReturnValues The return values of the option parser in the format array("method", "returnValue")
     * @param bool $_expectedReturnValue The expected return value of the initialize() function
     *
     * @dataProvider canBeInitializedProvider()
     * @covers \GameOfLife\GameOfLife::__construct()
     * @covers \GameOfLife\GameOfLife::initialize()
     *
     * @throws ReflectionException
     */
Checks whether the initialize() function works as expected.
@param array $_optionParserReturnValues The return values of the option parser in the format array("method", "returnValue")
@param bool $_expectedReturnValue The expected return value of the initialize() function




Checks whether the initialize () function works as expected . @param array $_optionParserReturnValues The return values of the option parser in the format array ( " method " " returnValue " ) @param bool $_expectedReturnValue The expected return value of the initialize () function
public function testCanBeInitialized(array $_optionParserReturnValues, Bool $_expectedReturnValue)
    {
        $optionHandlerMock = $this->getMockBuilder(\OptionHandler\OptionHandler::class)
                                  ->getMock();
        $optionParserMock = $this->getMockBuilder(\OptionHandler\OptionParser::class)
                                 ->disableOriginalConstructor()
                                 ->getMock();
        $optionHandlerMock->expects($this->exactly(1))
                          ->method("initializeOptions")
                          ->willReturn(null);
        $optionHandlerMock->expects($this->exactly(count($_optionParserReturnValues)))
                          ->method("optionParser")
                          ->willReturn($optionParserMock);
        foreach ($_optionParserReturnValues as $methodName => $returnValue)
        {
            if ($methodName == "parseBoardOptions" && $returnValue == false)
            {
                $optionParserMock->expects($this->exactly(1))
                                 ->method($methodName)
                                 ->willThrowException(new \Exception("Board is empty."));
            }
            else
            {
                $optionParserMock->expects($this->exactly(1))
                                 ->method($methodName)
                                 ->willReturn($returnValue);
            }
        }
        $this->expectOutputRegex("/.*/");
        $gameOfLife = new GameOfLife();
        $optionsMock = $this->getMockBuilder(\Ulrichsg\Getopt::class)
                            ->getMock();
        $reflectionClass = new ReflectionClass(\GameOfLife\GameOfLife::class);
        $reflectionProperty = $reflectionClass->getProperty("optionHandler");
        $reflectionProperty->setAccessible(true);
        $reflectionProperty->setValue($gameOfLife, $optionHandlerMock);
        $reflectionProperty = $reflectionClass->getProperty("options");
        $reflectionProperty->setAccessible(true);
        $reflectionProperty->setValue($gameOfLife, $optionsMock);
        $canSimulationBeStarted = $gameOfLife->initialize();
        $this->assertEquals($_expectedReturnValue, $canSimulationBeStarted);
    }
public function testCanBeInitialized ( array $ _optionParserReturnValues , Bool $ _expectedReturnValue ) { $ optionHandlerMock = $ this -> getMockBuilder ( \ OptionHandler \ OptionHandler :: class ) -> getMock ( ) ; $ optionParserMock = $ this -> getMockBuilder ( \ OptionHandler \ OptionParser :: class ) -> disableOriginalConstructor ( ) -> getMock ( ) ; $ optionHandlerMock -> expects ( $ this -> exactly ( 1 ) ) -> method ( " initializeOptions " ) -> willReturn ( null ) ; $ optionHandlerMock -> expects ( $ this -> exactly ( count ( $ _optionParserReturnValues ) ) ) -> method ( " optionParser " ) -> willReturn ( $ optionParserMock ) ; foreach ( $ _optionParserReturnValues as $ methodName => $ returnValue ) { if ( $ methodName == " parseBoardOptions " && $ returnValue == false ) { $ optionParserMock -> expects ( $ this -> exactly ( 1 ) ) -> method ( $ methodName ) -> willThrowException ( new \ Exception ( " Board is empty. " ) ) ; } else { $ optionParserMock -> expects ( $ this -> exactly ( 1 ) ) -> method ( $ methodName ) -> willReturn ( $ returnValue ) ; } } $ this -> expectOutputRegex ( " /.*/ " ) ; $ gameOfLife = new GameOfLife ( ) ; $ optionsMock = $ this -> getMockBuilder ( \ Ulrichsg \ Getopt :: class ) -> getMock ( ) ; $ reflectionClass = new ReflectionClass ( \ GameOfLife \ GameOfLife :: class ) ; $ reflectionProperty = $ reflectionClass -> getProperty ( " optionHandler " ) ; $ reflectionProperty -> setAccessible ( true ) ; $ reflectionProperty -> setValue ( $ gameOfLife , $ optionHandlerMock ) ; $ reflectionProperty = $ reflectionClass -> getProperty ( " options " ) ; $ reflectionProperty -> setAccessible ( true ) ; $ reflectionProperty -> setValue ( $ gameOfLife , $ optionsMock ) ; $ canSimulationBeStarted = $ gameOfLife -> initialize ( ) ; $ this -> assertEquals ( $ _expectedReturnValue , $ canSimulationBeStarted ) ; }
Checks whether the initialize() function works as expected.
Checks whether the initialize () function works as expected .
// Hide output