Coduo\PHPMatcher\Matcher\Pattern\Expander\Count::match PHP Method

match() public method

public match ( $value ) : boolean
$value
return boolean
    public function match($value)
    {
        if (!is_array($value)) {
            $this->error = sprintf("Count expander require \"array\", got \"%s\".", new StringConverter($value));
            return false;
        }
        if (count($value) !== $this->value) {
            $this->error = sprintf("Expected count of %s is %s.", new StringConverter($value), new StringConverter($this->value));
            return false;
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * @dataProvider invalidCasesProvider
  */
 public function test_error_when_matching_fail($boundary, $value, $errorMessage)
 {
     $expander = new Count($boundary);
     $this->assertFalse($expander->match($value));
     $this->assertEquals($errorMessage, $expander->getError());
 }