Skip to content

Commit

Permalink
JSON full text maching fixed (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Aug 11, 2019
1 parent 300c41a commit fc0e5a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Factory/SimpleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class SimpleFactory implements Factory
{
private $parser;

public function createMatcher() : Matcher
{
return new Matcher($this->buildMatchers());
Expand Down Expand Up @@ -39,7 +41,8 @@ protected function buildOrMatcher() : Matcher\ChainMatcher
$arrayMatcher = new Matcher\ArrayMatcher(
new Matcher\ChainMatcher([
$orMatcher,
$scalarMatchers
$scalarMatchers,
new Matcher\TextMatcher($scalarMatchers, $this->buildParser())
]),
$this->buildParser()
);
Expand Down Expand Up @@ -76,6 +79,12 @@ protected function buildScalarMatchers() : Matcher\ChainMatcher

protected function buildParser() : Parser
{
return new Parser(new Lexer(), new Parser\ExpanderInitializer());
if ($this->parser) {
return $this->parser;
}

$this->parser = new Parser(new Lexer(), new Parser\ExpanderInitializer());

return $this->parser;
}
}
10 changes: 10 additions & 0 deletions tests/MatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ public function jsonDataProvider()
"nextPage": "@string@"
}',
],
'matches json values with full text matcher' => [
/** @lang JSON */
'{
"url": "/accounts/9a7dae2d-d135-4bd7-b202-b3e7e91aaecd"
}',
/** @lang JSON */
'{
"url": "/accounts/@uuid@"
}',
],
'matches none elements - empty array' => [
/** @lang JSON */
'{
Expand Down

0 comments on commit fc0e5a2

Please sign in to comment.