diff --git a/src/Factory/SimpleFactory.php b/src/Factory/SimpleFactory.php index c1a8ec6e..35bd2792 100644 --- a/src/Factory/SimpleFactory.php +++ b/src/Factory/SimpleFactory.php @@ -11,6 +11,8 @@ class SimpleFactory implements Factory { + private $parser; + public function createMatcher() : Matcher { return new Matcher($this->buildMatchers()); @@ -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() ); @@ -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; } } diff --git a/tests/MatcherTest.php b/tests/MatcherTest.php index fd639a60..f80e8b78 100644 --- a/tests/MatcherTest.php +++ b/tests/MatcherTest.php @@ -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 */ '{