From fc0e5a235485b580ba64571ea130a32e1efd7a5e Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 11 Aug 2019 09:23:36 +0200 Subject: [PATCH] JSON full text maching fixed (#167) --- src/Factory/SimpleFactory.php | 13 +++++++++++-- tests/MatcherTest.php | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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 7998e0d0..b5c2d1f7 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 */ '{