Skip to content

Commit

Permalink
include ArrayMatcher in OrMatcher to fix issues with `@null@||@array@…
Browse files Browse the repository at this point in the history
…` pattern (#214)

Co-authored-by: michal <[email protected]>
  • Loading branch information
mtomala and michal authored Oct 9, 2020
1 parent b8ddc75 commit 5c3f3cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Factory/MatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher
{
$scalarMatchers = $this->buildScalarMatchers($parser, $backtrace);
$arrayMatcher = $this->buildArrayMatcher($scalarMatchers, $parser, $backtrace);
$orMatcher = $this->buildOrMatcher([$scalarMatchers, $arrayMatcher], $backtrace);

// Matchers are registered in order of matching
// 1) all scalars
Expand All @@ -39,7 +40,7 @@ protected function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher
new Matcher\JsonMatcher($arrayMatcher, $backtrace),
new Matcher\XmlMatcher($arrayMatcher, $backtrace),
$arrayMatcher,
new Matcher\OrMatcher($backtrace, $scalarMatchers),
$orMatcher,
new Matcher\TextMatcher($scalarMatchers, $backtrace, $parser),
]
);
Expand Down Expand Up @@ -88,7 +89,19 @@ protected function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : M
);
}

protected function buildParser(Backtrace $backtrace) : Parser
private function buildOrMatcher(array $orMatchers, Backtrace $backtrace) : Matcher\OrMatcher
{
return new Matcher\OrMatcher(
$backtrace,
new Matcher\ChainMatcher(
'or',
$backtrace,
$orMatchers
)
);
}

private function buildParser(Backtrace $backtrace) : Parser
{
return new Parser(new Lexer(), new Parser\ExpanderInitializer($backtrace));
}
Expand Down
8 changes: 7 additions & 1 deletion tests/OrMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ public static function orExamples()
['ipsum lorem', '@[email protected]("lorem")||@[email protected]("lorem")', true],
['[email protected]', '@[email protected]()||@null@', true],
[null, '@[email protected]()||@null@', true],
[null, '@[email protected]()||@null@', true],
['2014-08-19', '@[email protected]()||@integer@', true],
[null, '@integer@||@string@', false],
[1, '@[email protected](10)||@[email protected]("10")', false],
[[], '@array@||@null@', true],
[[1, 2, 3], '@[email protected](3)||@null@', true],
[null, '@array@||@null@', true],
[null, '@[email protected](3)||@null@', true],
['ipsum', '@array@||@string@', true],
['ipsum', '@array@||@null@', false],
[1, '@array@||@null@', false],
];
}
}

0 comments on commit 5c3f3cb

Please sign in to comment.