예제 #1
0
 /**
  * @param FileGenerator $file
  * @param Type          $type
  *
  * @return string
  */
 public function generate(FileGenerator $file, $type)
 {
     $class = $file->getClass() ?: new ClassGenerator();
     $class->setNamespaceName($type->getNamespace());
     $class->setName($type->getName());
     $this->ruleSet->applyRules(new TypeContext($class, $type));
     foreach ($type->getProperties() as $property) {
         $this->ruleSet->applyRules(new PropertyContext($class, $type, $property));
     }
     $file->setClass($class);
     return $file->generate();
 }
예제 #2
0
 function it_generates_types(RuleSetInterface $ruleSet, FileGenerator $file, ClassGenerator $class)
 {
     $type = new Type('MyNamespace', 'MyType', ['prop1' => 'string']);
     $property = $type->getProperties()[0];
     $file->generate()->willReturn('code');
     $file->getClass()->willReturn($class);
     $class->setNamespaceName('MyNamespace')->shouldBeCalled();
     $class->setName('MyType')->shouldBeCalled();
     $file->setClass($class)->shouldBeCalled();
     $ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type) {
         return $context instanceof TypeContext && $context->getType() === $type;
     }))->shouldBeCalled();
     $ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type, $property) {
         return $context instanceof PropertyContext && $context->getType() === $type && $context->getProperty() === $property;
     }))->shouldBeCalled();
     $this->generate($file, $type)->shouldReturn('code');
 }
예제 #3
0
 /**
  * @param FileGenerator $file
  * @param TypeMap       $typeMap
  *
  * @return string
  */
 public function generate(FileGenerator $file, $typeMap)
 {
     $this->ruleSet->applyRules(new ClassMapContext($file, $typeMap));
     return $file->generate();
 }
예제 #4
0
 /**
  * @param RuleInterface $rule
  *
  * @return Config
  */
 public function addRule(RuleInterface $rule)
 {
     $this->ruleSet->addRule($rule);
     return $this;
 }
예제 #5
0
 function it_generates_classmaps(RuleSetInterface $ruleSet, FileGenerator $file, TypeMap $typeMap)
 {
     $ruleSet->applyRules(Argument::type(ClassMapContext::class))->shouldBeCalled();
     $file->generate()->willReturn('code');
     $this->generate($file, $typeMap)->shouldReturn('code');
 }