public function create(ClassType $classType) { $source = $this->sourceFactory->create($classType); $param = $this->definitionFactory->createParameter('id', new StringType()); //Add constructor method. $source->addConstructorMethod($this->definitionFactory->createConstructorMethod([$param])); //Add __toString() method. $source->addMethod($this->definitionFactory->createToStringMethod($param)); //Add static create() method. $source->addMethod($this->definitionFactory->createUuidCreateMethod($classType)); //Add Ramsey\Uuid\Uuid to imports. $source->addImport(ClassType::create('Ramsey\\Uuid\\Uuid')); return $source; }
public function it_will_create_source_from_given_class_type(ClassSourceFactory $sourceFactory, DefinitionFactory $definitionFactory, ClassType $classType, ImprovedClassSource $classSource, Parameter $parameter, ConstructorMethod $constructorMethod, ToStringMethod $toStringMethod, UuidCreateMethod $uuidCreateMethod) { $sourceFactory->create($classType)->willReturn($classSource); $definitionFactory->createParameter('id', Argument::type(StringType::class))->shouldBeCalled()->willReturn($parameter); $definitionFactory->createConstructorMethod([$parameter])->shouldBeCalled()->willReturn($constructorMethod); $definitionFactory->createToStringMethod($parameter)->shouldBeCalled()->willReturn($toStringMethod); $definitionFactory->createUuidCreateMethod($classType)->shouldBeCalled()->willReturn($uuidCreateMethod); $this->create($classType)->shouldReturn($classSource); }