From e90a69ed9fddec2e387cb4c7b944a64f8efb4afd Mon Sep 17 00:00:00 2001 From: mmp4k Date: Sat, 4 Nov 2017 22:01:04 +0100 Subject: [PATCH] 0.1.11 fix bug on uuid strategy --- proophgen | 2 +- .../PhpSpecGenerator/PhpSpecAggregateCodeSpec.php | 4 ++++ .../PhpSpecGenerator/PhpSpecEventSourcedSpec.php | 1 + .../PhpSpecGenerator/PhpSpecEventSpec.php | 1 + .../PhpSpecGenerator/PhpSpecExceptionNotFoundSpec.php | 1 + .../PhpSpecGenerator/PhpSpecInMemoryRepositorySpec.php | 1 + .../PhpSpecCommandGeneratorSpec.php | 2 ++ .../PhpSpecGenerator/PhpSpecAggregateCode.php | 2 +- .../PhpSpecGenerator/PhpSpecEvent.php | 2 +- .../PhpSpecGenerator/PhpSpecEventSourced.php | 8 ++++---- .../PhpSpecGenerator/PhpSpecExceptionNotFound.php | 2 +- .../PhpSpecGenerator/PhpSpecInMemoryRepository.php | 2 +- .../PhpSpecCommandGenerator/PhpSpecCommandGenerator.php | 2 +- .../IdStrategy/RamseyUuidIdStrategy.php | 6 ++++++ .../GossiCodeGenerator/IdStrategy/StringIdStrategy.php | 5 +++++ src/Pilsniak/ProophGen/IdStrategy.php | 1 + 16 files changed, 32 insertions(+), 10 deletions(-) diff --git a/proophgen b/proophgen index c5731e1..a044402 100755 --- a/proophgen +++ b/proophgen @@ -10,7 +10,7 @@ try { use Symfony\Component\Console\Application; -$application = new Application('proophgen', '0.1.10'); +$application = new Application('proophgen', '0.1.11'); $application->add(new \Pilsniak\Command\DoCommand()); $application->add(new \Pilsniak\Command\ValueObjectCommand()); diff --git a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCodeSpec.php b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCodeSpec.php index 3e6fe0a..6982473 100644 --- a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCodeSpec.php +++ b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCodeSpec.php @@ -50,6 +50,8 @@ class UserSpec extends ObjectBehavior { $aggregateRoot = new AggregateRoot('Model\User', [new Event('UserRegistered')]); $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); + $idStrategy->convertToString(Argument::any())->willReturnArgument(0); $this->execute($aggregateRoot)->filename()->shouldBe('./spec/Model/UserSpec.php'); $this->execute($aggregateRoot)->fileContent()->shouldBe($content); } @@ -80,6 +82,8 @@ class UserSpec extends ObjectBehavior { $aggregateRoot = new AggregateRoot('Model\User', [new Event('UserRegistered', true)]); $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); + $idStrategy->convertToString(Argument::any())->willReturnArgument(0); $this->execute($aggregateRoot)->filename()->shouldBe('./spec/Model/UserSpec.php'); $this->execute($aggregateRoot)->fileContent()->shouldBe($content); } diff --git a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourcedSpec.php b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourcedSpec.php index 3b6448a..642823f 100644 --- a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourcedSpec.php +++ b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourcedSpec.php @@ -28,6 +28,7 @@ function it_generates_code(IdStrategy $idStrategy) $aggregateRoot = new AggregateRoot('Model\User', [new Event('UserRegistered')]); $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); $this->execute($aggregateRoot)->filename()->shouldBe('./spec/Infrastructure/User/EventSourcedSpec.php'); $this->execute($aggregateRoot)->fileContent()->shouldBe($this->expectedContent()); } diff --git a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSpec.php b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSpec.php index e3efaea..ddd869a 100644 --- a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSpec.php +++ b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSpec.php @@ -29,6 +29,7 @@ function it_generates_code(IdStrategy $idStrategy) $aggregateRoot = new AggregateRoot('Model\User', [$event]); $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); $this->execute($aggregateRoot, $event)->filename()->shouldBe('./spec/Model/User/Event/UserRegisteredSpec.php'); $this->execute($aggregateRoot, $event)->fileContent()->shouldBe($this->expectedContent()); } diff --git a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFoundSpec.php b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFoundSpec.php index bd6dc8b..a45c101 100644 --- a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFoundSpec.php +++ b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFoundSpec.php @@ -28,6 +28,7 @@ function it_is_initializable(IdStrategy $idStrategy) $aggregateRoot = new AggregateRoot('Model\User', [new Event('UserRegistered')]); $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); $this->execute($aggregateRoot)->filename()->shouldBe('./spec/Model/User/Exception/UserNotFoundSpec.php'); $this->execute($aggregateRoot)->fileContent()->shouldBe($this->expectedContent()); } diff --git a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepositorySpec.php b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepositorySpec.php index 7d58842..0e16651 100644 --- a/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepositorySpec.php +++ b/spec/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepositorySpec.php @@ -28,6 +28,7 @@ function it_generates_code(IdStrategy $idStrategy) $aggregateRoot = new AggregateRoot('Model\User', [new Event('UserRegistered')]); $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); $this->execute($aggregateRoot)->filename()->shouldBe('./spec/Infrastructure/User/InMemorySpec.php'); $this->execute($aggregateRoot)->fileContent()->shouldBe($this->expectedContent()); } diff --git a/spec/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGeneratorSpec.php b/spec/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGeneratorSpec.php index 4dd75f2..a0fecaa 100644 --- a/spec/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGeneratorSpec.php +++ b/spec/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGeneratorSpec.php @@ -54,6 +54,8 @@ class RegisterUserSpec extends ObjectBehavior { "; $idStrategy->modifyPhpClass(Argument::any())->shouldBeCalled(); $idStrategy->phpSpecIdGenerator(Argument::any())->shouldBeCalled(); + $idStrategy->value()->willReturn('id'); + $idStrategy->convertToString(Argument::any())->willReturnArgument(0); $command = new Command('Model\Command\RegisterUser'); $this->execute($command)->filename()->shouldBe('./spec/Model/Command/RegisterUserSpec.php'); $this->execute($command)->fileContent()->shouldBe($content); diff --git a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCode.php b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCode.php index 740bcc9..2fc3763 100644 --- a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCode.php +++ b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecAggregateCode.php @@ -44,7 +44,7 @@ private function generateFileContent(AggregateRoot $aggregateRoot): string $phpClass->setMethod( PhpMethod::create('it_returns_id') - ->setBody('$this->id()->shouldBe($this->_id());') + ->setBody($this->idStrategy->convertToString('$this->id()').'->shouldBe('.$this->idStrategy->convertToString('$this->_id()').');') ); foreach ($aggregateRoot->events() as $event) { diff --git a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEvent.php b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEvent.php index 999ac23..0c34e2d 100644 --- a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEvent.php +++ b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEvent.php @@ -59,7 +59,7 @@ private function generateFileName(AggregateRoot $aggregateRoot, Event $event): s private function generateBodyForCreateWithIdMethod(AggregateRoot $aggregateRoot, Event $event): string { $body = '$this->beConstructedThrough(\'create\', [$this->_id()]);' . "\n"; - $body .= '$this->aggregateId()->shouldBe(\'id\');'; + $body .= '$this->aggregateId()->shouldBe(\''.$this->idStrategy->value().'\');'; return $body; } diff --git a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourced.php b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourced.php index 04654ce..de6fce8 100644 --- a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourced.php +++ b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecEventSourced.php @@ -117,8 +117,8 @@ private function generateBodyForSaveMethod(AggregateRoot $aggregateRoot): string private function generateBodyForGetMethod(AggregateRoot $aggregateRoot): string { - $body = '$repository->getAggregateRoot(\'id\')->shouldBeCalled();' . "\n"; - $body .= '$repository->getAggregateRoot(\'id\')->willReturn($'.$aggregateRoot->variableName().');' . "\n"; + $body = '$repository->getAggregateRoot(\''.$this->idStrategy->value().'\')->shouldBeCalled();' . "\n"; + $body .= '$repository->getAggregateRoot(\''.$this->idStrategy->value().'\')->willReturn($'.$aggregateRoot->variableName().');' . "\n"; $body .= '$this->get($this->_id())->shouldBe($'.$aggregateRoot->variableName().');' . "\n"; return $body; @@ -126,8 +126,8 @@ private function generateBodyForGetMethod(AggregateRoot $aggregateRoot): string private function generateBodyForGetExceptionMethod(AggregateRoot $aggregateRoot): string { - $body = '$repository->getAggregateRoot(\'id\')->shouldBeCalled();' . "\n"; - $body .= '$repository->getAggregateRoot(\'id\')->willReturn(null);' . "\n"; + $body = '$repository->getAggregateRoot(\''.$this->idStrategy->value().'\')->shouldBeCalled();' . "\n"; + $body .= '$repository->getAggregateRoot(\''.$this->idStrategy->value().'\')->willReturn(null);' . "\n"; $body .= '$this->shouldThrow('.$aggregateRoot->exceptionClassName().'::class)->during(\'get\', [$this->_id()]);' . "\n"; return $body; diff --git a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFound.php b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFound.php index ae36730..814da96 100644 --- a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFound.php +++ b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecExceptionNotFound.php @@ -63,7 +63,7 @@ private function generateFileName(AggregateRoot $aggregateRoot): string private function generateBodyForCreateMethod(AggregateRoot $aggregateRoot): string { $body = '$this->beConstructedThrough(\'withId\', [$this->_id()]);' . "\n"; - $body .= '$this->getMessage()->shouldBe(\''.$aggregateRoot->className().' with ID id does not exists.\');'; + $body .= '$this->getMessage()->shouldBe(\''.$aggregateRoot->className().' with ID '.$this->idStrategy->value().' does not exists.\');'; return $body; } diff --git a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepository.php b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepository.php index 669c31d..42593f1 100644 --- a/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepository.php +++ b/src/Pilsniak/GossiCodeGenerator/AggregateRootGenerator/PhpSpecGenerator/PhpSpecInMemoryRepository.php @@ -83,7 +83,7 @@ private function generateFileName(AggregateRoot $aggregateRoot): string private function generateBodyForGetMethod(AggregateRoot $aggregateRoot): string { - $body = '$this->getWrappedObject()->data[\'id\'] = $'.$aggregateRoot->variableName().'->getWrappedObject();' . "\n"; + $body = '$this->getWrappedObject()->data[\''.$this->idStrategy->value().'\'] = $'.$aggregateRoot->variableName().'->getWrappedObject();' . "\n"; $body .= '$this->get($this->_id());'; return $body; diff --git a/src/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGenerator.php b/src/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGenerator.php index d1f8392..b6b8fd5 100644 --- a/src/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGenerator.php +++ b/src/Pilsniak/GossiCodeGenerator/CommandGenerator/PhpSpecCommandGenerator/PhpSpecCommandGenerator.php @@ -51,7 +51,7 @@ private function generateFileContent(Command $command): string $phpClass->setMethod( PhpMethod::create('it_returns_id') - ->setBody('$this->id()->shouldBe($this->_id());') + ->setBody($this->idStrategy->convertToString('$this->id()').'->shouldBe('.$this->idStrategy->convertToString('$this->_id()').');') ); $phpClass->setMethod( diff --git a/src/Pilsniak/GossiCodeGenerator/IdStrategy/RamseyUuidIdStrategy.php b/src/Pilsniak/GossiCodeGenerator/IdStrategy/RamseyUuidIdStrategy.php index 8f51ec3..caa6f71 100644 --- a/src/Pilsniak/GossiCodeGenerator/IdStrategy/RamseyUuidIdStrategy.php +++ b/src/Pilsniak/GossiCodeGenerator/IdStrategy/RamseyUuidIdStrategy.php @@ -40,6 +40,7 @@ public function phpSpecIdGenerator(AbstractPhpStruct $class) protected function generateBodyForIdPhpSpecGenerator() { + return "return Uuid::fromString('dd76226a-926d-4603-ab5a-69010722510e');"; $body = '$prophet = new \Prophecy\Prophet;'."\n"; $body .= '$prophecy = $prophet->prophesize(UuidInterface::class);'."\n"; @@ -49,4 +50,9 @@ protected function generateBodyForIdPhpSpecGenerator() return $body; } + + public function value(): string + { + return 'dd76226a-926d-4603-ab5a-69010722510e'; + } } diff --git a/src/Pilsniak/GossiCodeGenerator/IdStrategy/StringIdStrategy.php b/src/Pilsniak/GossiCodeGenerator/IdStrategy/StringIdStrategy.php index a630c08..4c3a2ca 100644 --- a/src/Pilsniak/GossiCodeGenerator/IdStrategy/StringIdStrategy.php +++ b/src/Pilsniak/GossiCodeGenerator/IdStrategy/StringIdStrategy.php @@ -36,4 +36,9 @@ public function phpSpecIdGenerator(AbstractPhpStruct $class) ->setBody('return \'id\';') ); } + + public function value(): string + { + return 'id'; + } } diff --git a/src/Pilsniak/ProophGen/IdStrategy.php b/src/Pilsniak/ProophGen/IdStrategy.php index b24cd64..15176ce 100644 --- a/src/Pilsniak/ProophGen/IdStrategy.php +++ b/src/Pilsniak/ProophGen/IdStrategy.php @@ -6,6 +6,7 @@ interface IdStrategy { + public function value(): string; public function type(): string; public function convertToType(string $expression): string; public function convertToString(string $expression): string;