예제 #1
0
 /** @return SearchEngine */
 protected function getSearchEngine()
 {
     if ($this->searchEngine) {
         return $this->searchEngine;
     }
     $engine = new SearchEngine();
     $phpConverter = $this->getPhpConverter();
     $engine->registerStrategy(new PhpSearchStrategy($phpConverter));
     $engine->registerStrategy(new LineRegexSearchStrategy(), 20);
     $engine->registerStrategy(new SameSearchStrategy(), 10);
     $engine->registerStrategy(new LineNumberSearchStrategy());
     foreach ($this->searchStrategies as $priority => $strategies) {
         foreach ($strategies as $strategy) {
             $engine->registerStrategy($strategy, $priority);
         }
     }
     return $engine;
 }
예제 #2
0
 function it_checks_pattern_existence_below_the_given_line(SearchEngine $searchEngine, SearchStrategy $searchStrategy, Text $text)
 {
     $pattern = 'No one expects the Spanish inquisition!';
     $foundLineNumber = 42;
     $searchEngine->resolve($pattern)->willReturn($searchStrategy);
     $searchStrategy->findBelow($text, $pattern, 0)->willReturn($foundLineNumber);
     $this->hasBelow($text, $pattern, 0)->shouldBe(true);
     $searchStrategy->findBelow($text, $pattern, 0)->willReturn(false);
     $this->hasBelow($text, $pattern, 0)->shouldBe(false);
 }
예제 #3
0
 /**
  * Checks the presence of the given pattern in the Text below the current
  * line.
  *
  * @param Text  $text
  * @param mixed $pattern
  * @param int   $location
  *
  * @return bool
  *
  * @throws \Gnugat\Redaktilo\Exception\NotSupportedException If the given pattern isn't supported by any registered strategy
  *
  * @api
  */
 public function hasBelow(Text $text, $pattern, $location = null)
 {
     $searchStrategy = $this->searchEngine->resolve($pattern);
     $foundLineNumber = $searchStrategy->findBelow($text, $pattern, $location);
     return false !== $foundLineNumber;
 }