protected function putCode($path, Method $method)
    {
        // In the generated class, the repository is passed as argument.
        // Create a repository here so that we can run the code successfully.
        $method->getClass()->addImport(new Import('Puli\\Manager\\Tests\\Factory\\Generator\\Fixtures\\TestRepository'));
        $method->setBody(<<<EOF
\$repo = new TestRepository();
{$method->getBody()}
EOF
);
        parent::putCode($path, $method);
    }
Example #2
0
 public function testClearBody()
 {
     $this->method->setBody("\$foo = 'bar';");
     $this->method->clearBody();
     $this->assertSame('', $this->method->getBody());
 }
Example #3
0
    public function testWriteMethodWithBodyAndReturnValue()
    {
        $method = new Method('doSomething');
        $method->setBody('$foo = \'bar\';');
        $method->setReturnValue(new ReturnValue('$foo'));
        $this->class->addMethod($method);
        $this->writer->writeClass($this->class);
        $expected = <<<EOF
<?php

class MyClass
{
    /**
     * @return mixed
     */
    public function doSomething()
    {
        \$foo = 'bar';

        return \$foo;
    }
}

EOF;
        $this->assertFileSame($expected, $this->tempDir . '/MyClass.php');
    }