tests/GameOfLife/Rules/CustomRuleTest.php
/**
     * Checks whether the rule can be initialized.
     *
     * @param String|null $_rulesString The rules string
     * @param int[] $_expectedRulesBirth The expected birth rules array
     * @param int[] $_expectedRulesStayAlive The expected stay alive rules array
     * @param String $_expectedErrorMessage The expected error message
     *
     * @dataProvider parseRuleStringsProvider()
     *
     * @covers \Rule\CustomRule::initialize()
     * @covers \Rule\CustomRule::isStayAliveSlashBirthString()
     * @covers \Rule\CustomRule::parseStayAliveSlashBirthString()
     * @covers \Rule\CustomRule::isAlternateNotationString()
     * @covers \Rule\CustomRule::parseAlternateNotationString()
     * @covers \Rule\CustomRule::getRulesFromNumericString()
     */
Checks whether the rule can be initialized.
@param String|null $_rulesString The rules string
@param int[] $_expectedRulesBirth The expected birth rules array
@param int[] $_expectedRulesStayAlive The expected stay alive rules array
@param String $_expectedErrorMessage The expected error message




Checks whether the rule can be initialized . @param String|null $_rulesString The rules string @param int [] $_expectedRulesBirth The expected birth rules array @param int [] $_expectedRulesStayAlive The expected stay alive rules array @param String $_expectedErrorMessage The expected error message
public function testCanParseRuleStrings($_rulesString = "", array $_expectedRulesBirth, array $_expectedRulesStayAlive, String $_expectedErrorMessage = "")
    {
        $optionsMock = $this->getMockBuilder(\Ulrichsg\Getopt::class)
                            ->getMock();
        if ($_rulesString === "")
        {
            $optionsMock->expects($this->exactly(2))
                        ->method("getOption")
                        ->withConsecutive(array("rulesString"), array("rulesBirth"))
                        ->willReturn(null, null);
        }
        elseif ($_expectedErrorMessage)
        {
            $optionsMock->expects($this->exactly(2))
                        ->method("getOption")
                        ->withConsecutive(array("rulesString"), array("rulesString"))
                        ->willReturn($_rulesString, $_rulesString);
        }
        else
        {
            $optionsMock->expects($this->exactly(3))
                ->method("getOption")
                ->withConsecutive(array("rulesString"), array("rulesString"), array("antiRules"))
                ->willReturn($_rulesString, $_rulesString, null);
        }
        $rule = new CustomRule();
        $this->expectOutputRegex("/.*/");
        if ($optionsMock instanceof Ulrichsg\Getopt)
        {
            $exceptionOccurred = false;
            try
            {
                $rule->initialize($optionsMock);
            }
            catch (\Exception $_exception)
            {
                $exceptionOccurred = true;
                $this->assertEquals($_expectedErrorMessage, $_exception->getMessage());
            }
            if ($_expectedErrorMessage) $this->assertTrue($exceptionOccurred);
            else
            {
                $this->assertFalse($exceptionOccurred);
                $this->assertEquals($_expectedRulesBirth, $rule->rulesBirth());
                $this->assertEquals($_expectedRulesStayAlive, $rule->rulesStayAlive());
            }
        }
    }
public function testCanParseRuleStrings ( $ _rulesString = " " , array $ _expectedRulesBirth , array $ _expectedRulesStayAlive , String $ _expectedErrorMessage = " " ) { $ optionsMock = $ this -> getMockBuilder ( \ Ulrichsg \ Getopt :: class ) -> getMock ( ) ; if ( $ _rulesString === " " ) { $ optionsMock -> expects ( $ this -> exactly ( 2 ) ) -> method ( " getOption " ) -> withConsecutive ( array ( " rulesString " ) , array ( " rulesBirth " ) ) -> willReturn ( null , null ) ; } elseif ( $ _expectedErrorMessage ) { $ optionsMock -> expects ( $ this -> exactly ( 2 ) ) -> method ( " getOption " ) -> withConsecutive ( array ( " rulesString " ) , array ( " rulesString " ) ) -> willReturn ( $ _rulesString , $ _rulesString ) ; } else { $ optionsMock -> expects ( $ this -> exactly ( 3 ) ) -> method ( " getOption " ) -> withConsecutive ( array ( " rulesString " ) , array ( " rulesString " ) , array ( " antiRules " ) ) -> willReturn ( $ _rulesString , $ _rulesString , null ) ; } $ rule = new CustomRule ( ) ; $ this -> expectOutputRegex ( " /.*/ " ) ; if ( $ optionsMock instanceof Ulrichsg \ Getopt ) { $ exceptionOccurred = false ; try { $ rule -> initialize ( $ optionsMock ) ; } catch ( \ Exception $ _exception ) { $ exceptionOccurred = true ; $ this -> assertEquals ( $ _expectedErrorMessage , $ _exception -> getMessage ( ) ) ; } if ( $ _expectedErrorMessage ) $ this -> assertTrue ( $ exceptionOccurred ) ; else { $ this -> assertFalse ( $ exceptionOccurred ) ; $ this -> assertEquals ( $ _expectedRulesBirth , $ rule -> rulesBirth ( ) ) ; $ this -> assertEquals ( $ _expectedRulesStayAlive , $ rule -> rulesStayAlive ( ) ) ; } } }
Checks whether the rule can be initialized.
Checks whether the rule can be initialized .
// Hide output