tests/GameOfLife/GameOfLifeTest.php
/**
     * Checks whether a simulation can be successfully started and stopped.
     *
     * @param int $_amountLoops The amount of loops for which the simulation will be allowed to run
     * @param String $_endLoopMethodName The name of the method that will return true in order to end the loop
     *
     * @dataProvider startSimulationProvider()
     *
     * @covers \GameOfLife\GameOfLife::startSimulation()
     *
     * @throws \Exception
     */
Checks whether a simulation can be successfully started and stopped.
@param int $_amountLoops The amount of loops for which the simulation will be allowed to run
@param String $_endLoopMethodName The name of the method that will return true in order to end the loop





@throws \Exception
Checks whether a simulation can be successfully started and stopped . @param int $_amountLoops The amount of loops for which the simulation will be allowed to run @param String $_endLoopMethodName The name of the method that will return true in order to end the loop @throws \ Exception
public function testCanStartSimulation(int $_amountLoops, String $_endLoopMethodName)
    {
        $gameOfLife = new GameOfLife();
        $optionsMock = $this->getMockBuilder(\Ulrichsg\Getopt::class)
                            ->getMock();
        $optionsMock->expects($this->exactly(10))
                    ->method("getOption")
                    ->withConsecutive(array("template"), array("template"), array("templatePosX"), array("templatePosY"),
                                      array("templatePosX"), array("templatePosY"), array("width"), array("height"),
                                      array("invertTemplate"))
                    ->willReturn("blinker", "blinker", null, null, null, null, null, null, null);
        $input = new TemplateInput();
        $output = new ConsoleOutput();
        $board = new Board(5, 5, 200, true);
        $gameLogicMock = $this->getMockBuilder(\GameOfLife\GameLogic::class)
                              ->disableOriginalConstructor()
                              ->getMock();
        $counter = 0;
        $loopCounter = 0;
        $endLoopMethodNames = array("isMaxStepsReached", "isLoopDetected", "isBoardEmpty");
        while ($loopCounter < $_amountLoops)
        {
            foreach ($endLoopMethodNames as $endLoopMethodName)
            {
                $gameLogicMock->expects($this->at($counter))
                              ->method($endLoopMethodName)
                              ->willReturn(false);
                $counter++;
            }
            $gameLogicMock->expects($this->at($counter))
                          ->method("calculateNextBoard")
                          ->willReturn(null);
            $counter++;
            $loopCounter++;
        }
        $endLoopMethodPosition = array_search($_endLoopMethodName, $endLoopMethodNames) + $counter;
        $gameLogicMock->expects($this->at($endLoopMethodPosition))
                      ->method($_endLoopMethodName)
                      ->willReturn(true);
        \setPrivateAttribute($gameOfLife, "options", $optionsMock);
        \setPrivateAttribute($gameOfLife, "input", $input);
        \setPrivateAttribute($gameOfLife, "output", $output);
        \setPrivateAttribute($gameOfLife, "board", $board);
        \setPrivateAttribute($gameOfLife, "gameLogic", $gameLogicMock);
        $this->expectOutputRegex("/.*Simulation finished.*/s");
        $gameOfLife->startSimulation();
    }
public function testCanStartSimulation ( int $ _amountLoops , String $ _endLoopMethodName ) { $ gameOfLife = new GameOfLife ( ) ; $ optionsMock = $ this -> getMockBuilder ( \ Ulrichsg \ Getopt :: class ) -> getMock ( ) ; $ optionsMock -> expects ( $ this -> exactly ( 10 ) ) -> method ( " getOption " ) -> withConsecutive ( array ( " template " ) , array ( " template " ) , array ( " templatePosX " ) , array ( " templatePosY " ) , array ( " templatePosX " ) , array ( " templatePosY " ) , array ( " width " ) , array ( " height " ) , array ( " invertTemplate " ) ) -> willReturn ( " blinker " , " blinker " , null , null , null , null , null , null , null ) ; $ input = new TemplateInput ( ) ; $ output = new ConsoleOutput ( ) ; $ board = new Board ( 5 , 5 , 200 , true ) ; $ gameLogicMock = $ this -> getMockBuilder ( \ GameOfLife \ GameLogic :: class ) -> disableOriginalConstructor ( ) -> getMock ( ) ; $ counter = 0 ; $ loopCounter = 0 ; $ endLoopMethodNames = array ( " isMaxStepsReached " , " isLoopDetected " , " isBoardEmpty " ) ; while ( $ loopCounter < $ _amountLoops ) { foreach ( $ endLoopMethodNames as $ endLoopMethodName ) { $ gameLogicMock -> expects ( $ this -> at ( $ counter ) ) -> method ( $ endLoopMethodName ) -> willReturn ( false ) ; $ counter ++ ; } $ gameLogicMock -> expects ( $ this -> at ( $ counter ) ) -> method ( " calculateNextBoard " ) -> willReturn ( null ) ; $ counter ++ ; $ loopCounter ++ ; } $ endLoopMethodPosition = array_search ( $ _endLoopMethodName , $ endLoopMethodNames ) + $ counter ; $ gameLogicMock -> expects ( $ this -> at ( $ endLoopMethodPosition ) ) -> method ( $ _endLoopMethodName ) -> willReturn ( true ) ; \ setPrivateAttribute ( $ gameOfLife , " options " , $ optionsMock ) ; \ setPrivateAttribute ( $ gameOfLife , " input " , $ input ) ; \ setPrivateAttribute ( $ gameOfLife , " output " , $ output ) ; \ setPrivateAttribute ( $ gameOfLife , " board " , $ board ) ; \ setPrivateAttribute ( $ gameOfLife , " gameLogic " , $ gameLogicMock ) ; $ this -> expectOutputRegex ( " /.*Simulation finished.*/s " ) ; $ gameOfLife -> startSimulation ( ) ; }
Checks whether a simulation can be successfully started and stopped.
Checks whether a simulation can be successfully started and stopped .
// Hide output