Ejemplo n.º 1
0
 /**
  * @param string $methodName
  * @param string $snippetToInsert
  * @param string $code
  * @return string
  */
 private function getUpdatedCode($methodName, $snippetToInsert, $code)
 {
     if ('__construct' === $methodName) {
         return $this->codeWriter->insertMethodFirstInClass($code, $snippetToInsert);
     }
     return $this->codeWriter->insertMethodLastInClass($code, $snippetToInsert);
 }
Ejemplo n.º 2
0
    function it_generates_class_method_from_resource($io, $tpl, $fs, Resource $resource, CodeWriter $codeWriter)
    {
        $codeWithoutMethod = <<<CODE
<?php

namespace Acme;

class App
{
}

CODE;
        $codeWithMethod = <<<CODE
<?php

namespace Acme;

class App
{
METHOD
}

CODE;
        $values = array('%name%' => 'setName', '%arguments%' => '$argument1');
        $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
        $resource->getSrcClassname()->willReturn('Acme\\App');
        $tpl->render('method', $values)->willReturn(null);
        $tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
        $codeWriter->insertMethodLastInClass($codeWithoutMethod, 'METHOD')->willReturn($codeWithMethod);
        $fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
        $fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();
        $this->generate($resource, array('name' => 'setName', 'arguments' => array('everzet')));
    }