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
 protected function getPathItBelongsTo(ImprovedClassSource $classSource)
 {
     foreach ($this->paths as $path) {
         if ($path->belongsTo($classSource->getFullName())) {
             return $path;
         }
     }
     throw new \Exception('Err 912123132: Cant find path that "' . $classSource->getFullName() . '" would belong to!');
 }
 public function getNode(ImprovedClassSource $classSource)
 {
     //Namespace
     $code = $this->builderFactory->namespace($classSource->getNamespace());
     //Adds use to header of file
     foreach ($classSource->getImports() as $import) {
         $code->addStmt($this->builderFactory->use($import->getFullName()));
     }
     $classCode = $this->classGenerator->generate($classSource);
     foreach ($classSource->getMethods() as $method) {
         $result = $this->methodFactory->generate($method);
         $classCode->addStmt($result);
     }
     $code->addStmt($classCode);
     return $code->getNode();
 }
Ejemplo n.º 4
0
 public function generate(ImprovedClassSource $classSource)
 {
     //Building class.
     $classCode = $this->builderFactory->class($classSource->getName());
     //Add parent to class.
     if ($classSource->hasParent()) {
         $classCode->extend($classSource->getParentName());
     }
     //Add interfaces
     foreach ($classSource->getInterfaces() as $interface) {
         $classCode->implement($interface->getName());
     }
     //Add traits
     foreach ($classSource->getTraits() as $trait) {
         $classCode->addStmt($this->createTrait($trait));
     }
     foreach ($classSource->getProperties() as $property) {
         $classCode->addStmt($this->createClassProperty($property));
     }
     return $classCode;
 }
 protected function provideSourceWithTrait() : ImprovedClassSource
 {
     $source = new ImprovedClassSource($this->provideClassType());
     return $source->addTrait($this->provideTraitType1());
 }
 public function let(Path $path, ImprovedClassSource $classSource)
 {
     $classSource->getFullName()->willReturn('Namespace\\ClassName');
     $this->beConstructedWith($path, $classSource);
 }
Ejemplo n.º 7
0
 public function getFileName() : string
 {
     return $this->path->getFileNameFor($this->classSource->getFullName());
 }
Ejemplo n.º 8
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;
 }
 public function let(ImprovedClassSource $classSource)
 {
     $classSource->getProperties()->willReturn([]);
     $this->beConstructedWith($classSource);
 }
Ejemplo n.º 10
0
 public function it_will_create_file_resource(ImprovedClassSource $classSource, $path1)
 {
     $classSource->getFullName()->willReturn('Namespace\\ClassName');
     $path1->belongsTo('Namespace\\ClassName')->willReturn(true);
     $this->create($classSource)->shouldReturnAnInstanceOf(FileResource::class);
 }