/** * @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(); }
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'); }
/** * @param FileGenerator $file * @param TypeMap $typeMap * * @return string */ public function generate(FileGenerator $file, $typeMap) { $this->ruleSet->applyRules(new ClassMapContext($file, $typeMap)); return $file->generate(); }
/** * @param RuleInterface $rule * * @return Config */ public function addRule(RuleInterface $rule) { $this->ruleSet->addRule($rule); return $this; }
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'); }