public function it_will_show_interfaces_in_imports(InterfaceType $interface1, InterfaceType $interface2) { $interface1->getFullName()->willReturn('InterfaceType1'); $interface2->getFullName()->willReturn('InterfaceType2'); $this->addInterface($interface1)->shouldReturn($this); $this->addInterface($interface2)->shouldReturn($this); $this->getImports()->shouldReturn([$interface1, $interface2]); }
public function generate(RepositoryConstructorMethod $method) { $constructor = $this->builderFactory->method('__construct')->makePublic(); $constructor->addParam($this->createMethodParam(new Parameter('eventStore', InterfaceType::create('Broadway\\EventStore\\EventStoreInterface')))); $constructor->addParam($this->createMethodParam(new Parameter('eventBus', InterfaceType::create('Broadway\\EventHandling\\EventBusInterface')))); $constructor->addParam($this->createMethodParamWithDefaultValue(new Parameter('eventStreamDecorators', new ArrayType()), [])); $constructor->addStmt(new Node\Expr\StaticCall(new Name('parent'), '__construct', [new Node\Expr\Variable('eventStore'), new Node\Expr\Variable('eventBus'), new Name($method->getModelClassType()->getName() . '::class'), new Node\Expr\New_(new Name('PublicConstructorAggregateFactory')), new Node\Expr\Variable('eventStreamDecorators')])); return $constructor; }
public function create(ClassType $classType, array $parameters) { $source = $this->sourceFactory->create($classType); //Add constructor method. $source->addConstructorMethod($this->definitionFactory->createConstructorMethod($parameters)); //Adds Broadway ReadModelInterface. $source->addInterface(InterfaceType::create('Broadway\\ReadModel\\ReadModelInterface')); //Adds Broadway SerializableInterface. $source->addInterface(InterfaceType::create('Broadway\\Serializer\\SerializableInterface')); //Adds serialize() method. $source->addMethod($this->definitionFactory->createSerializeMethod($source)); //Adds static deserialize() method. $source->addMethod($this->definitionFactory->createDeserializeMethod($source)); $source->addMethod($this->definitionFactory->createReadModelIdGetterMethod($parameters[0])); return $source; }
/** * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function generate(ImprovedClassSource $improvedClassSource) { $specClassType = ClassType::create('spec\\' . $improvedClassSource->getClassType()->getFullName() . 'Spec'); $specSource = $this->factory->create($specClassType); foreach ($improvedClassSource->getImports() as $import) { if (false === $import instanceof TraitType) { $specSource->addImport($import); } } $specSource->addImport($improvedClassSource->getClassType()); $specSource->addImport(ClassType::create('Prophecy\\Argument')); $specSource->addParent(ClassType::create('PhpSpec\\ObjectBehavior')); $initializable = [$improvedClassSource->getClassType()]; if ($improvedClassSource->hasParent()) { $initializable[] = $improvedClassSource->getParent(); } foreach ($improvedClassSource->getInterfaces() as $interface) { $initializable[] = $interface; } $lets = $improvedClassSource->getConstructorParameters(); foreach ($improvedClassSource->getConstructorParameters() as $methodParameter) { if ($methodParameter->hasClass()) { $specSource->addImport($methodParameter->getClassType()); } } //@TODO: foreach ($improvedClassSource->getMethods() as $method) { if ($method instanceof RepositoryConstructorMethod) { $lets[] = new Parameter('eventStore', InterfaceType::create('Broadway\\EventStore\\EventStoreInterface')); $lets[] = new Parameter('eventBus', InterfaceType::create('Broadway\\EventHandling\\EventBusInterface')); $lets[] = new Parameter('eventStreamDecorators', new ArrayType()); } } $specSource->addMethod(new LetMethod($lets)); $specSource->addMethod(new InitializableMethod($initializable)); $skip = false; if (true === $improvedClassSource->hasParent()) { if ($improvedClassSource->getParent()->getFullName() === 'Broadway\\EventSourcing\\EventSourcingRepository') { $skip = true; } } if (false === $skip) { $specSource->addMethod(new ExposeConstructorArgumentsAsGettersMethod($lets)); } return $specSource; }