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
#213)

* include ArrayMatcher in OrMatcher to fix issues with `@null@||@array@` pattern

* more test cases

Co-authored-by: michal <[email protected]>
  • Loading branch information
mtomala and michal authored Oct 9, 2020
1 parent efd3b2f commit 2e8ed68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Factory/MatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function buildMatchers(Parser $parser, Backtrace $backtrace) : Matcher\C
}

$matchers[] = $arrayMatcher;
$matchers[] = new Matcher\OrMatcher($backtrace, $scalarMatchers);
$matchers[] = $this->buildOrMatcher($backtrace, $matchers);
$matchers[] = new Matcher\TextMatcher($scalarMatchers, $backtrace, $parser);

return new Matcher\ChainMatcher(
Expand Down Expand Up @@ -88,6 +88,18 @@ private function buildScalarMatchers(Parser $parser, Backtrace $backtrace) : Mat
);
}

private function buildOrMatcher(Backtrace $backtrace, array $orMatchers) : 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 @@ -21,10 +21,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],
];
}

Expand Down

0 comments on commit 2e8ed68

Please sign in to comment.