示例#1
0
    /**
     * @dataProvider basicClassCodeProvider
     */
    public function testRemoveMethodRemovesMethod($code)
    {
        $parser = new PropelPHPParser($code);
        $parser->removeMethod('bar1');
        $expected = <<<EOF
<?php
class Foo {
\t
\tprotected \$bar2;
\t
\tpublic function bar2()
\t{
\t\t// this is bar2
\t}

\t/**
\t * This is the bar3 method
\t */
\tpublic function bar3()
\t{
\t\t// this is bar3
\t}

\tpublic function bar4()
\t{
\t\t// this is bar4 with a curly brace }
\t\techo '}';
\t}
}
EOF;
        $this->assertEquals($expected, $parser->getCode());
    }
    /**
     * @dataProvider basicClassCodeProvider
     */
    public function testRemoveMethodRemovesMethod($code)
    {
        $parser = new PropelPHPParser($code);
        $parser->removeMethod('bar1');
        $expected = <<<EOF
<?php
class Foo
{

    protected \$bar2;

    public function bar2()
    {
        // this is bar2
    }

    /**
     * This is the bar3 method
     */
    public function bar3()
    {
        // this is bar3
    }

    public function bar4()
    {
        // this is bar4 with a curly brace }
        echo '}';
    }
}
EOF;
        $this->assertEquals($expected, $parser->getCode());
    }
 public function objectFilter(&$script)
 {
     $script = preg_replace('#(implements Persistent)#', '$1, EventDispatcherAwareModelInterface', $script);
     // rename the dummy_construct to __construct if __construct does not exists
     if (strpos($script, 'function __construct') === false) {
         $script = str_replace('function dummy_construct', 'function __construct', $script);
     }
     $parser = new PropelPHPParser($script, true);
     $parser->removeMethod('dummy_construct');
     $oldCode = $parser->findMethod('__construct');
     $newCode = substr_replace($oldCode, $this->addConstructHook() . '}', strrpos($oldCode, '}'));
     $parser->replaceMethod('__construct', $newCode);
     $script = $parser->getCode();
 }