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); }
public function testClearBody() { $this->method->setBody("\$foo = 'bar';"); $this->method->clearBody(); $this->assertSame('', $this->method->getBody()); }
protected function putCode($path, Method $method) { $imports = 'use ' . implode(";\nuse ", $method->getClass()->getImports()) . ";\n"; file_put_contents($path, "<?php\nnamespace Puli\\Test;\n{$imports}\n" . $method->getBody()); // echo file_get_contents($path); }