Пример #1
0
                    }
                }
            }
            expect($check)->toBe(5);
        });
        it("parses declare", function () {
            $filename = 'spec/Fixture/Parser/Declare';
            $content = file_get_contents($filename . '.php');
            $parsed = Parser::debug($content);
            expect($parsed)->toBe(file_get_contents($filename . '.txt'));
            $parsed = Parser::parse($content);
            expect(Parser::unparse($parsed))->toBe($content);
        });
        it("parses declare as block", function () {
            $filename = 'spec/Fixture/Parser/DeclareAsBlock';
            $content = file_get_contents($filename . '.php');
            $parsed = Parser::debug($content);
            expect($parsed)->toBe(file_get_contents($filename . '.txt'));
            $parsed = Parser::parse($content);
            expect(Parser::unparse($parsed))->toBe($content);
        });
        it("parses interfaces", function () {
            $filename = 'spec/Fixture/Parser/Interface';
            $content = file_get_contents($filename . '.php');
            $parsed = Parser::debug($content);
            expect($parsed)->toBe(file_get_contents($filename . '.txt'));
            $parsed = Parser::parse($content);
            expect(Parser::unparse($parsed))->toBe($content);
        });
    });
});
Пример #2
0
 });
 describe("->process()", function () {
     beforeEach(function () {
         $this->path = 'spec/Fixture/Jit/Patcher';
         $this->patcher = new Filter();
     });
     it("patches class's methods", function () {
         $nodes = Parser::parse(file_get_contents($this->path . '/Example.php'));
         $expected = file_get_contents($this->path . '/ExampleProcessed.php');
         $actual = Parser::unparse($this->patcher->process($nodes));
         expect($actual)->toBe($expected);
     });
     it("patches trait's methods", function () {
         $nodes = Parser::parse(file_get_contents($this->path . '/ExampleTrait.php'));
         $expected = file_get_contents($this->path . '/ExampleTraitProcessed.php');
         $actual = Parser::unparse($this->patcher->process($nodes));
         expect($actual)->toBe($expected);
     });
 });
 describe("->register()", function () {
     it("registers a classes/methods", function () {
         $filter = new Filter();
         expect($filter->registered())->toBe(true);
         $filter->register('My\\Name\\Space\\ClassName');
         expect($filter->registered())->toBe(['My\\Name\\Space\\ClassName' => []]);
         $filter->register('My\\Name\\Space\\MyClass3', 'foo');
         expect($filter->registered())->toBe(['My\\Name\\Space\\ClassName' => [], 'My\\Name\\Space\\MyClass3' => ['foo' => true]]);
         $filter->register('My\\Name\\Space\\MyClass3', 'bar');
         expect($filter->registered())->toBe(['My\\Name\\Space\\ClassName' => [], 'My\\Name\\Space\\MyClass3' => ['foo' => true, 'bar' => true]]);
     });
 });
Пример #3
0
 /**
  * Runs file patchers.
  *
  * @param  string $code The source code to process.
  * @param  string $path The file path of the source code.
  * @return string       The patched source code.
  */
 public function process($code, $path = null)
 {
     if (!$code) {
         return '';
     }
     $nodes = Parser::parse($code);
     foreach ($this->_patchers as $patcher) {
         $patcher->process($nodes, $path);
     }
     return Parser::unparse($nodes);
 }