Skip to content

include ArrayMatcher in OrMatcher to fix issues with @null@||@array@ #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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