예제 #1
0
 /**
  * @covers \spriebsch\PHPca\Pattern\Pattern::oneOf
  */
 public function testOneOfMapsToRegExWithoutTrailingBlank()
 {
     $pattern = new Pattern();
     $pattern->oneOf(array(new Token(T_OPEN_TAG), new Token(T_FUNCTION)));
     $this->assertEquals('((\\bT_OPEN_TAG\\b)|(\\bT_FUNCTION\\b))', $pattern->getRegEx());
 }
예제 #2
0
 /**
  * @covers spriebsch\PHPca\Finder::findPattern
  */
 public function testFindPatternWithTwoMatches()
 {
     $file = Tokenizer::tokenize('filename', "<?php \n\n class Test { public function hello(\$a, \$b) {}\n protected function sayHello(\$a, \$b) {}} \n ?>");
     $pattern = new Pattern();
     $pattern->oneOf(array(new Token(T_PUBLIC), new Token(T_PROTECTED), new Token(T_PRIVATE)))->token(T_WHITESPACE)->token(T_FUNCTION);
     $result = Finder::findPattern($file, $pattern);
     // Since there are two matches, the result array must contain two elements
     $this->assertEquals(2, sizeof($result));
     // First result must have three elements
     $this->assertEquals(3, sizeof($result[0]));
     // The first element of the first result must be T_PUBLIC
     $this->assertEquals('T_PUBLIC', $result[0][0]->getName());
     // The last element of the first result must be T_FUNCTION
     $this->assertEquals('T_FUNCTION', $result[0][2]->getName());
     // Second result must have three elements
     $this->assertEquals(3, sizeof($result[1]));
     // The first element of the second result must be T_PROTECTED
     $this->assertEquals('T_PROTECTED', $result[1][0]->getName());
     // The last element of the second result must be T_FUNCTION
     $this->assertEquals('T_FUNCTION', $result[1][2]->getName());
 }