unparse() public static method

Unparsing a node.
public static unparse ( $node ) : string
return string the unparsed file.
Beispiel #1
0
<?php

namespace Kahlan\Spec\Suite\Jit\Patcher;

use Kahlan\Jit\Parser;
use Kahlan\Jit\Patcher\Rebase;
describe("Rebase", function () {
    beforeEach(function () {
        $this->path = 'spec/Fixture/Jit/Patcher/Rebase';
        $this->patcher = new Rebase();
    });
    describe("->process()", function () {
        it("patches class's methods", function () {
            $nodes = Parser::parse(file_get_contents($this->path . '/Rebase.php'));
            $expected = file_get_contents($this->path . '/RebaseProcessed.php');
            $actual = Parser::unparse($this->patcher->process($nodes, '/the/original/path/Rebase.php'));
            expect($actual)->toBe($expected);
        });
    });
    describe("->patchable()", function () {
        it("return `true`", function () {
            expect($this->patcher->patchable('SomeClass'))->toBe(true);
        });
    });
});
Beispiel #2
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);
 }
Beispiel #3
0
{

}class InspectorKLAYER extends \\Kahlan\\Analysis\\Inspector {    public static function inspect(\$class) {\$__KPOINTCUT_ARGS__ = func_get_args(); \$__KPOINTCUT_SELF__ = isset(\$this) ? \$this : get_called_class(); if (\$__KPOINTCUT__ = \\Kahlan\\Plugin\\Pointcut::before(__METHOD__, \$__KPOINTCUT_SELF__, \$__KPOINTCUT_ARGS__)) { \$r = \$__KPOINTCUT__(\$__KPOINTCUT_SELF__, \$__KPOINTCUT_ARGS__); return \$r; }return parent::inspect(\$class);}    public static function parameters(\$class, \$method, \$data = NULL) {\$__KPOINTCUT_ARGS__ = func_get_args(); \$__KPOINTCUT_SELF__ = isset(\$this) ? \$this : get_called_class(); if (\$__KPOINTCUT__ = \\Kahlan\\Plugin\\Pointcut::before(__METHOD__, \$__KPOINTCUT_SELF__, \$__KPOINTCUT_ARGS__)) { \$r = \$__KPOINTCUT__(\$__KPOINTCUT_SELF__, \$__KPOINTCUT_ARGS__); return \$r; }return parent::parameters(\$class, \$method, \$data);}    public static function typehint(\$parameter) {\$__KPOINTCUT_ARGS__ = func_get_args(); \$__KPOINTCUT_SELF__ = isset(\$this) ? \$this : get_called_class(); if (\$__KPOINTCUT__ = \\Kahlan\\Plugin\\Pointcut::before(__METHOD__, \$__KPOINTCUT_SELF__, \$__KPOINTCUT_ARGS__)) { \$r = \$__KPOINTCUT__(\$__KPOINTCUT_SELF__, \$__KPOINTCUT_ARGS__); return \$r; }return parent::typehint(\$parameter);}}

EOD;
            expect($actual)->toBe($expected);
        });
        it("bails out when `'override'` is empty", function () {
            $this->patcher = new Layer([]);
            $nodes = Parser::parse(file_get_contents($this->path . '/Layer.php'));
            $actual = Parser::unparse($this->patcher->process($nodes));
            expect($actual)->toBe("");
        });
        it("doesn't patch classes which are not present in the `'override'` option", function () {
            $this->patcher = new Layer(['override' => ['Kahlan\\Analysis\\Debugger']]);
            $nodes = Parser::parse(file_get_contents($this->path . '/Layer.php'));
            $actual = Parser::unparse($this->patcher->process($nodes));
            $expected = <<<EOD
<?php
namespace Kahlan\\Spec\\Fixture\\Jit\\Patcher\\Layer;

class Inspector extends \\Kahlan\\Analysis\\Inspector
{

}

EOD;
            expect($actual)->toBe($expected);
        });
    });
});
Beispiel #4
0
 });
 it("parses ::class syntax", function () {
     $filename = 'spec/Fixture/Jit/Parser/StaticClassKeyword';
     $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 anonymous class", function () {
     $filename = 'spec/Fixture/Jit/Parser/AnonymousClass';
     $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 extends", function () {
     $sample = file_get_contents('spec/Fixture/Jit/Parser/Extends.php');
     $root = Parser::parse($sample);
     $check = 0;
     foreach ($root->tree as $node) {
         if ($node->type !== 'namespace') {
             continue;
         }
         expect($node->name)->toBe('Test');
         foreach ($node->tree as $node) {
             if ($node->type !== 'class') {
                 continue;
             }
             if ($node->name === 'A') {