Skip to content

Commit

Permalink
0.1.11 fix bug on uuid strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mmp4k committed Nov 4, 2017
1 parent ba3403f commit e90a69e
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion proophgen
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ 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;
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -49,4 +50,9 @@ protected function generateBodyForIdPhpSpecGenerator()

return $body;
}

public function value(): string
{
return 'dd76226a-926d-4603-ab5a-69010722510e';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public function phpSpecIdGenerator(AbstractPhpStruct $class)
->setBody('return \'id\';')
);
}

public function value(): string
{
return 'id';
}
}
1 change: 1 addition & 0 deletions src/Pilsniak/ProophGen/IdStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e90a69e

Please sign in to comment.