Ejemplo n.º 1
0
    public function testStripNodes()
    {
        $reader = new Reader(<<<EOF
<?php
namespace {
    class ClassName
    {
        public function foobar()
        {
            include "somefile.php";
            echo 'foobar';
        }
    }
}
EOF
);
        $expected = <<<EOF
namespace  {
    class ClassName
    {
        public function foobar()
        {
            echo 'foobar';
        }
    }
}
EOF;
        $writer = new Writer();
        $writer->apply(new NodeStripper('Expr_Include'));
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
Ejemplo n.º 2
0
    public function testStripComments()
    {
        $reader = new Reader(<<<EOF
<?php
/**
 * File docblock comment
 */

/**
 * Class docblock
 */
class ClassName
{
    /**
     * @var string Some desc
     */
    private \$var;

    /**
     * Some docblock here too
     */
    public function test()
    {
        // inline comment
        return true; // comment at end of line
        /*
            Comment
        */
        # Comment...
    }
}
EOF
);
        $expected = <<<EOF
namespace  {
    class ClassName
    {
        private \$var;
        public function test()
        {
            return true;
        }
    }
}
EOF;
        $writer = new Writer();
        $writer->apply(new CommentStripper());
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
Ejemplo n.º 3
0
    public function testWhitelistNamespace()
    {
        $reader = new Reader(<<<EOF
<?php
class ClassName
{
    public function foobar()
    {
        new \\whitelist\\NonExistingClass();
    }
}
EOF
);
        $writer = new Writer();
        $writer->apply(new NameResolver());
        $writer->apply(new NamespaceCrawler([''], ['whitelist']));
        // NonExistingClass does not resolve, but no exception is thrown
        $this->assertTrue(is_string($writer->write($reader->read('ClassName'))));
    }
Ejemplo n.º 4
0
    public function testIgnoreExtendedEmptyNamespace()
    {
        $reader = new Reader(<<<EOF
<?php
namespace foobar {
    class ClassName
    {
    }
}
EOF
);
        $expected = <<<EOF
namespace foobar {
    class ClassName
    {
    }
}
EOF;
        $writer = new Writer();
        // Assert that a empty second wrapper makes no difference
        $writer->apply(new NamespaceWrapper(''));
        $this->assertEquals($expected, $writer->write($reader->read('foobar\\ClassName')));
    }