public function TODO_it_can_generate_spec_source_from_class_source($factory, ImprovedClassSource $classSource, ClassType $classType, ImprovedClassSource $specSource)
 {
     $classSource->getClassType()->willReturn($classType);
     $classType->getFullName()->willReturn('Namespace\\Class');
     $factory->create(Argument::type(ClassType::class))->willReturn($specSource);
     $this->generate($classSource)->shouldReturn($specSource);
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }