getName() public method

public getName ( ) : string
return string
    function it_generates_static_constructor_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('%methodName%' => 'setName', '%arguments%' => '$argument1', '%returnVar%' => '$app', '%className%' => 'App', '%constructorArguments%' => '');
        $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
        $resource->getSrcClassname()->willReturn('Acme\\App');
        $resource->getName()->willReturn('App');
        $tpl->render('named_constructor_create_object', $values)->willReturn(null);
        $tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
        $codeWriter->insertAfterMethod($codeWithoutMethod, '__construct', '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('jmurphy')));
    }
Exemplo n.º 2
0
 /**
  * @param Resource $resource
  * @param string            $filepath
  *
  * @return string
  */
 protected function renderTemplate(Resource $resource, $filepath)
 {
     $values = array('%filepath%' => $filepath, '%name%' => $resource->getName(), '%namespace%' => $resource->getSrcNamespace(), '%namespace_block%' => '' !== $resource->getSrcNamespace() ? sprintf("\n\nnamespace %s;", $resource->getSrcNamespace()) : '');
     if (!($content = $this->getTemplateRenderer()->render('class', $values))) {
         $content = $this->getTemplateRenderer()->renderString($this->getTemplate(), $values);
     }
     return $content;
 }
Exemplo n.º 3
0
 /**
  * @param Resource $resource
  * @param string            $filepath
  *
  * @return string
  */
 protected function renderTemplate(Resource $resource, $filepath)
 {
     $values = array('%filepath%' => $filepath, '%name%' => $resource->getSpecName(), '%namespace%' => $resource->getSpecNamespace(), '%subject%' => $resource->getSrcClassname(), '%subject_class%' => $resource->getName());
     if (!($content = $this->getTemplateRenderer()->render('specification', $values))) {
         $content = $this->getTemplateRenderer()->renderString($this->getTemplate(), $values);
     }
     return $content;
 }
 function it_creates_folder_for_spec_if_needed($io, $tpl, $fs, Resource $resource)
 {
     $resource->getSpecName()->willReturn('AppAppSpec');
     $resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
     $resource->getSpecNamespace()->willReturn('spec\\Acme');
     $resource->getSrcClassname()->willReturn('Acme\\App');
     $resource->getName()->willReturn('App');
     $fs->pathExists('/project/spec/Acme/AppSpec.php')->willReturn(false);
     $fs->isDirectory('/project/spec/Acme')->willReturn(false);
     $fs->makeDirectory('/project/spec/Acme')->shouldBeCalled();
     $fs->putFileContents('/project/spec/Acme/AppSpec.php', Argument::any())->willReturn(null);
     $this->generate($resource);
 }
Exemplo n.º 5
0
 function it_records_that_class_was_created_in_executioncontext(Resource $resource, ExecutionContext $executionContext)
 {
     $resource->getName()->willReturn('App');
     $resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
     $resource->getSrcNamespace()->willReturn('Acme');
     $resource->getSrcClassname()->willReturn('Acme\\App');
     $this->generate($resource);
     $executionContext->addGeneratedType('Acme\\App')->shouldHaveBeenCalled();
 }
Exemplo n.º 6
0
 /**
  * @param  Resource $resource
  * @param  string            $methodName
  * @param  array             $arguments
  * @return string
  */
 private function getContent(Resource $resource, $methodName, $arguments)
 {
     $className = $resource->getName();
     $class = $resource->getSrcClassname();
     $template = new CreateObjectTemplate($this->templates, $methodName, $arguments, $className);
     if (method_exists($class, '__construct')) {
         $template = new ExistingConstructorTemplate($this->templates, $methodName, $arguments, $className, $class);
     }
     return $template->getContent();
 }