From 98c5a277ab4340ec3eefe83ed2d5c9cda2029b1b Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 10:43:07 -0300 Subject: [PATCH 01/81] adding new packages, changing symofony to zend-expressive and starting event aggregate model --- composer.json | 55 +++--------------- .../Model/Aggregates/Event/EventSpec.php | 29 ++++++++++ .../Model/Aggregates/Event/Event.php | 56 +++++++++++++++++++ .../Model/Aggregates/Event/EventId.php | 55 ++++++++++++++++++ .../Model/Events/Event/EventWasCreated.php | 42 ++++++++++++++ 5 files changed, 190 insertions(+), 47 deletions(-) create mode 100644 spec/Conticket/Model/Aggregates/Event/EventSpec.php create mode 100644 src/Conticket/Model/Aggregates/Event/Event.php create mode 100644 src/Conticket/Model/Aggregates/Event/EventId.php create mode 100644 src/Conticket/Model/Events/Event/EventWasCreated.php diff --git a/composer.json b/composer.json index 11b8d09..58fc0ed 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,7 @@ ], "autoload": { "psr-4": { - "": "src/", - "SymfonyStandard\\": "app/SymfonyStandard/" + "": "src/" } }, "autoload-dev": { @@ -25,63 +24,25 @@ }, "require": { "php": "~5.5|^7.0", - "symfony/symfony": "2.7.*", "doctrine/mongodb-odm": "^1.0", - "doctrine/mongodb-odm-bundle": "~3.0", - "symfony/assetic-bundle": "~2.3", - "symfony/swiftmailer-bundle": "~2.3", - "symfony/monolog-bundle": "~2.4", - "sensio/distribution-bundle": "~4.0", - "sensio/framework-extra-bundle": "~3.0,>=3.0.2", "incenteev/composer-parameter-handler": "~2.0", - "hwi/oauth-bundle": "0.4.*@dev", - "snc/redis-bundle": "~1.1", "predis/predis": "~1.0", - "friendsofsymfony/rest-bundle": "^1.7", - "jms/serializer-bundle": "^1.0", - "doctrine/doctrine-fixtures-bundle": "^2.2" + "zendframework/zend-expressive": "^1.0", + "ramsey/uuid": "^2.8", + "beberlei/assert": "^2.6", + "prooph/event-sourcing": "~4.0", + "prooph/event-store": "^6.0" }, "require-dev": { - "sensio/generator-bundle": "~2.3", "behat/behat": "3.*@stable", "behat/mink": "*@stable", "behat/mink-extension": "*", "behat/mink-selenium2-driver": "*", "behat/mink-goutte-driver": "*", - "phpunit/phpunit": "4.7.*" - }, - "scripts": { - "post-root-package-install": [ - "SymfonyStandard\\Composer::hookRootPackageInstall" - ], - "post-install-cmd": [ - "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" - ], - "post-update-cmd": [ - "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles", - "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" - ] + "phpunit/phpunit": "4.7.*", + "phpspec/phpspec": "^2.5" }, "config": { "bin-dir": "bin" - }, - "extra": { - "symfony-app-dir": "app", - "symfony-web-dir": "web", - "symfony-assets-install": "relative", - "incenteev-parameters": { - "file": "app/config/parameters.yml" - } } } diff --git a/spec/Conticket/Model/Aggregates/Event/EventSpec.php b/spec/Conticket/Model/Aggregates/Event/EventSpec.php new file mode 100644 index 0000000..daf537d --- /dev/null +++ b/spec/Conticket/Model/Aggregates/Event/EventSpec.php @@ -0,0 +1,29 @@ +beConstructedThrough('fromNameAndDescription', [ + 'Event specification by example', + 'Description of event specified by example' + ]); + } + + function it_is_initializable() + { + $this->shouldHaveType('Conticket\Model\Aggregates\Event\Event'); + } + + function it_should_return_event_id() + { + $this->aggregateId()->shouldReturnAnInstanceOf(EventId::class); + } +} diff --git a/src/Conticket/Model/Aggregates/Event/Event.php b/src/Conticket/Model/Aggregates/Event/Event.php new file mode 100644 index 0000000..129aa7a --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/Event.php @@ -0,0 +1,56 @@ +aggregateId; + } + + public static function fromNameAndDescription($name, $description) + { + Assertion::notEmpty($name, 'Name is required.'); + Assertion::notEmpty($description, 'Description is required.'); + + $event = new self(); + $event->aggregateId = new EventId(); + $event->recordThat( + EventWasCreated::fromEventAndNameAndDescription($event->aggregateId()->toString(), $name, $description) + ); + return $event; + } + + public function whenEventWasCreated(EventWasCreated $eventWasCreated) + { + $this->aggregateId = EventId::fromString($eventWasCreated->aggregateId()); + $this->name = $eventWasCreated->name(); + $this->description = $eventWasCreated->description(); + } +} diff --git a/src/Conticket/Model/Aggregates/Event/EventId.php b/src/Conticket/Model/Aggregates/Event/EventId.php new file mode 100644 index 0000000..299adf3 --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/EventId.php @@ -0,0 +1,55 @@ +id = null === $id ? self::fromString(Uuid::uuid4()->toString()) : $id; + } + + public static function fromString($id) + { + return new self($id); + } + + public function id() + { + return $this->id; + } + + public function equals(UserId $userId) + { + return $this->id() === $userId->id(); + } + + public function toString() + { + return $this->id; + } + + public function __toString() + { + return $this->id; + } +} diff --git a/src/Conticket/Model/Events/Event/EventWasCreated.php b/src/Conticket/Model/Events/Event/EventWasCreated.php new file mode 100644 index 0000000..0e676a4 --- /dev/null +++ b/src/Conticket/Model/Events/Event/EventWasCreated.php @@ -0,0 +1,42 @@ +toString(), [ + 'name' => $name, + 'description' => $description + ]); + } + + public function name() + { + return $this->payload['name']; + } + + public function description() + { + return $this->payload['description']; + } +} From 047b7f15d9b2fd0276af380ccc85ad429118443c Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 14:33:04 -0300 Subject: [PATCH 02/81] creating ticket aggregate and a value object TicketLifespan for encapsulating start and end dates logic --- .../Aggregates/Event/TicketLifespanSpec.php | 28 ++++++++++ .../Model/Aggregates/Event/Event.php | 28 +++++++++- .../Model/Aggregates/Event/TickedId.php | 55 +++++++++++++++++++ .../Model/Aggregates/Event/Ticket.php | 47 ++++++++++++++++ ...ateMustBeGreaterThanStartDateException.php | 11 ++++ .../Model/Aggregates/Event/TicketLifespan.php | 49 +++++++++++++++++ .../Model/Aggregates/Event/TicketStatus.php | 36 ++++++++++++ .../Model/Events/Event/TicketWasAdded.php | 42 ++++++++++++++ 8 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php create mode 100644 src/Conticket/Model/Aggregates/Event/TickedId.php create mode 100644 src/Conticket/Model/Aggregates/Event/Ticket.php create mode 100644 src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php create mode 100644 src/Conticket/Model/Aggregates/Event/TicketLifespan.php create mode 100644 src/Conticket/Model/Aggregates/Event/TicketStatus.php create mode 100644 src/Conticket/Model/Events/Event/TicketWasAdded.php diff --git a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php new file mode 100644 index 0000000..4a21143 --- /dev/null +++ b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php @@ -0,0 +1,28 @@ +shouldHaveType('Conticket\Model\Aggregates\Event\TicketLifespan'); + } + + function it_throws_an_exception_when_start_date_is_greater_than_end_date() + { + $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2015-01-01']); + $this->shouldThrow(TicketEndDateMustBeGreaterThanStartDateException::class); + } + + function it_should_return_datetimes_objects_on_start_and_end_methods() + { + $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2016-04-01']); + $this->start()->shouldReturnAnInstanceOf(\DateTime::class); + $this->end()->shouldReturnAnInstanceOf(\DateTime::class); + } +} diff --git a/src/Conticket/Model/Aggregates/Event/Event.php b/src/Conticket/Model/Aggregates/Event/Event.php index 129aa7a..d3184ce 100644 --- a/src/Conticket/Model/Aggregates/Event/Event.php +++ b/src/Conticket/Model/Aggregates/Event/Event.php @@ -18,7 +18,9 @@ namespace Conticket\Model\Aggregates\Event; use Prooph\EventSourcing\AggregateRoot; +use Conticket\Model\Aggregates\Ticket\TicketId; use Conticket\Model\Events\Event\EventWasCreated; +use Conticket\Model\Events\Event\TicketWasAdded; use Assert\Assertion; class Event extends AggregateRoot @@ -26,6 +28,7 @@ class Event extends AggregateRoot private $aggregateId; private $name; private $description; + private $tickets = []; private $banner; private $gateway; @@ -42,7 +45,11 @@ public static function fromNameAndDescription($name, $description) $event = new self(); $event->aggregateId = new EventId(); $event->recordThat( - EventWasCreated::fromEventAndNameAndDescription($event->aggregateId()->toString(), $name, $description) + EventWasCreated::fromEventAndNameAndDescription( + $event->aggregateId()->toString(), + $name, + $description + ) ); return $event; } @@ -53,4 +60,23 @@ public function whenEventWasCreated(EventWasCreated $eventWasCreated) $this->name = $eventWasCreated->name(); $this->description = $eventWasCreated->description(); } + + public function addTicket($name, $description) + { + $ticketId = new TicketId(); + $this->recordThat(TicketWasAdded::fromTicketAndNameAndDescription( + $ticketId->toString(), + $name, + $description + )); + } + + public function whenTicketWasAdded(TicketWasAdded $ticketWasAdded) + { + $this->tickets[] = Ticket::fromIdAndNameAndDescription( + TicketId::fromString($ticketWasAdded->aggregateId()), + $ticketWasAdded->name(), + $ticketWasAdded->description() + ); + } } diff --git a/src/Conticket/Model/Aggregates/Event/TickedId.php b/src/Conticket/Model/Aggregates/Event/TickedId.php new file mode 100644 index 0000000..d01d413 --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/TickedId.php @@ -0,0 +1,55 @@ +id = null === $id ? self::fromString(Uuid::uuid4()->toString()) : $id; + } + + public static function fromString($id) + { + return new self($id); + } + + public function id() + { + return $this->id; + } + + public function equals(UserId $userId) + { + return $this->id() === $userId->id(); + } + + public function toString() + { + return $this->id; + } + + public function __toString() + { + return $this->id; + } +} diff --git a/src/Conticket/Model/Aggregates/Event/Ticket.php b/src/Conticket/Model/Aggregates/Event/Ticket.php new file mode 100644 index 0000000..b14f760 --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/Ticket.php @@ -0,0 +1,47 @@ +aggregateId; + } + + public function fromIdAndNameAndDescription(TicketId $id, $name, $description) + { + $ticket = new self(); + $ticket->aggregateId = $id; + $ticket->name = $name; + $this->description = $description; + $this->status = TicketStatus::INACTIVE; + } +} diff --git a/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php b/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php new file mode 100644 index 0000000..e77d7e9 --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php @@ -0,0 +1,11 @@ +start = $start; + $this->end = $end; + } + + public static function fromStartAndEnd($start, $end) + { + Assertion::notEmpty($start, "Start date is required."); + Assertion::notEmpty($end, "End date is required."); + + $start = new \DateTime($start); + $end = new \DateTime($end); + + if ($start > $end) { + throw new TicketEndDateMustBeGreaterThanStartDateException(); + } + + return new self($start, $end); + } + + public function start() + { + return $this->start; + } + + public function end() + { + return $this->end; + } + + public function expiresOn(){} + + public function daysLeft(){} + + public function expired(){} + +} \ No newline at end of file diff --git a/src/Conticket/Model/Aggregates/Event/TicketStatus.php b/src/Conticket/Model/Aggregates/Event/TicketStatus.php new file mode 100644 index 0000000..d87110e --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/TicketStatus.php @@ -0,0 +1,36 @@ + 'Active', + self::INACTIVE => 'Inactive' + ]; + + public static function toString($statusCode) + { + return isset(self::$strings[$statusCode]) ? self::$strings[$statusCode] : null; + } + + private function __construct(){} +} diff --git a/src/Conticket/Model/Events/Event/TicketWasAdded.php b/src/Conticket/Model/Events/Event/TicketWasAdded.php new file mode 100644 index 0000000..c7ec0ab --- /dev/null +++ b/src/Conticket/Model/Events/Event/TicketWasAdded.php @@ -0,0 +1,42 @@ +toString(), [ + 'name' => $name, + 'description' => $description + ]); + } + + public function name() + { + return $this->payload['name']; + } + + public function description() + { + return $this->payload['description']; + } +} From c7350eb9d344bdcc50e029a2895333d2f81f4bd3 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 14:36:01 -0300 Subject: [PATCH 03/81] adding return to ticket aggregate method constructor --- src/Conticket/Model/Aggregates/Event/Ticket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Conticket/Model/Aggregates/Event/Ticket.php b/src/Conticket/Model/Aggregates/Event/Ticket.php index b14f760..956bfdb 100644 --- a/src/Conticket/Model/Aggregates/Event/Ticket.php +++ b/src/Conticket/Model/Aggregates/Event/Ticket.php @@ -43,5 +43,6 @@ public function fromIdAndNameAndDescription(TicketId $id, $name, $description) $ticket->name = $name; $this->description = $description; $this->status = TicketStatus::INACTIVE; + return $ticket; } } From 5db4eff9826ba6c32a8ed4ef45bf307c3a4cffb8 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 18:03:46 -0300 Subject: [PATCH 04/81] patching up some fixes of last code review --- .../Model/Aggregates/Event/EventSpec.php | 3 +- .../Aggregates/Event/TicketLifespanSpec.php | 26 ++++++++++------ .../Model/Aggregates/Event/Event.php | 30 +++++++++++-------- .../Model/Aggregates/Event/EventId.php | 21 +++++-------- .../Model/Aggregates/Event/TickedId.php | 28 +++++------------ .../Model/Aggregates/Event/Ticket.php | 13 ++++---- ...ateMustBeGreaterThanStartDateException.php | 4 ++- .../Model/Aggregates/Event/TicketLifespan.php | 25 +++++----------- .../Model/Aggregates/Event/TicketStatus.php | 3 ++ .../Model/Events/Event/EventWasCreated.php | 15 ++++++---- .../Model/Events/Event/TicketWasAdded.php | 16 ++++++---- 11 files changed, 93 insertions(+), 91 deletions(-) diff --git a/spec/Conticket/Model/Aggregates/Event/EventSpec.php b/spec/Conticket/Model/Aggregates/Event/EventSpec.php index daf537d..5678da6 100644 --- a/spec/Conticket/Model/Aggregates/Event/EventSpec.php +++ b/spec/Conticket/Model/Aggregates/Event/EventSpec.php @@ -5,6 +5,7 @@ use Conticket\Model\Aggregates\Event\EventId; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Conticket\Model\Aggregates\Event\Event; class EventSpec extends ObjectBehavior { @@ -19,7 +20,7 @@ function let() function it_is_initializable() { - $this->shouldHaveType('Conticket\Model\Aggregates\Event\Event'); + $this->shouldHaveType(Event::class); } function it_should_return_event_id() diff --git a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php index 4a21143..4623fdd 100644 --- a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php +++ b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php @@ -2,27 +2,35 @@ namespace spec\Conticket\Model\Aggregates\Event; +use Conticket\Model\Aggregates\Event\TicketLifespan; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Conticket\Model\Aggregates\Event\TicketEndDateMustBeGreaterThanStartDateException; -class TicketLifespanSpec extends ObjectBehavior + +final class TicketLifespanSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Conticket\Model\Aggregates\Event\TicketLifespan'); + $this->shouldHaveType(TicketLifespan::class); } - function it_throws_an_exception_when_start_date_is_greater_than_end_date() + public function it_throws_an_exception_when_start_date_is_greater_than_end_date() { - $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2015-01-01']); $this->shouldThrow(TicketEndDateMustBeGreaterThanStartDateException::class); + $this->beConstructedThrough('fromStartAndEnd', [ + new \DateTimeImmutable('2016-01-01'), + new \DateTimeImmutable('2015-01-01'), + ]); } - function it_should_return_datetimes_objects_on_start_and_end_methods() + public function it_should_return_datetimes_objects_on_start_and_end_methods() { - $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2016-04-01']); - $this->start()->shouldReturnAnInstanceOf(\DateTime::class); - $this->end()->shouldReturnAnInstanceOf(\DateTime::class); + $this->beConstructedThrough('fromStartAndEnd', [ + new \DateTimeImmutable('2016-01-01'), + new \DateTimeImmutable('2016-04-01'), + ]); + $this->start()->shouldReturnAnInstanceOf(\DateTimeImmutable::class); + $this->end()->shouldReturnAnInstanceOf(\DateTimeImmutable::class); } } diff --git a/src/Conticket/Model/Aggregates/Event/Event.php b/src/Conticket/Model/Aggregates/Event/Event.php index d3184ce..9395e43 100644 --- a/src/Conticket/Model/Aggregates/Event/Event.php +++ b/src/Conticket/Model/Aggregates/Event/Event.php @@ -15,38 +15,43 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Aggregates\Event; +use Doctrine\Common\Collections\ArrayCollection; use Prooph\EventSourcing\AggregateRoot; use Conticket\Model\Aggregates\Ticket\TicketId; use Conticket\Model\Events\Event\EventWasCreated; use Conticket\Model\Events\Event\TicketWasAdded; use Assert\Assertion; +use Rhumsaa\Uuid\Uuid; -class Event extends AggregateRoot +final class Event extends AggregateRoot { private $aggregateId; private $name; private $description; - private $tickets = []; + private $tickets; private $banner; private $gateway; - public function aggregateId() + public function aggregateId() : EventId { return $this->aggregateId; } - public static function fromNameAndDescription($name, $description) + public static function fromNameAndDescription($name, $description) : self { Assertion::notEmpty($name, 'Name is required.'); Assertion::notEmpty($description, 'Description is required.'); $event = new self(); - $event->aggregateId = new EventId(); + $event->aggregateId = new EventId(Uuid::uuid4()); $event->recordThat( - EventWasCreated::fromEventAndNameAndDescription( - $event->aggregateId()->toString(), + EventWasCreated::fromEventIdAndNameAndDescription( + $event->aggregateId(), $name, $description ) @@ -59,24 +64,25 @@ public function whenEventWasCreated(EventWasCreated $eventWasCreated) $this->aggregateId = EventId::fromString($eventWasCreated->aggregateId()); $this->name = $eventWasCreated->name(); $this->description = $eventWasCreated->description(); + $this->tickets = new ArrayCollection(); } - public function addTicket($name, $description) + public function addTicket($name, $description) : void { $ticketId = new TicketId(); $this->recordThat(TicketWasAdded::fromTicketAndNameAndDescription( - $ticketId->toString(), + (string) $ticketId, $name, $description )); } - public function whenTicketWasAdded(TicketWasAdded $ticketWasAdded) + public function whenTicketWasAdded(TicketWasAdded $ticketWasAdded) : void { - $this->tickets[] = Ticket::fromIdAndNameAndDescription( + $this->tickets->add(Ticket::fromIdAndNameAndDescription( TicketId::fromString($ticketWasAdded->aggregateId()), $ticketWasAdded->name(), $ticketWasAdded->description() - ); + )); } } diff --git a/src/Conticket/Model/Aggregates/Event/EventId.php b/src/Conticket/Model/Aggregates/Event/EventId.php index 299adf3..bfbb43a 100644 --- a/src/Conticket/Model/Aggregates/Event/EventId.php +++ b/src/Conticket/Model/Aggregates/Event/EventId.php @@ -15,6 +15,9 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Aggregates\Event; use Rhumsaa\Uuid\Uuid; @@ -23,14 +26,14 @@ final class EventId { private $id; - public function __construct($id = null) + public function __construct(Uuid $id) { - $this->id = null === $id ? self::fromString(Uuid::uuid4()->toString()) : $id; + $this->id = $id; } public static function fromString($id) { - return new self($id); + return new self(Uuid::fromString($id)); } public function id() @@ -38,17 +41,7 @@ public function id() return $this->id; } - public function equals(UserId $userId) - { - return $this->id() === $userId->id(); - } - - public function toString() - { - return $this->id; - } - - public function __toString() + public function __toString() : string { return $this->id; } diff --git a/src/Conticket/Model/Aggregates/Event/TickedId.php b/src/Conticket/Model/Aggregates/Event/TickedId.php index d01d413..58425dd 100644 --- a/src/Conticket/Model/Aggregates/Event/TickedId.php +++ b/src/Conticket/Model/Aggregates/Event/TickedId.php @@ -15,6 +15,9 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Aggregates\Ticket; use Rhumsaa\Uuid\Uuid; @@ -23,32 +26,17 @@ final class TicketId { private $id; - public function __construct($id = null) + public function __construct(Uuid $id) { - $this->id = null === $id ? self::fromString(Uuid::uuid4()->toString()) : $id; + $this->id = $id; } - public static function fromString($id) + public static function fromString(string $id): self { - return new self($id); - } - - public function id() - { - return $this->id; - } - - public function equals(UserId $userId) - { - return $this->id() === $userId->id(); - } - - public function toString() - { - return $this->id; + return new self(Uuid::fromString($id)); } - public function __toString() + public function __toString(): string { return $this->id; } diff --git a/src/Conticket/Model/Aggregates/Event/Ticket.php b/src/Conticket/Model/Aggregates/Event/Ticket.php index 956bfdb..667bdf4 100644 --- a/src/Conticket/Model/Aggregates/Event/Ticket.php +++ b/src/Conticket/Model/Aggregates/Event/Ticket.php @@ -15,12 +15,15 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Aggregates\Event; use Conticket\Model\Aggregates\Ticket\TicketId; use Prooph\EventSourcing\AggregateRoot; -class Ticket extends AggregateRoot +final class Ticket extends AggregateRoot { private $aggregateId; private $eventId; @@ -31,18 +34,18 @@ class Ticket extends AggregateRoot private $value; private $status; - public function aggregateId() + public function aggregateId() : TicketId { return $this->aggregateId; } - public function fromIdAndNameAndDescription(TicketId $id, $name, $description) + public function fromIdAndNameAndDescription(TicketId $id, string $name, string $description) : self { $ticket = new self(); $ticket->aggregateId = $id; $ticket->name = $name; - $this->description = $description; - $this->status = TicketStatus::INACTIVE; + $ticket->description = $description; + $ticket->status = TicketStatus::INACTIVE; return $ticket; } } diff --git a/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php b/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php index e77d7e9..c039692 100644 --- a/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php +++ b/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php @@ -1,5 +1,7 @@ start = $start; $this->end = $end; } - public static function fromStartAndEnd($start, $end) + public static function fromStartAndEnd(\DateTimeImmutable $start, \DateTimeImmutable $end): self { - Assertion::notEmpty($start, "Start date is required."); - Assertion::notEmpty($end, "End date is required."); - - $start = new \DateTime($start); - $end = new \DateTime($end); - if ($start > $end) { throw new TicketEndDateMustBeGreaterThanStartDateException(); } @@ -30,20 +24,17 @@ public static function fromStartAndEnd($start, $end) return new self($start, $end); } - public function start() + public function start() : \DateTimeImmutable { return $this->start; } - public function end() + public function end() : \DateTimeImmutable { return $this->end; } public function expiresOn(){} - public function daysLeft(){} - public function expired(){} - -} \ No newline at end of file +} diff --git a/src/Conticket/Model/Aggregates/Event/TicketStatus.php b/src/Conticket/Model/Aggregates/Event/TicketStatus.php index d87110e..3a81ff9 100644 --- a/src/Conticket/Model/Aggregates/Event/TicketStatus.php +++ b/src/Conticket/Model/Aggregates/Event/TicketStatus.php @@ -15,6 +15,9 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Aggregates\Event; final class TicketStatus diff --git a/src/Conticket/Model/Events/Event/EventWasCreated.php b/src/Conticket/Model/Events/Event/EventWasCreated.php index 0e676a4..ea62a65 100644 --- a/src/Conticket/Model/Events/Event/EventWasCreated.php +++ b/src/Conticket/Model/Events/Event/EventWasCreated.php @@ -15,27 +15,30 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Events\Event; use Conticket\Model\Aggregates\Event\EventId; use Prooph\EventSourcing\AggregateChanged; -class EventWasCreated extends AggregateChanged +final class EventWasCreated extends AggregateChanged { - public static function fromEventAndNameAndDescription(EventId $eventId, $name, $description) + public static function fromEventIdAndNameAndDescription(EventId $eventId, string $name, string $description) { - return self::occur($eventId->toString(), [ + return self::occur((string) $eventId, [ 'name' => $name, - 'description' => $description + 'description' => $description, ]); } - public function name() + public function name() : string { return $this->payload['name']; } - public function description() + public function description() : string { return $this->payload['description']; } diff --git a/src/Conticket/Model/Events/Event/TicketWasAdded.php b/src/Conticket/Model/Events/Event/TicketWasAdded.php index c7ec0ab..5026d56 100644 --- a/src/Conticket/Model/Events/Event/TicketWasAdded.php +++ b/src/Conticket/Model/Events/Event/TicketWasAdded.php @@ -15,27 +15,31 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ + +declare(strict_types=1); + namespace Conticket\Model\Events\Event; use Conticket\Model\Aggregates\Event\EventId; +use Conticket\Model\Aggregates\Ticket\TicketId; use Prooph\EventSourcing\AggregateChanged; -class TicketWasAdded extends AggregateChanged +final class TicketWasAdded extends AggregateChanged { - public static function fromTicketAndNameAndDescription($ticketId, $name, $description) + public static function fromTicketAndNameAndDescription(TicketId $ticketId, string $name, string $description): self { - return self::occur($ticketId->toString(), [ + return self::occur((string) $ticketId, [ 'name' => $name, - 'description' => $description + 'description' => $description, ]); } - public function name() + public function name(): string { return $this->payload['name']; } - public function description() + public function description(): string { return $this->payload['description']; } From 2d10867bf563f6907f5c8c244575a4f138bb4729 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 19:09:19 -0300 Subject: [PATCH 05/81] patching up more fixes --- src/Conticket/Model/Aggregates/Event/Event.php | 4 ++-- src/Conticket/Model/Aggregates/Event/EventId.php | 9 ++------- src/Conticket/Model/Aggregates/Event/TickedId.php | 6 +++--- src/Conticket/Model/Aggregates/Event/TicketLifespan.php | 2 +- src/Conticket/Model/Aggregates/Event/TicketStatus.php | 4 ++-- src/Conticket/Model/Events/Event/EventWasCreated.php | 2 +- src/Conticket/Model/Events/Event/TicketWasAdded.php | 6 +++--- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/Conticket/Model/Aggregates/Event/Event.php b/src/Conticket/Model/Aggregates/Event/Event.php index 9395e43..022794e 100644 --- a/src/Conticket/Model/Aggregates/Event/Event.php +++ b/src/Conticket/Model/Aggregates/Event/Event.php @@ -59,7 +59,7 @@ public static function fromNameAndDescription($name, $description) : self return $event; } - public function whenEventWasCreated(EventWasCreated $eventWasCreated) + public function whenEventWasCreated(EventWasCreated $eventWasCreated) : void { $this->aggregateId = EventId::fromString($eventWasCreated->aggregateId()); $this->name = $eventWasCreated->name(); @@ -70,7 +70,7 @@ public function whenEventWasCreated(EventWasCreated $eventWasCreated) public function addTicket($name, $description) : void { $ticketId = new TicketId(); - $this->recordThat(TicketWasAdded::fromTicketAndNameAndDescription( + $this->recordThat(TicketWasAdded::fromTicketIdAndNameAndDescription( (string) $ticketId, $name, $description diff --git a/src/Conticket/Model/Aggregates/Event/EventId.php b/src/Conticket/Model/Aggregates/Event/EventId.php index bfbb43a..6d4d816 100644 --- a/src/Conticket/Model/Aggregates/Event/EventId.php +++ b/src/Conticket/Model/Aggregates/Event/EventId.php @@ -31,18 +31,13 @@ public function __construct(Uuid $id) $this->id = $id; } - public static function fromString($id) + public static function fromString($id) : self { return new self(Uuid::fromString($id)); } - public function id() - { - return $this->id; - } - public function __toString() : string { - return $this->id; + return $this->id->toString(); } } diff --git a/src/Conticket/Model/Aggregates/Event/TickedId.php b/src/Conticket/Model/Aggregates/Event/TickedId.php index 58425dd..e6de8c3 100644 --- a/src/Conticket/Model/Aggregates/Event/TickedId.php +++ b/src/Conticket/Model/Aggregates/Event/TickedId.php @@ -31,13 +31,13 @@ public function __construct(Uuid $id) $this->id = $id; } - public static function fromString(string $id): self + public static function fromString(string $id) : self { return new self(Uuid::fromString($id)); } - public function __toString(): string + public function __toString() : string { - return $this->id; + return $this->id->toString(); } } diff --git a/src/Conticket/Model/Aggregates/Event/TicketLifespan.php b/src/Conticket/Model/Aggregates/Event/TicketLifespan.php index 8151369..1b836a3 100644 --- a/src/Conticket/Model/Aggregates/Event/TicketLifespan.php +++ b/src/Conticket/Model/Aggregates/Event/TicketLifespan.php @@ -15,7 +15,7 @@ protected function __construct(\DateTimeImmutable $start, \DateTimeImmutable $en $this->end = $end; } - public static function fromStartAndEnd(\DateTimeImmutable $start, \DateTimeImmutable $end): self + public static function fromStartAndEnd(\DateTimeImmutable $start, \DateTimeImmutable $end) : self { if ($start > $end) { throw new TicketEndDateMustBeGreaterThanStartDateException(); diff --git a/src/Conticket/Model/Aggregates/Event/TicketStatus.php b/src/Conticket/Model/Aggregates/Event/TicketStatus.php index 3a81ff9..5c3f828 100644 --- a/src/Conticket/Model/Aggregates/Event/TicketStatus.php +++ b/src/Conticket/Model/Aggregates/Event/TicketStatus.php @@ -25,12 +25,12 @@ final class TicketStatus const ACTIVE = 1; const INACTIVE = 2; - private static $strings = [ + private $strings = [ self::ACTIVE => 'Active', self::INACTIVE => 'Inactive' ]; - public static function toString($statusCode) + public static function toString($statusCode) : string { return isset(self::$strings[$statusCode]) ? self::$strings[$statusCode] : null; } diff --git a/src/Conticket/Model/Events/Event/EventWasCreated.php b/src/Conticket/Model/Events/Event/EventWasCreated.php index ea62a65..2e96972 100644 --- a/src/Conticket/Model/Events/Event/EventWasCreated.php +++ b/src/Conticket/Model/Events/Event/EventWasCreated.php @@ -25,7 +25,7 @@ final class EventWasCreated extends AggregateChanged { - public static function fromEventIdAndNameAndDescription(EventId $eventId, string $name, string $description) + public static function fromEventIdAndNameAndDescription(EventId $eventId, string $name, string $description) : self { return self::occur((string) $eventId, [ 'name' => $name, diff --git a/src/Conticket/Model/Events/Event/TicketWasAdded.php b/src/Conticket/Model/Events/Event/TicketWasAdded.php index 5026d56..cd303a2 100644 --- a/src/Conticket/Model/Events/Event/TicketWasAdded.php +++ b/src/Conticket/Model/Events/Event/TicketWasAdded.php @@ -26,7 +26,7 @@ final class TicketWasAdded extends AggregateChanged { - public static function fromTicketAndNameAndDescription(TicketId $ticketId, string $name, string $description): self + public static function fromTicketIdAndNameAndDescription(TicketId $ticketId, string $name, string $description) : self { return self::occur((string) $ticketId, [ 'name' => $name, @@ -34,12 +34,12 @@ public static function fromTicketAndNameAndDescription(TicketId $ticketId, strin ]); } - public function name(): string + public function name() : string { return $this->payload['name']; } - public function description(): string + public function description() : string { return $this->payload['description']; } From 1deefd30224e2111e22007b1f28b55687e635edc Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 21:06:54 -0300 Subject: [PATCH 06/81] deleting old files --- src/Conticket/Model/Aggregates/Event/EventId.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Conticket/Model/Aggregates/Event/EventId.php b/src/Conticket/Model/Aggregates/Event/EventId.php index 6d4d816..a9d3ca3 100644 --- a/src/Conticket/Model/Aggregates/Event/EventId.php +++ b/src/Conticket/Model/Aggregates/Event/EventId.php @@ -41,3 +41,4 @@ public function __toString() : string return $this->id->toString(); } } + From afb1b2010f906e5f6000a1dfd9a36cafdf07d8f5 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 21:11:51 -0300 Subject: [PATCH 07/81] renaming method on ticket lifespan object --- spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php index 4623fdd..cd05292 100644 --- a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php +++ b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php @@ -24,7 +24,7 @@ public function it_throws_an_exception_when_start_date_is_greater_than_end_date( ]); } - public function it_should_return_datetimes_objects_on_start_and_end_methods() + public function it_should_return_immutable_datetime__objects_on_start_and_end_methods() { $this->beConstructedThrough('fromStartAndEnd', [ new \DateTimeImmutable('2016-01-01'), From 8fc1a4ee88e044d815649273b2b9e8f87ac15587 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 22:55:27 -0300 Subject: [PATCH 08/81] removing doctrine-mongodb-odm and adding money package --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 58fc0ed..5aee5e3 100644 --- a/composer.json +++ b/composer.json @@ -24,14 +24,14 @@ }, "require": { "php": "~5.5|^7.0", - "doctrine/mongodb-odm": "^1.0", "incenteev/composer-parameter-handler": "~2.0", "predis/predis": "~1.0", "zendframework/zend-expressive": "^1.0", "ramsey/uuid": "^2.8", "beberlei/assert": "^2.6", - "prooph/event-sourcing": "~4.0", - "prooph/event-store": "^6.0" + "prooph/event-sourcing": "^4.0", + "prooph/event-store": "^6.0", + "moneyphp/money": "^3.0" }, "require-dev": { "behat/behat": "3.*@stable", From afc97bd1e784296aa8ac8a83b1e0fc1ef67dabd8 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Thu, 1 Dec 2016 23:00:47 -0300 Subject: [PATCH 09/81] modelling ticket related value objects and events, improving ticket aggregate and refactoring ticket addition to an event --- .../Model/Aggregates/Event/EventSpec.php | 6 +- .../Aggregates/Event/TicketLifespanSpec.php | 2 +- .../Model/Aggregates/Event/Event.php | 25 +------ .../Model/Aggregates/Event/EventId.php | 1 - .../Model/Aggregates/Event/TickedId.php | 2 +- .../Model/Aggregates/Event/Ticket.php | 65 +++++++++++++++++-- .../Model/Aggregates/Event/TicketPrice.php | 31 +++++++++ .../Model/Aggregates/Event/TicketQuantity.php | 29 +++++++++ .../Events/Event/TicketLifespanWasSet.php | 48 ++++++++++++++ .../Model/Events/Event/TicketPriceWasSet.php | 41 ++++++++++++ .../Events/Event/TicketQuantityWasSet.php | 41 ++++++++++++ .../Model/Events/Event/TicketWasAdded.php | 20 ++---- .../Model/Events/Event/TicketWasCreated.php | 54 +++++++++++++++ 13 files changed, 317 insertions(+), 48 deletions(-) create mode 100644 src/Conticket/Model/Aggregates/Event/TicketPrice.php create mode 100644 src/Conticket/Model/Aggregates/Event/TicketQuantity.php create mode 100644 src/Conticket/Model/Events/Event/TicketLifespanWasSet.php create mode 100644 src/Conticket/Model/Events/Event/TicketPriceWasSet.php create mode 100644 src/Conticket/Model/Events/Event/TicketQuantityWasSet.php create mode 100644 src/Conticket/Model/Events/Event/TicketWasCreated.php diff --git a/spec/Conticket/Model/Aggregates/Event/EventSpec.php b/spec/Conticket/Model/Aggregates/Event/EventSpec.php index 5678da6..f04df58 100644 --- a/spec/Conticket/Model/Aggregates/Event/EventSpec.php +++ b/spec/Conticket/Model/Aggregates/Event/EventSpec.php @@ -10,7 +10,7 @@ class EventSpec extends ObjectBehavior { - function let() + public function let() { $this->beConstructedThrough('fromNameAndDescription', [ 'Event specification by example', @@ -18,12 +18,12 @@ function let() ]); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType(Event::class); } - function it_should_return_event_id() + public function it_should_return_event_id() { $this->aggregateId()->shouldReturnAnInstanceOf(EventId::class); } diff --git a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php index cd05292..60e8208 100644 --- a/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php +++ b/spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php @@ -24,7 +24,7 @@ public function it_throws_an_exception_when_start_date_is_greater_than_end_date( ]); } - public function it_should_return_immutable_datetime__objects_on_start_and_end_methods() + public function it_should_return_immutable_datetime_objects_on_start_and_end_methods() { $this->beConstructedThrough('fromStartAndEnd', [ new \DateTimeImmutable('2016-01-01'), diff --git a/src/Conticket/Model/Aggregates/Event/Event.php b/src/Conticket/Model/Aggregates/Event/Event.php index 022794e..b571bb6 100644 --- a/src/Conticket/Model/Aggregates/Event/Event.php +++ b/src/Conticket/Model/Aggregates/Event/Event.php @@ -20,9 +20,7 @@ namespace Conticket\Model\Aggregates\Event; -use Doctrine\Common\Collections\ArrayCollection; use Prooph\EventSourcing\AggregateRoot; -use Conticket\Model\Aggregates\Ticket\TicketId; use Conticket\Model\Events\Event\EventWasCreated; use Conticket\Model\Events\Event\TicketWasAdded; use Assert\Assertion; @@ -33,7 +31,6 @@ final class Event extends AggregateRoot private $aggregateId; private $name; private $description; - private $tickets; private $banner; private $gateway; @@ -48,10 +45,9 @@ public static function fromNameAndDescription($name, $description) : self Assertion::notEmpty($description, 'Description is required.'); $event = new self(); - $event->aggregateId = new EventId(Uuid::uuid4()); $event->recordThat( EventWasCreated::fromEventIdAndNameAndDescription( - $event->aggregateId(), + new EventId(Uuid::uuid4()), $name, $description ) @@ -64,25 +60,10 @@ public function whenEventWasCreated(EventWasCreated $eventWasCreated) : void $this->aggregateId = EventId::fromString($eventWasCreated->aggregateId()); $this->name = $eventWasCreated->name(); $this->description = $eventWasCreated->description(); - $this->tickets = new ArrayCollection(); } - public function addTicket($name, $description) : void + public function addTicket(Ticket $ticket) : void { - $ticketId = new TicketId(); - $this->recordThat(TicketWasAdded::fromTicketIdAndNameAndDescription( - (string) $ticketId, - $name, - $description - )); - } - - public function whenTicketWasAdded(TicketWasAdded $ticketWasAdded) : void - { - $this->tickets->add(Ticket::fromIdAndNameAndDescription( - TicketId::fromString($ticketWasAdded->aggregateId()), - $ticketWasAdded->name(), - $ticketWasAdded->description() - )); + $this->recordThat(TicketWasAdded::fromEventAndTicket($this, $ticket)); } } diff --git a/src/Conticket/Model/Aggregates/Event/EventId.php b/src/Conticket/Model/Aggregates/Event/EventId.php index a9d3ca3..6d4d816 100644 --- a/src/Conticket/Model/Aggregates/Event/EventId.php +++ b/src/Conticket/Model/Aggregates/Event/EventId.php @@ -41,4 +41,3 @@ public function __toString() : string return $this->id->toString(); } } - diff --git a/src/Conticket/Model/Aggregates/Event/TickedId.php b/src/Conticket/Model/Aggregates/Event/TickedId.php index e6de8c3..2628a7b 100644 --- a/src/Conticket/Model/Aggregates/Event/TickedId.php +++ b/src/Conticket/Model/Aggregates/Event/TickedId.php @@ -18,7 +18,7 @@ declare(strict_types=1); -namespace Conticket\Model\Aggregates\Ticket; +namespace Conticket\Model\Aggregates\Event; use Rhumsaa\Uuid\Uuid; diff --git a/src/Conticket/Model/Aggregates/Event/Ticket.php b/src/Conticket/Model/Aggregates/Event/Ticket.php index 667bdf4..ff785de 100644 --- a/src/Conticket/Model/Aggregates/Event/Ticket.php +++ b/src/Conticket/Model/Aggregates/Event/Ticket.php @@ -20,8 +20,12 @@ namespace Conticket\Model\Aggregates\Event; -use Conticket\Model\Aggregates\Ticket\TicketId; +use Conticket\Model\Events\Event\TicketPriceWasSet; +use Conticket\Model\Events\Event\TicketWasCreated; use Prooph\EventSourcing\AggregateRoot; +use Conticket\Model\Events\Event\TicketLifespanWasSet; +use Conticket\Model\Events\Event\TicketQuantityWasSet; +use Rhumsaa\Uuid\Uuid; final class Ticket extends AggregateRoot { @@ -31,7 +35,7 @@ final class Ticket extends AggregateRoot private $description; private $lifespan; private $quantity; - private $value; + private $price; private $status; public function aggregateId() : TicketId @@ -39,13 +43,60 @@ public function aggregateId() : TicketId return $this->aggregateId; } - public function fromIdAndNameAndDescription(TicketId $id, string $name, string $description) : self + public static function fromEventIdAndNameAndDescription(EventId $eventId, string $name, string $description) : self { $ticket = new self(); - $ticket->aggregateId = $id; - $ticket->name = $name; - $ticket->description = $description; - $ticket->status = TicketStatus::INACTIVE; + $ticket->recordThat(TicketWasCreated::fromTicketIdAndEventIdAndNameAndDescription( + new TicketId(Uuid::uuid4()), + $eventId, + $name, + $description + )); return $ticket; } + + public function whenTicketWasCreated(TicketWasCreated $ticketWasCreated) + { + $this->aggregateId = $ticketWasCreated->aggregateId(); + $this->eventId = EventId::fromString($ticketWasCreated->eventId()); + $this->name = $ticketWasCreated->name(); + $this->description = $ticketWasCreated->description(); + $this->status = TicketStatus::INACTIVE; + } + + public function setLifespan(\DateTimeImmutable $start, \DateTimeImmutable $end) : void + { + $this->recordThat(TicketLifeSpanWasSet::fromTicketAndStartDateAndEndDate( + $this, $start, $end + )); + } + + public function whenTicketLifespanWasSet(TicketLifespanWasSet $ticketLifespanWasSet) : void + { + $this->lifespan = TicketLifespan::fromStartAndEnd( + new \DateTimeImmutable($ticketLifespanWasSet->start()), + new \DateTimeImmutable($ticketLifespanWasSet->end()) + ); + } + + public function setQuantity(TicketQuantity $ticketQuantity) : void + { + $this->recordThat(TicketQuantityWasSet::fromTicketAndTicketQuantity($this, $ticketQuantity)); + } + + public function whenTicketQuantityWasSet(TicketQuantityWasSet $ticketQuantityWasSet) : void + { + $this->quantity = TicketQuantity::fromInteger($ticketQuantityWasSet->value()); + } + + public function setPrice(TicketPrice $ticketPrice) : void + { + $this->recordThat(TicketPriceWasSet::fromTicketAndTicketPrice($this, $ticketPrice)); + } + + public function whenTicketPriceWasSet(TicketPriceWasSet $ticketPriceWasSet) : void + { + $this->price = TicketPrice::fromAmount($ticketPriceWasSet->value()); + } + } diff --git a/src/Conticket/Model/Aggregates/Event/TicketPrice.php b/src/Conticket/Model/Aggregates/Event/TicketPrice.php new file mode 100644 index 0000000..8debe87 --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/TicketPrice.php @@ -0,0 +1,31 @@ +value = $value; + } + + public static function fromAmount(string $amount, string $code = self::CURRENCY_DEFAULT) + { + return new self(new Money($amount, new Currency($code))); + } + + public function amount() : string + { + return (string) $this->value->getAmount(); + } +} \ No newline at end of file diff --git a/src/Conticket/Model/Aggregates/Event/TicketQuantity.php b/src/Conticket/Model/Aggregates/Event/TicketQuantity.php new file mode 100644 index 0000000..5fe2bb9 --- /dev/null +++ b/src/Conticket/Model/Aggregates/Event/TicketQuantity.php @@ -0,0 +1,29 @@ +value; + } + + public static function fromInteger(integer $value) + { + Assertion::min(1, $value); + + return new self($value); + } + + public function value() : int + { + return $this->value; + } +} diff --git a/src/Conticket/Model/Events/Event/TicketLifespanWasSet.php b/src/Conticket/Model/Events/Event/TicketLifespanWasSet.php new file mode 100644 index 0000000..2497ce2 --- /dev/null +++ b/src/Conticket/Model/Events/Event/TicketLifespanWasSet.php @@ -0,0 +1,48 @@ +aggregateId(), [ + 'start' => (string) $start->format('Y-m-d H:i:s'), + 'end' => (string) $end->format('Y-m-d H:i:s'), + ]); + } + + public function start() : string + { + return $this->payload['start']; + } + + public function end() : string + { + return $this->payload['end']; + } +} diff --git a/src/Conticket/Model/Events/Event/TicketPriceWasSet.php b/src/Conticket/Model/Events/Event/TicketPriceWasSet.php new file mode 100644 index 0000000..24e8430 --- /dev/null +++ b/src/Conticket/Model/Events/Event/TicketPriceWasSet.php @@ -0,0 +1,41 @@ +aggregateId(), [ + 'value' => $ticketPrice->amount() + ]); + } + + public function value() : string + { + return $this->payload['value']; + } +} diff --git a/src/Conticket/Model/Events/Event/TicketQuantityWasSet.php b/src/Conticket/Model/Events/Event/TicketQuantityWasSet.php new file mode 100644 index 0000000..7df9cb2 --- /dev/null +++ b/src/Conticket/Model/Events/Event/TicketQuantityWasSet.php @@ -0,0 +1,41 @@ +aggregateId(), [ + 'quantity' => (string) $ticketQuantity->value() + ]); + } + + public function value() : int + { + return (int) $this->payload['value']; + } +} diff --git a/src/Conticket/Model/Events/Event/TicketWasAdded.php b/src/Conticket/Model/Events/Event/TicketWasAdded.php index cd303a2..264b7e6 100644 --- a/src/Conticket/Model/Events/Event/TicketWasAdded.php +++ b/src/Conticket/Model/Events/Event/TicketWasAdded.php @@ -20,27 +20,21 @@ namespace Conticket\Model\Events\Event; -use Conticket\Model\Aggregates\Event\EventId; -use Conticket\Model\Aggregates\Ticket\TicketId; use Prooph\EventSourcing\AggregateChanged; +use Conticket\Model\Aggregates\Event\Ticket; +use Conticket\Model\Aggregates\Event\Event; final class TicketWasAdded extends AggregateChanged { - public static function fromTicketIdAndNameAndDescription(TicketId $ticketId, string $name, string $description) : self + public static function fromEventAndTicket(Event $event, Ticket $ticket) : self { - return self::occur((string) $ticketId, [ - 'name' => $name, - 'description' => $description, + return self::occur((string) $event->aggregateId(), [ + 'ticket_id' => (string)$ticket->aggregateId() ]); } - public function name() : string + public function ticketId() : string { - return $this->payload['name']; - } - - public function description() : string - { - return $this->payload['description']; + return $this->payload['ticked_id']; } } diff --git a/src/Conticket/Model/Events/Event/TicketWasCreated.php b/src/Conticket/Model/Events/Event/TicketWasCreated.php new file mode 100644 index 0000000..e63ca28 --- /dev/null +++ b/src/Conticket/Model/Events/Event/TicketWasCreated.php @@ -0,0 +1,54 @@ + (string) $eventId, + 'name' => $name, + 'description' => $description, + ]); + } + + public function eventId() : string + { + return $this->payload['event_id']; + } + + public function name() : string + { + return $this->payload['name']; + } + + public function description() : string + { + return $this->payload['description']; + } +} From 640c1ea21dc0adaaf4650843e4a254da250edbbf Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 12:13:51 -0300 Subject: [PATCH 10/81] Better php version description as it's not semantic version complains --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5aee5e3..c1cef5b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ] }, "require": { - "php": "~5.5|^7.0", + "php": "7.0.* || 7.1.*", "incenteev/composer-parameter-handler": "~2.0", "predis/predis": "~1.0", "zendframework/zend-expressive": "^1.0", From 5ae319e9bc133a0b1c412498537f927c4a9f7d31 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 12:58:06 -0300 Subject: [PATCH 11/81] composer require zendframework/zend-expressive-fastroute --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c1cef5b..e7cc02b 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "beberlei/assert": "^2.6", "prooph/event-sourcing": "^4.0", "prooph/event-store": "^6.0", - "moneyphp/money": "^3.0" + "moneyphp/money": "^3.0", + "zendframework/zend-expressive-fastroute": "^1.0" }, "require-dev": { "behat/behat": "3.*@stable", From 654acf07ede81038e9c7b4851ba99a41a6f39407 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 12:58:31 -0300 Subject: [PATCH 12/81] composer require zendframework/zend-servicemanager --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7cc02b..ae90c41 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "prooph/event-sourcing": "^4.0", "prooph/event-store": "^6.0", "moneyphp/money": "^3.0", - "zendframework/zend-expressive-fastroute": "^1.0" + "zendframework/zend-expressive-fastroute": "^1.0", + "zendframework/zend-servicemanager": "^3.2" }, "require-dev": { "behat/behat": "3.*@stable", From 343401eff0f75d1ffd6477f8982f6e135eb7260c Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:14:01 -0300 Subject: [PATCH 13/81] describe basic factories for router services --- config/services.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 config/services.php diff --git a/config/services.php b/config/services.php new file mode 100644 index 0000000..3f8d3a1 --- /dev/null +++ b/config/services.php @@ -0,0 +1,19 @@ + [ + Application::class => function (ContainerInterface $container) { + return new Application($container->get(FastRouteRouter::class), $container); + }, + FastRouteRouter::class => function (ContainerInterface $container) { + return new FastRouteRouter(); + }, + ] + ]; +})(); From 7dcd11220ca05421749c9bfe5e995729ecd57e29 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:14:30 -0300 Subject: [PATCH 14/81] added config file for middleware --- config/middlewares.php | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 config/middlewares.php diff --git a/config/middlewares.php b/config/middlewares.php new file mode 100644 index 0000000..0b67a5f --- /dev/null +++ b/config/middlewares.php @@ -0,0 +1,3 @@ + Date: Fri, 3 Feb 2017 13:14:53 -0300 Subject: [PATCH 15/81] remove web folder --- web/app.php | 16 ----- web/app_dev.php | 17 ------ web/apple-touch-icon.png | Bin 10784 -> 0 bytes web/config.php | 124 --------------------------------------- web/favicon.ico | Bin 6518 -> 0 bytes web/robots.txt | 4 -- 6 files changed, 161 deletions(-) delete mode 100644 web/app.php delete mode 100644 web/app_dev.php delete mode 100644 web/apple-touch-icon.png delete mode 100644 web/config.php delete mode 100644 web/favicon.ico delete mode 100644 web/robots.txt diff --git a/web/app.php b/web/app.php deleted file mode 100644 index 7a757b0..0000000 --- a/web/app.php +++ /dev/null @@ -1,16 +0,0 @@ -loadClassCache(); - -$request = Request::createFromGlobals(); -$response = $kernel->handle($request); -$response->send(); -$kernel->terminate($request, $response); diff --git a/web/app_dev.php b/web/app_dev.php deleted file mode 100644 index 51e5f2d..0000000 --- a/web/app_dev.php +++ /dev/null @@ -1,17 +0,0 @@ -loadClassCache(); - -$request = Request::createFromGlobals(); -$response = $kernel->handle($request); -$response->send(); -$kernel->terminate($request, $response); diff --git a/web/apple-touch-icon.png b/web/apple-touch-icon.png deleted file mode 100644 index 11f17e6d89ee3b416218ede42b66ec1dd81507f2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10784 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 f!getFailedRequirements(); -$minorProblems = $symfonyRequirements->getFailedRecommendations(); - -?> - - - - - - Symfony Configuration - - - - - -
-
- - - -
- -
-
-
-

Welcome!

-

Welcome to your new Symfony project.

-

- This script will guide you through the basic configuration of your project. - You can also do the same by editing the ‘app/config/parameters.yml’ file directly. -

- - -

Major problems

-

Major problems have been detected and must be fixed before continuing:

-
    - -
  1. getHelpHtml() ?>
  2. - -
- - - -

Recommendations

-

- Additionally, toTo enhance your Symfony experience, - it’s recommended that you fix the following: -

-
    - -
  1. getHelpHtml() ?>
  2. - -
- - - hasPhpIniConfigIssue()): ?> -

* - getPhpIniConfigPath()): ?> - Changes to the php.ini file must be done in "getPhpIniConfigPath() ?>". - - To change settings, create a "php.ini". - -

- - - -

Your configuration looks good to run Symfony.

- - - -
-
-
-
Symfony Standard Edition
-
- - diff --git a/web/favicon.ico b/web/favicon.ico deleted file mode 100644 index 479f7f50f404ada1e42c536097521d19f2c22f35..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6518 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 BFLeL_ diff --git a/web/robots.txt b/web/robots.txt deleted file mode 100644 index 214e411..0000000 --- a/web/robots.txt +++ /dev/null @@ -1,4 +0,0 @@ -# www.robotstxt.org/ -# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449 - -User-agent: * From e0404baa002fc2e1f9d99a26c7bcf13fdd845c2e Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:15:48 -0300 Subject: [PATCH 16/81] added root index file --- public/index.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 public/index.php diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..ed9dedd --- /dev/null +++ b/public/index.php @@ -0,0 +1,13 @@ +get(\Zend\Expressive\Application::class); + +})(); From 432d3b33d7219bcc912f022f274298aa44f96ff5 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:16:16 -0300 Subject: [PATCH 17/81] create service manager with given configs --- config/service-manager.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 config/service-manager.php diff --git a/config/service-manager.php b/config/service-manager.php new file mode 100644 index 0000000..94570cd --- /dev/null +++ b/config/service-manager.php @@ -0,0 +1,14 @@ + Date: Fri, 3 Feb 2017 13:24:08 -0300 Subject: [PATCH 18/81] sort composer packages --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index ae90c41..8e5d7a1 100644 --- a/composer.json +++ b/composer.json @@ -24,14 +24,14 @@ }, "require": { "php": "7.0.* || 7.1.*", + "beberlei/assert": "^2.6", "incenteev/composer-parameter-handler": "~2.0", + "moneyphp/money": "^3.0", "predis/predis": "~1.0", - "zendframework/zend-expressive": "^1.0", - "ramsey/uuid": "^2.8", - "beberlei/assert": "^2.6", "prooph/event-sourcing": "^4.0", "prooph/event-store": "^6.0", - "moneyphp/money": "^3.0", + "ramsey/uuid": "^2.8", + "zendframework/zend-expressive": "^1.0", "zendframework/zend-expressive-fastroute": "^1.0", "zendframework/zend-servicemanager": "^3.2" }, From a0f60e9c9f50adfe21ed4824a4599a1fd56d9430 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:38:23 -0300 Subject: [PATCH 19/81] register middleware to register a conference --- config/middlewares.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/config/middlewares.php b/config/middlewares.php index 0b67a5f..4809be9 100644 --- a/config/middlewares.php +++ b/config/middlewares.php @@ -1,3 +1,10 @@ [ + CreateAConference::class => CreateAConferenceFactory::class, + ], +]; From 5a56cedbd74050bf5419bba61f642d33299bd3c4 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:40:00 -0300 Subject: [PATCH 20/81] register router on front controller --- public/index.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/index.php b/public/index.php index ed9dedd..9ea424d 100644 --- a/public/index.php +++ b/public/index.php @@ -2,12 +2,21 @@ declare(strict_types=1); +use Conticket\Conference\Infrastructure\Middleware\CreateAConference; + (function () { require __DIR__ . '/../vendor/autoload.php'; /* @var $serviceManager \Zend\ServiceManager\ServiceManager */ $serviceManager = require __DIR__ . '/../config/service-manager.php'; + /* @var $app \Zend\Expressive\Application */ $app = $serviceManager->get(\Zend\Expressive\Application::class); + // @todo change it to POST + $app->get(CreateAConference::PATH, CreateAConference::class); + + $app->pipeRoutingMiddleware(); + $app->pipeDispatchMiddleware(); + $app->run(); })(); From 0654cbe11558e6cbfca31c7bf449860d059a2b15 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:50:11 -0300 Subject: [PATCH 21/81] added event to create conference --- .../DomainEvent/ConferenceWasCreated.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/Conticket/Conference/DomainEvent/ConferenceWasCreated.php diff --git a/src/Conticket/Conference/DomainEvent/ConferenceWasCreated.php b/src/Conticket/Conference/DomainEvent/ConferenceWasCreated.php new file mode 100644 index 0000000..f818c05 --- /dev/null +++ b/src/Conticket/Conference/DomainEvent/ConferenceWasCreated.php @@ -0,0 +1,136 @@ + + */ +final class ConferenceWasCreated extends AggregateChanged +{ + /** + * @var ConferenceId + */ + private $conferenceId; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $description; + + /** + * @var string + */ + private $author; + + /** + * @var \DateTimeImmutable + */ + private $date; + + public static function fromRequestData( + ConferenceId $conferenceId, + string $name, + string $description, + string $author, + \DateTimeImmutable $date + ): self { + + Assertion::notEmpty($name); + Assertion::notEmpty($description); + Assertion::notEmpty($author); + + return self::occur( + $conferenceId, + [ + 'conferenceId' => (string) $conferenceId, + 'name' => $name, + 'description' => $description, + 'author' => $author, + 'date' => $date->format('U.u'), + ] + ); + } + + /** + * {@inheritDoc} + */ + public function payload(): array + { + return [ + 'name' => $this->name, + 'description' => $this->description, + 'conferenceId' => (string) $this->conferenceId, + 'author' => $this->author, + 'date' => $this->date->format('U.u'), + ]; + } + + /** + * {@inheritDoc} + */ + protected function setPayload(array $payload): void + { + [ + $this->name, + $this->description, + $this->author, + $this->conferenceId, + $this->date + ] = [ + $payload['name'], + $payload['description'], + $payload['author'], + ConferenceId::fromString($payload['description']), + \DateTimeImmutable::createFromFormat('U.u', $payload['date']), + ]; + } + + /** + * @return string + */ + public function getAuthor(): string + { + return $this->author; + } + + /** + * @return ConferenceId + */ + public function getConferenceId(): ConferenceId + { + return $this->conferenceId; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return mixed + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return \DateTimeImmutable + */ + public function getDate(): \DateTimeImmutable + { + return $this->date; + } +} From 604baa7aa05518b31283b54fe77a5b4a391b7d13 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:53:01 -0300 Subject: [PATCH 22/81] added identifier for conference aggregate --- .../Conference/Domain/ConferenceId.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Conticket/Conference/Domain/ConferenceId.php diff --git a/src/Conticket/Conference/Domain/ConferenceId.php b/src/Conticket/Conference/Domain/ConferenceId.php new file mode 100644 index 0000000..f29bd99 --- /dev/null +++ b/src/Conticket/Conference/Domain/ConferenceId.php @@ -0,0 +1,41 @@ + + */ +final class ConferenceId +{ + /** + * @var Uuid + */ + private $uuid; + + private function __construct(Uuid $uuid) + { + $this->uuid = Uuid::uuid4(); + } + + public static function new(): self + { + return new self(Uuid::uuid4()); + } + + public static function fromString(string $uuid): self + { + return new self(Uuid::fromString($uuid)); + } + + public function __toString(): string + { + return (string) $this->uuid; + } + + public function uuid(): Uuid + { + return $this->uuid; + } +} From 8d521bce7052a9d02300f2f4cfd0ca2a501e9d6d Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 13:57:18 -0300 Subject: [PATCH 23/81] added command to create conference --- .../Conference/Command/CreateConference.php | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/Conticket/Conference/Command/CreateConference.php diff --git a/src/Conticket/Conference/Command/CreateConference.php b/src/Conticket/Conference/Command/CreateConference.php new file mode 100644 index 0000000..6d62010 --- /dev/null +++ b/src/Conticket/Conference/Command/CreateConference.php @@ -0,0 +1,138 @@ + + */ +final class CreateConference extends Command +{ + /** + * @var ConferenceId + */ + private $conferenceId; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $description; + + /** + * @var string + */ + private $author; + + /** + * @var \DateTimeImmutable + */ + private $date; + + private function __construct() + { + } + + public static function fromRequestData( + ConferenceId $conferenceId, + string $name, + string $description, + string $author, + \DateTimeImmutable $date + ): self { + // @todo move to __constructor + Assertion::notEmpty($name); + Assertion::notEmpty($description); + Assertion::notEmpty($author); + + $self = new self(); + $self->conferenceId = (string) $conferenceId; + $self->name = $name; + $self->description = $description; + $self->author = $author; + $self->date = $date->format('U.u'); + + return $self; + } + + /** + * {@inheritDoc} + */ + public function payload(): array + { + return [ + 'name' => $this->name, + 'description' => $this->description, + 'conferenceId' => (string) $this->conferenceId, + 'author' => $this->author, + 'date' => $this->date->format('U.u'), + ]; + } + + /** + * {@inheritDoc} + */ + protected function setPayload(array $payload): void + { + [ + $this->name, + $this->description, + $this->author, + $this->conferenceId, + $this->date + ] = [ + $payload['name'], + $payload['description'], + $payload['author'], + ConferenceId::fromString($payload['description']), + \DateTimeImmutable::createFromFormat('U.u', $payload['date']), + ]; + } + + /** + * @return string + */ + public function getAuthor(): string + { + return $this->author; + } + + /** + * @return ConferenceId + */ + public function getConferenceId(): ConferenceId + { + return $this->conferenceId; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return mixed + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return \DateTimeImmutable + */ + public function getDate(): \DateTimeImmutable + { + return $this->date; + } +} From 0f460742339b9cf72e31a06f0526f0ea5515a3da Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 14:31:36 -0300 Subject: [PATCH 24/81] composer require zendframework/zend-servicemanager --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8e5d7a1..22a438f 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "ramsey/uuid": "^2.8", "zendframework/zend-expressive": "^1.0", "zendframework/zend-expressive-fastroute": "^1.0", - "zendframework/zend-servicemanager": "^3.2" + "zendframework/zend-servicemanager": "^3.2", + "prooph/service-bus": "^5.2" }, "require-dev": { "behat/behat": "3.*@stable", From f38a6ccc83518affabc7edc10eecbcaad51f7f67 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 14:34:02 -0300 Subject: [PATCH 25/81] config proper namespace psr-4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 22a438f..4f6ddf7 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "autoload": { "psr-4": { - "": "src/" + "Conticket\\": "src/" } }, "autoload-dev": { From a33f366186bfd7714024d94ed27eeaae0fb480b4 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 15:21:38 -0300 Subject: [PATCH 26/81] make responsibilities more descriptive --- public/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/index.php b/public/index.php index 9ea424d..772745b 100644 --- a/public/index.php +++ b/public/index.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use Conticket\Conference\Infrastructure\Middleware\CreateAConference; +use Conticket\Conference\Infrastructure\Middleware\CreateConferenceMiddleware; (function () { require __DIR__ . '/../vendor/autoload.php'; @@ -14,7 +14,7 @@ $app = $serviceManager->get(\Zend\Expressive\Application::class); // @todo change it to POST - $app->get(CreateAConference::PATH, CreateAConference::class); + $app->get(CreateConferenceMiddleware::PATH, CreateConferenceMiddleware::class); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); From b9baa21035e37fa9a1246839678ab8dffad7bdb7 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 15:22:46 -0300 Subject: [PATCH 27/81] fix error on conference id implementation --- src/{Conticket => }/Conference/Domain/ConferenceId.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/{Conticket => }/Conference/Domain/ConferenceId.php (89%) diff --git a/src/Conticket/Conference/Domain/ConferenceId.php b/src/Conference/Domain/ConferenceId.php similarity index 89% rename from src/Conticket/Conference/Domain/ConferenceId.php rename to src/Conference/Domain/ConferenceId.php index f29bd99..322f4d3 100644 --- a/src/Conticket/Conference/Domain/ConferenceId.php +++ b/src/Conference/Domain/ConferenceId.php @@ -1,6 +1,6 @@ uuid = Uuid::uuid4(); + $this->uuid = $uuid; } public static function new(): self From cb74529aa0dfb26640038bb0f37db54a1a0266ec Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:18:30 -0300 Subject: [PATCH 28/81] fix middleware factories name --- config/middlewares.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/middlewares.php b/config/middlewares.php index 4809be9..958c34d 100644 --- a/config/middlewares.php +++ b/config/middlewares.php @@ -1,10 +1,12 @@ [ - CreateAConference::class => CreateAConferenceFactory::class, + CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class, ], ]; From a173b998912e13864484589ba77f84a58255ca34 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:19:12 -0300 Subject: [PATCH 29/81] introduce a command bus --- .../Service/CommandBusFactory.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Conference/Infrastructure/Service/CommandBusFactory.php diff --git a/src/Conference/Infrastructure/Service/CommandBusFactory.php b/src/Conference/Infrastructure/Service/CommandBusFactory.php new file mode 100644 index 0000000..263d9f7 --- /dev/null +++ b/src/Conference/Infrastructure/Service/CommandBusFactory.php @@ -0,0 +1,70 @@ + + */ +final class CommandBusFactory +{ + public function __invoke(ContainerInterface $container): CommandBus + { + $commandBus = new CommandBus(); + $commandBus->utilize(new ServiceLocatorPlugin($container)); + $commandBus->utilize($this->buildCommandRouter($container)); + + return $commandBus; + } + + private function buildCommandRouter(ContainerInterface $container): ActionEventListenerAggregate + { + return new class($container) implements ActionEventListenerAggregate + { + /** + * @var ContainerInterface + */ + private $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * {@inheritDoc} + */ + public function attach(ActionEventEmitter $dispatcher) + { + $dispatcher->attachListener(MessageBus::EVENT_ROUTE, [$this, 'onRoute']); + } + + /** + * {@inheritDoc} + * + * @throws \BadMethodCallException + */ + public function detach(ActionEventEmitter $dispatcher) + { + throw new \BadMethodCallException('Not implemented'); + } + + public function onRoute(ActionEvent $actionEvent) + { + $actionEvent->setParam( + MessageBus::EVENT_PARAM_MESSAGE_HANDLER, + (string) $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME) + ); + } + }; + } +} From 9a440b8f827080e368ad431b4dce8926cf6c0639 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:19:51 -0300 Subject: [PATCH 30/81] move files to fit psr-4 declaration --- .../Domain}/Command/CreateConference.php | 6 ++++-- .../Domain/Event}/ConferenceWasCreated.php | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) rename src/{Conticket/Conference => Conference/Domain}/Command/CreateConference.php (95%) rename src/{Conticket/Conference/DomainEvent => Conference/Domain/Event}/ConferenceWasCreated.php (96%) diff --git a/src/Conticket/Conference/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php similarity index 95% rename from src/Conticket/Conference/Command/CreateConference.php rename to src/Conference/Domain/Command/CreateConference.php index 6d62010..669293d 100644 --- a/src/Conticket/Conference/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -1,9 +1,11 @@ Date: Fri, 3 Feb 2017 16:20:22 -0300 Subject: [PATCH 31/81] middleware example --- .../Middleware/CreateConferenceMiddleware.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Conference/Infrastructure/Middleware/CreateConferenceMiddleware.php diff --git a/src/Conference/Infrastructure/Middleware/CreateConferenceMiddleware.php b/src/Conference/Infrastructure/Middleware/CreateConferenceMiddleware.php new file mode 100644 index 0000000..145490f --- /dev/null +++ b/src/Conference/Infrastructure/Middleware/CreateConferenceMiddleware.php @@ -0,0 +1,58 @@ + + */ +final class CreateConferenceMiddleware implements MiddlewareInterface +{ + const PATH = '/conference'; + + /** + * @var callable + */ + private $commandBus; + + public function __construct(CommandBus $commandBus) + { + $this->commandBus = $commandBus; + } + + /** + * {@inheritDoc} + * + * @throws \InvalidArgumentException + * @throws \Prooph\ServiceBus\Exception\CommandDispatchException + */ + public function __invoke(Request $request, Response $response, callable $out = null) + { + // @todo work with post parameters + $commandBus = $this->commandBus; + + $command = CreateConference::fromRequestData( + ConferenceId::new(), + 'blah', + 'desc', + 'author', + new \DateTimeImmutable('now') + ); + + $commandBus->dispatch($command); + + // @todo return a json response + + $response->getBody()->write('aaa'); + + return $response; + } +} From 33c9aab79a1767e278679489d4c5998251162ea6 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:21:12 -0300 Subject: [PATCH 32/81] create conference middleware factory --- .../CreateConferenceMiddlewareFactory.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php diff --git a/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php b/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php new file mode 100644 index 0000000..f652b9c --- /dev/null +++ b/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php @@ -0,0 +1,27 @@ + + */ +final class CreateConferenceMiddlewareFactory +{ + /** + * {@inheritDoc} + * + * @throws \Interop\Container\Exception\ContainerException + */ + public function __invoke(ContainerInterface $container): CreateConferenceMiddleware + { + return new CreateConferenceMiddleware( + $container->get(CommandBus::class) + ); + } +} From 31773ed765c0f226818415190da8762b5703bd62 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:21:44 -0300 Subject: [PATCH 33/81] add repository for conference aggregate --- .../ConferenceRepositoryInterface.php | 18 +++++++ .../Repository/ConferenceRepository.php | 52 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/Conference/Domain/Repository/ConferenceRepositoryInterface.php create mode 100644 src/Conference/Infrastructure/Repository/ConferenceRepository.php diff --git a/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php b/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php new file mode 100644 index 0000000..a310460 --- /dev/null +++ b/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php @@ -0,0 +1,18 @@ + + */ +interface ConferenceRepositoryInterface +{ + public function get(ConferenceId $conferenceId): Conference; + + public function store(Conference $conference): void; +} diff --git a/src/Conference/Infrastructure/Repository/ConferenceRepository.php b/src/Conference/Infrastructure/Repository/ConferenceRepository.php new file mode 100644 index 0000000..07f8811 --- /dev/null +++ b/src/Conference/Infrastructure/Repository/ConferenceRepository.php @@ -0,0 +1,52 @@ + + */ +final class ConferenceRepository implements ConferenceRepositoryInterface +{ + /** + * @var AggregateRepository + */ + private $repository; + + public function __construct(AggregateRepository $repository) + { + $this->repository = $repository; + } + + /** + * {@inheritDoc} + * + * @throws \DomainException + */ + public function get(ConferenceId $conferenceId): Conference + { + $conference = $this->repository->getAggregateRoot((string) $conferenceId); + + if (! $conference instanceof Conference) { + throw new \DomainException(sprintf('Could not load aggregate using id "%s"', $conferenceId)); + } + + return $conference; + } + + /** + * {@inheritDoc} + * + * @throws \Prooph\EventStore\Aggregate\Exception\AggregateTypeException + */ + public function store(Conference $conference): void + { + $this->repository->addAggregateRoot($conference); + } +} From f6ed89810c3ad8c3a71137c7f0461ec46698f099 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:22:29 -0300 Subject: [PATCH 34/81] command handler for create a conference --- .../CreateConferenceHandler.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/Conference/Domain/CommandHandler/CreateConferenceHandler.php diff --git a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php new file mode 100644 index 0000000..8110c38 --- /dev/null +++ b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php @@ -0,0 +1,29 @@ + + */ +final class CreateConferenceHandler +{ + /** + * @var ConferenceRepositoryInterface + */ + private $repository; + + public function __construct(ConferenceRepositoryInterface $repository) + { + $this->repository = $repository; + } + + public function __invoke(CreateConference $command) + { + var_dump(__METHOD__);exit; + } +} From b6f3c8cb07e6ad3aa63e7f93cdbcc47d674035e1 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:22:51 -0300 Subject: [PATCH 35/81] added repository factory --- .../ConferenceRepositoryFactory.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Conference/Factory/Repository/ConferenceRepositoryFactory.php diff --git a/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php b/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php new file mode 100644 index 0000000..ced7d61 --- /dev/null +++ b/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php @@ -0,0 +1,81 @@ + + */ +final class ConferenceRepositoryFactory +{ + public function __invoke(ContainerInterface $container): ConferenceRepository + { + return new ConferenceRepository(new AggregateRepository( + // @todo create event store + $container->get(EventStore::class), + AggregateType::fromAggregateRootClass(Conference::class), + $this->buildTranslator() + )); + } + + private function buildTranslator(): AggregateTranslator + { + return new class implements AggregateTranslator + { + /** + * {@inheritDoc} + * + * @throws \Prooph\EventStore\Aggregate\Exception\AggregateTranslationFailedException + */ + public function extractAggregateVersion($eventSourcedAggregateRoot) + { + throw new AggregateTranslationFailedException(); + } + + /** + * {@inheritDoc} + */ + public function extractAggregateId($eventSourcedAggregateRoot) + { + return (string) $eventSourcedAggregateRoot->getId(); + } + + /** + * {@inheritDoc} + */ + public function reconstituteAggregateFromHistory(AggregateType $aggregateType, Iterator $historyEvents) + { + return Conference::fromEvents(iterator_to_array($historyEvents)); + } + + /** + * {@inheritDoc} + */ + public function extractPendingStreamEvents($eventSourcedAggregateRoot) + { + return $eventSourcedAggregateRoot->popRecordedEvents(); + } + + /** + * {@inheritDoc} + * + * @throws \Prooph\EventStore\Aggregate\Exception\AggregateTranslationFailedException + */ + public function replayStreamEvents($anEventSourcedAggregateRoot, Iterator $events) + { + throw new AggregateTranslationFailedException(); + } + }; + } +} From d9da9dbcf7e615f4defb01b57f11296f6e47d75d Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:23:50 -0300 Subject: [PATCH 36/81] add conference aggregate --- src/Conference/Domain/Conference.php | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Conference/Domain/Conference.php diff --git a/src/Conference/Domain/Conference.php b/src/Conference/Domain/Conference.php new file mode 100644 index 0000000..342c482 --- /dev/null +++ b/src/Conference/Domain/Conference.php @@ -0,0 +1,41 @@ + + */ +final class Conference extends AggregateRoot +{ + /** + * @var ConferenceId + */ + private $conferenceId; + + public static function new( + ConferenceId $conferenceId, + string $name, + string $description, + string $author, + \DateTimeImmutable $date + ): self { + $self = new self(); + $self->recordThat(ConferenceWasCreated::fromRequestData($conferenceId, $name, $description, $author, $date)); + + return $self; + } + + /** + * {@inheritDoc} + */ + protected function aggregateId(): string + { + return (string) $this->conferenceId; + } +} From 09f9e859f49f12ba3cf5bf170abc7e94092db330 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:24:13 -0300 Subject: [PATCH 37/81] added command handler factory for create conference --- .../CreateConferenceHandlerFactory.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php diff --git a/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php b/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php new file mode 100644 index 0000000..6bc5b9e --- /dev/null +++ b/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php @@ -0,0 +1,22 @@ + + */ +final class CreateConferenceHandlerFactory +{ + public function __invoke(ContainerInterface $container): CreateConferenceHandler + { + return new CreateConferenceHandler( + $container->get(ConferenceRepositoryInterface::class) + ); + } +} From 34c58521e1805e73b855073d8c3a11d1310c01c9 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 3 Feb 2017 16:24:41 -0300 Subject: [PATCH 38/81] describe services on config file --- config/services.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/services.php b/config/services.php index 3f8d3a1..1e71dae 100644 --- a/config/services.php +++ b/config/services.php @@ -1,6 +1,14 @@ function (ContainerInterface $container) { return new FastRouteRouter(); }, + + CommandBus::class => CommandBusFactory::class, + + // @todo move commands/events to another config file + CreateConference::class => CreateConferenceHandlerFactory::class, + + // @todo move repository to another file + ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class, ] ]; })(); From 72e902987e2ccaa925e2d13b05ee9b6b3bf04b01 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 10:57:59 -0300 Subject: [PATCH 39/81] composer require --sort-packages prooph/event-store-doctrine-adapter --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4f6ddf7..57acdbd 100644 --- a/composer.json +++ b/composer.json @@ -30,11 +30,12 @@ "predis/predis": "~1.0", "prooph/event-sourcing": "^4.0", "prooph/event-store": "^6.0", + "prooph/event-store-doctrine-adapter": "^3.3", + "prooph/service-bus": "^5.2", "ramsey/uuid": "^2.8", "zendframework/zend-expressive": "^1.0", "zendframework/zend-expressive-fastroute": "^1.0", - "zendframework/zend-servicemanager": "^3.2", - "prooph/service-bus": "^5.2" + "zendframework/zend-servicemanager": "^3.2" }, "require-dev": { "behat/behat": "3.*@stable", From 9e3aa6e696e6edc41508b0c46abc1e77dedcd177 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 11:50:28 -0300 Subject: [PATCH 40/81] fix conference aggregate root namespace --- src/Conference/Domain/Conference.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Conference/Domain/Conference.php b/src/Conference/Domain/Conference.php index 342c482..c06b24e 100644 --- a/src/Conference/Domain/Conference.php +++ b/src/Conference/Domain/Conference.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace Conticket\Conference; +namespace Conticket\Conference\Domain; -use Conticket\Conference\Domain\ConferenceId; use Conticket\Conference\Domain\Event\ConferenceWasCreated; use Prooph\EventSourcing\AggregateRoot; From 085523eaee1feff3e7eda675dbc44ae270acea8d Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 11:52:07 -0300 Subject: [PATCH 41/81] register missing services --- config/services.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/config/services.php b/config/services.php index 1e71dae..57c9347 100644 --- a/config/services.php +++ b/config/services.php @@ -2,12 +2,16 @@ declare(strict_types=1); -use Conference\Domain\Repository\ConferenceRepositoryInterface; -use Conference\Factory\Repository\ConferenceRepositoryFactory; +use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface; +use Conticket\Conference\Factory\Repository\ConferenceRepositoryFactory; use Conticket\Conference\Factory\CommandHandler\CreateConferenceHandlerFactory; use Conticket\Conference\Domain\Command\CreateConference; use Conticket\Conference\Infrastructure\Service\CommandBusFactory; +use Conticket\Conference\Infrastructure\Service\ConnectionFactory; +use Conticket\Conference\Infrastructure\Service\EventStoreFactory; +use Doctrine\DBAL\Connection; use Interop\Container\ContainerInterface; +use Prooph\EventStore\EventStore; use Prooph\ServiceBus\CommandBus; use Zend\Expressive\Application; use Zend\Expressive\Router\FastRouteRouter; @@ -24,12 +28,25 @@ }, CommandBus::class => CommandBusFactory::class, + EventStore::class => EventStoreFactory::class, + Connection::class => ConnectionFactory::class, // @todo move commands/events to another config file CreateConference::class => CreateConferenceHandlerFactory::class, // @todo move repository to another file ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class, - ] + + // @todo move db info to a class to get ENV vars + 'db_dsn' => function () { + return 'mysql:host=localhost;dbname=conticket'; + }, + 'db_user' => function () { + return 'root'; + }, + 'db_password' => function () { + return 'root'; + }, + ], ]; })(); From 06f54b294d9f60b7a13ed84e39c1f45da6243ae7 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 11:52:50 -0300 Subject: [PATCH 42/81] allow show errors exceptions on our environment --- public/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/index.php b/public/index.php index 772745b..e7d1703 100644 --- a/public/index.php +++ b/public/index.php @@ -18,5 +18,6 @@ $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); + $app->raiseThrowables(); $app->run(); })(); From 2c41c3003a5c3210a2b3ab8da88ebbd3862e698a Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 11:54:01 -0300 Subject: [PATCH 43/81] fix namespace issues --- .../Domain/CommandHandler/CreateConferenceHandler.php | 4 ++-- .../Domain/Repository/ConferenceRepositoryInterface.php | 4 ++-- .../CommandHandler/CreateConferenceHandlerFactory.php | 2 +- .../Factory/Repository/ConferenceRepositoryFactory.php | 6 +++--- .../Infrastructure/Repository/ConferenceRepository.php | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php index 8110c38..b8c5de5 100644 --- a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php +++ b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php @@ -4,7 +4,7 @@ namespace Conticket\Conference\Domain\CommandHandler; -use Conference\Domain\Repository\ConferenceRepositoryInterface; +use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface; use Conticket\Conference\Domain\Command\CreateConference; /** @@ -24,6 +24,6 @@ public function __construct(ConferenceRepositoryInterface $repository) public function __invoke(CreateConference $command) { - var_dump(__METHOD__);exit; + // @todo raise an domain event } } diff --git a/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php b/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php index a310460..da1ed80 100644 --- a/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php +++ b/src/Conference/Domain/Repository/ConferenceRepositoryInterface.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Conference\Domain\Repository; +namespace Conticket\Conference\Domain\Repository; -use Conticket\Conference\Conference; +use Conticket\Conference\Domain\Conference; use Conticket\Conference\Domain\ConferenceId; /** diff --git a/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php b/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php index 6bc5b9e..ed8c5f2 100644 --- a/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php +++ b/src/Conference/Factory/CommandHandler/CreateConferenceHandlerFactory.php @@ -4,7 +4,7 @@ namespace Conticket\Conference\Factory\CommandHandler; -use Conference\Domain\Repository\ConferenceRepositoryInterface; +use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface; use Conticket\Conference\Domain\CommandHandler\CreateConferenceHandler; use Interop\Container\ContainerInterface; diff --git a/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php b/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php index ced7d61..f717a6d 100644 --- a/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php +++ b/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Conference\Factory\Repository; +namespace Conticket\Conference\Factory\Repository; -use Conference\Infrastructure\Repository\ConferenceRepository; -use Conticket\Conference\Conference; +use Conticket\Conference\Infrastructure\Repository\ConferenceRepository; +use Conticket\Conference\Domain\Conference; use Interop\Container\ContainerInterface; use Iterator; use Prooph\EventStore\Aggregate\AggregateRepository; diff --git a/src/Conference/Infrastructure/Repository/ConferenceRepository.php b/src/Conference/Infrastructure/Repository/ConferenceRepository.php index 07f8811..14316c7 100644 --- a/src/Conference/Infrastructure/Repository/ConferenceRepository.php +++ b/src/Conference/Infrastructure/Repository/ConferenceRepository.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Conference\Infrastructure\Repository; +namespace Conticket\Conference\Infrastructure\Repository; -use Conference\Domain\Repository\ConferenceRepositoryInterface; -use Conticket\Conference\Conference; +use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface; +use Conticket\Conference\Domain\Conference; use Conticket\Conference\Domain\ConferenceId; use Prooph\EventStore\Aggregate\AggregateRepository; From f70ed6aaa7e14aa01e14ef6ebb9460dc7b6e7c5f Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 11:55:34 -0300 Subject: [PATCH 44/81] add connection service --- .../Service/ConnectionFactory.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Conference/Infrastructure/Service/ConnectionFactory.php diff --git a/src/Conference/Infrastructure/Service/ConnectionFactory.php b/src/Conference/Infrastructure/Service/ConnectionFactory.php new file mode 100644 index 0000000..18406c7 --- /dev/null +++ b/src/Conference/Infrastructure/Service/ConnectionFactory.php @@ -0,0 +1,28 @@ + new PDO( + $container->get('db_dsn'), + $container->get('db_user'), + $container->get('db_password') + ), + ], + new Driver() + ); + } +} From 5b27875b5ae81ac35222191ab25eff7e4a1c84f7 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 11:55:57 -0300 Subject: [PATCH 45/81] add event store factory --- .../Service/EventStoreFactory.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Conference/Infrastructure/Service/EventStoreFactory.php diff --git a/src/Conference/Infrastructure/Service/EventStoreFactory.php b/src/Conference/Infrastructure/Service/EventStoreFactory.php new file mode 100644 index 0000000..784c598 --- /dev/null +++ b/src/Conference/Infrastructure/Service/EventStoreFactory.php @@ -0,0 +1,35 @@ + + */ +final class EventStoreFactory +{ + public function __invoke(ContainerInterface $container): EventStore + { + $eventStore = new EventStore( + new DoctrineEventStoreAdapter( + $container->get(Connection::class), + new FQCNMessageFactory(), + new NoOpMessageConverter(), + new JsonPayloadSerializer() + ), + new ProophActionEventEmitter() + ); + + return $eventStore; + } +} From 65c717de85ce97c723a0481883eadd69e7f457cb Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:42:21 -0300 Subject: [PATCH 46/81] creates schema if it doesn't exists --- .../Service/ConnectionFactory.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Conference/Infrastructure/Service/ConnectionFactory.php b/src/Conference/Infrastructure/Service/ConnectionFactory.php index 18406c7..aed96b7 100644 --- a/src/Conference/Infrastructure/Service/ConnectionFactory.php +++ b/src/Conference/Infrastructure/Service/ConnectionFactory.php @@ -6,15 +6,17 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\PDOMySql\Driver; +use Doctrine\DBAL\Schema\SchemaException; use Interop\Container\ContainerInterface; use PDO; +use Prooph\EventStore\Adapter\Doctrine\Schema\EventStoreSchema; final class ConnectionFactory { public function __invoke(ContainerInterface $container): Connection { // @todo create service for \PDO - return new Connection( + $connection = new Connection( [ 'pdo' => new PDO( $container->get('db_dsn'), @@ -24,5 +26,19 @@ public function __invoke(ContainerInterface $container): Connection ], new Driver() ); + + try { + $schema = $connection->getSchemaManager()->createSchema(); + + EventStoreSchema::createSingleStream($schema); + + foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { + $connection->exec($sql); + } + } catch (SchemaException $ignored) { + // this is ignored for now - we don't want to re-create the schema every time + } + + return $connection; } } From 3ac65bd95ee25ae1810f1fc709d269a431f50ac6 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:42:58 -0300 Subject: [PATCH 47/81] simplify repository --- .../ConferenceRepositoryFactory.php | 62 ++----------------- .../Repository/ConferenceRepository.php | 20 +++--- 2 files changed, 11 insertions(+), 71 deletions(-) diff --git a/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php b/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php index f717a6d..1ebdf60 100644 --- a/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php +++ b/src/Conference/Factory/Repository/ConferenceRepositoryFactory.php @@ -7,11 +7,8 @@ use Conticket\Conference\Infrastructure\Repository\ConferenceRepository; use Conticket\Conference\Domain\Conference; use Interop\Container\ContainerInterface; -use Iterator; -use Prooph\EventStore\Aggregate\AggregateRepository; -use Prooph\EventStore\Aggregate\AggregateTranslator; +use Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator; use Prooph\EventStore\Aggregate\AggregateType; -use Prooph\EventStore\Aggregate\Exception\AggregateTranslationFailedException; use Prooph\EventStore\EventStore; /** @@ -21,61 +18,10 @@ final class ConferenceRepositoryFactory { public function __invoke(ContainerInterface $container): ConferenceRepository { - return new ConferenceRepository(new AggregateRepository( - // @todo create event store + return new ConferenceRepository( $container->get(EventStore::class), AggregateType::fromAggregateRootClass(Conference::class), - $this->buildTranslator() - )); - } - - private function buildTranslator(): AggregateTranslator - { - return new class implements AggregateTranslator - { - /** - * {@inheritDoc} - * - * @throws \Prooph\EventStore\Aggregate\Exception\AggregateTranslationFailedException - */ - public function extractAggregateVersion($eventSourcedAggregateRoot) - { - throw new AggregateTranslationFailedException(); - } - - /** - * {@inheritDoc} - */ - public function extractAggregateId($eventSourcedAggregateRoot) - { - return (string) $eventSourcedAggregateRoot->getId(); - } - - /** - * {@inheritDoc} - */ - public function reconstituteAggregateFromHistory(AggregateType $aggregateType, Iterator $historyEvents) - { - return Conference::fromEvents(iterator_to_array($historyEvents)); - } - - /** - * {@inheritDoc} - */ - public function extractPendingStreamEvents($eventSourcedAggregateRoot) - { - return $eventSourcedAggregateRoot->popRecordedEvents(); - } - - /** - * {@inheritDoc} - * - * @throws \Prooph\EventStore\Aggregate\Exception\AggregateTranslationFailedException - */ - public function replayStreamEvents($anEventSourcedAggregateRoot, Iterator $events) - { - throw new AggregateTranslationFailedException(); - } - }; + new AggregateTranslator() + ); } } diff --git a/src/Conference/Infrastructure/Repository/ConferenceRepository.php b/src/Conference/Infrastructure/Repository/ConferenceRepository.php index 14316c7..93c0005 100644 --- a/src/Conference/Infrastructure/Repository/ConferenceRepository.php +++ b/src/Conference/Infrastructure/Repository/ConferenceRepository.php @@ -12,18 +12,8 @@ /** * @author Jefersson Nathan */ -final class ConferenceRepository implements ConferenceRepositoryInterface +final class ConferenceRepository extends AggregateRepository implements ConferenceRepositoryInterface { - /** - * @var AggregateRepository - */ - private $repository; - - public function __construct(AggregateRepository $repository) - { - $this->repository = $repository; - } - /** * {@inheritDoc} * @@ -31,7 +21,7 @@ public function __construct(AggregateRepository $repository) */ public function get(ConferenceId $conferenceId): Conference { - $conference = $this->repository->getAggregateRoot((string) $conferenceId); + $conference = $this->getAggregateRoot((string) $conferenceId); if (! $conference instanceof Conference) { throw new \DomainException(sprintf('Could not load aggregate using id "%s"', $conferenceId)); @@ -47,6 +37,10 @@ public function get(ConferenceId $conferenceId): Conference */ public function store(Conference $conference): void { - $this->repository->addAggregateRoot($conference); + $this->eventStore->beginTransaction(); + + $this->addAggregateRoot($conference); + + $this->eventStore->commit(); } } From f32a79248c4bfae431f0a1189cfb05b9fd0fa4b6 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:43:51 -0300 Subject: [PATCH 48/81] fix conference if reference --- src/Conference/Domain/Command/CreateConference.php | 8 ++++---- src/Conference/Domain/Event/ConferenceWasCreated.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Conference/Domain/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php index 669293d..0e88929 100644 --- a/src/Conference/Domain/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -55,11 +55,11 @@ public static function fromRequestData( Assertion::notEmpty($author); $self = new self(); - $self->conferenceId = (string) $conferenceId; + $self->conferenceId = $conferenceId; $self->name = $name; $self->description = $description; $self->author = $author; - $self->date = $date->format('U.u'); + $self->date = $date; return $self; } @@ -72,8 +72,8 @@ public function payload(): array return [ 'name' => $this->name, 'description' => $this->description, - 'conferenceId' => (string) $this->conferenceId, 'author' => $this->author, + 'conferenceId' => (string) $this->conferenceId, 'date' => $this->date->format('U.u'), ]; } @@ -93,7 +93,7 @@ protected function setPayload(array $payload): void $payload['name'], $payload['description'], $payload['author'], - ConferenceId::fromString($payload['description']), + ConferenceId::fromString($payload['conferenceId']), \DateTimeImmutable::createFromFormat('U.u', $payload['date']), ]; } diff --git a/src/Conference/Domain/Event/ConferenceWasCreated.php b/src/Conference/Domain/Event/ConferenceWasCreated.php index 2e95922..ece28fe 100644 --- a/src/Conference/Domain/Event/ConferenceWasCreated.php +++ b/src/Conference/Domain/Event/ConferenceWasCreated.php @@ -48,7 +48,7 @@ public static function fromRequestData( Assertion::notEmpty($author); return self::occur( - $conferenceId, + (string) $conferenceId, [ 'conferenceId' => (string) $conferenceId, 'name' => $name, @@ -88,7 +88,7 @@ protected function setPayload(array $payload): void $payload['name'], $payload['description'], $payload['author'], - ConferenceId::fromString($payload['description']), + ConferenceId::fromString($payload['conferenceId']), \DateTimeImmutable::createFromFormat('U.u', $payload['date']), ]; } From 28253d70da972dad49e0743461cea5e85f66dbe9 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:44:56 -0300 Subject: [PATCH 49/81] create conference aggregate --- .../Domain/CommandHandler/CreateConferenceHandler.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php index b8c5de5..835c374 100644 --- a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php +++ b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php @@ -4,6 +4,7 @@ namespace Conticket\Conference\Domain\CommandHandler; +use Conticket\Conference\Domain\Conference; use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface; use Conticket\Conference\Domain\Command\CreateConference; @@ -24,6 +25,12 @@ public function __construct(ConferenceRepositoryInterface $repository) public function __invoke(CreateConference $command) { - // @todo raise an domain event + $this->repository->store(Conference::new( + $command->getConferenceId(), + $command->getName(), + $command->getDescription(), + $command->getAuthor(), + $command->getDate() + )); } } From df8c9bb2f4d41c1980310782488d2f2484800b31 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:45:36 -0300 Subject: [PATCH 50/81] add method to respond to `ConferenceWasCreated` domain event --- src/Conference/Domain/Conference.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Conference/Domain/Conference.php b/src/Conference/Domain/Conference.php index c06b24e..60ecc08 100644 --- a/src/Conference/Domain/Conference.php +++ b/src/Conference/Domain/Conference.php @@ -30,6 +30,29 @@ public static function new( return $self; } + public function whenConferenceWasCreated(ConferenceWasCreated $event) + { + $this->conferenceId = ConferenceId::fromString($event->aggregateId()); + } + + /** + * @todo move it to a trait + * + * @return array + */ + public function popRecordedEvents(): array + { + return $this->recordedEvents; + } + + /** + * @return ConferenceId + */ + public function conferenceId() : ConferenceId + { + return $this->conferenceId; + } + /** * {@inheritDoc} */ From af4bc7212976b17c7323c2cc314e9f1231edbc2e Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:48:17 -0300 Subject: [PATCH 51/81] use transactional method --- .../Repository/ConferenceRepository.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Conference/Infrastructure/Repository/ConferenceRepository.php b/src/Conference/Infrastructure/Repository/ConferenceRepository.php index 93c0005..1678d1e 100644 --- a/src/Conference/Infrastructure/Repository/ConferenceRepository.php +++ b/src/Conference/Infrastructure/Repository/ConferenceRepository.php @@ -33,14 +33,15 @@ public function get(ConferenceId $conferenceId): Conference /** * {@inheritDoc} * + * @throws \Exception * @throws \Prooph\EventStore\Aggregate\Exception\AggregateTypeException */ public function store(Conference $conference): void { - $this->eventStore->beginTransaction(); - - $this->addAggregateRoot($conference); - - $this->eventStore->commit(); + $this + ->eventStore + ->transactional(function () use ($conference) { + $this->addAggregateRoot($conference); + }); } } From 4195114d3dd3e55127055a2b7ccdc834bc184585 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 13:52:54 -0300 Subject: [PATCH 52/81] remove code from old structure --- .../Model/Aggregates/Event/Event.php | 69 ------------ .../Model/Aggregates/Event/EventId.php | 43 -------- .../Model/Aggregates/Event/TickedId.php | 43 -------- .../Model/Aggregates/Event/Ticket.php | 102 ------------------ ...ateMustBeGreaterThanStartDateException.php | 13 --- .../Model/Aggregates/Event/TicketLifespan.php | 40 ------- .../Model/Aggregates/Event/TicketPrice.php | 31 ------ .../Model/Aggregates/Event/TicketQuantity.php | 29 ----- .../Model/Aggregates/Event/TicketStatus.php | 39 ------- .../Model/Events/Event/EventWasCreated.php | 45 -------- .../Events/Event/TicketLifespanWasSet.php | 48 --------- .../Model/Events/Event/TicketPriceWasSet.php | 41 ------- .../Events/Event/TicketQuantityWasSet.php | 41 ------- .../Model/Events/Event/TicketWasAdded.php | 40 ------- .../Model/Events/Event/TicketWasCreated.php | 54 ---------- 15 files changed, 678 deletions(-) delete mode 100644 src/Conticket/Model/Aggregates/Event/Event.php delete mode 100644 src/Conticket/Model/Aggregates/Event/EventId.php delete mode 100644 src/Conticket/Model/Aggregates/Event/TickedId.php delete mode 100644 src/Conticket/Model/Aggregates/Event/Ticket.php delete mode 100644 src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php delete mode 100644 src/Conticket/Model/Aggregates/Event/TicketLifespan.php delete mode 100644 src/Conticket/Model/Aggregates/Event/TicketPrice.php delete mode 100644 src/Conticket/Model/Aggregates/Event/TicketQuantity.php delete mode 100644 src/Conticket/Model/Aggregates/Event/TicketStatus.php delete mode 100644 src/Conticket/Model/Events/Event/EventWasCreated.php delete mode 100644 src/Conticket/Model/Events/Event/TicketLifespanWasSet.php delete mode 100644 src/Conticket/Model/Events/Event/TicketPriceWasSet.php delete mode 100644 src/Conticket/Model/Events/Event/TicketQuantityWasSet.php delete mode 100644 src/Conticket/Model/Events/Event/TicketWasAdded.php delete mode 100644 src/Conticket/Model/Events/Event/TicketWasCreated.php diff --git a/src/Conticket/Model/Aggregates/Event/Event.php b/src/Conticket/Model/Aggregates/Event/Event.php deleted file mode 100644 index b571bb6..0000000 --- a/src/Conticket/Model/Aggregates/Event/Event.php +++ /dev/null @@ -1,69 +0,0 @@ -aggregateId; - } - - public static function fromNameAndDescription($name, $description) : self - { - Assertion::notEmpty($name, 'Name is required.'); - Assertion::notEmpty($description, 'Description is required.'); - - $event = new self(); - $event->recordThat( - EventWasCreated::fromEventIdAndNameAndDescription( - new EventId(Uuid::uuid4()), - $name, - $description - ) - ); - return $event; - } - - public function whenEventWasCreated(EventWasCreated $eventWasCreated) : void - { - $this->aggregateId = EventId::fromString($eventWasCreated->aggregateId()); - $this->name = $eventWasCreated->name(); - $this->description = $eventWasCreated->description(); - } - - public function addTicket(Ticket $ticket) : void - { - $this->recordThat(TicketWasAdded::fromEventAndTicket($this, $ticket)); - } -} diff --git a/src/Conticket/Model/Aggregates/Event/EventId.php b/src/Conticket/Model/Aggregates/Event/EventId.php deleted file mode 100644 index 6d4d816..0000000 --- a/src/Conticket/Model/Aggregates/Event/EventId.php +++ /dev/null @@ -1,43 +0,0 @@ -id = $id; - } - - public static function fromString($id) : self - { - return new self(Uuid::fromString($id)); - } - - public function __toString() : string - { - return $this->id->toString(); - } -} diff --git a/src/Conticket/Model/Aggregates/Event/TickedId.php b/src/Conticket/Model/Aggregates/Event/TickedId.php deleted file mode 100644 index 2628a7b..0000000 --- a/src/Conticket/Model/Aggregates/Event/TickedId.php +++ /dev/null @@ -1,43 +0,0 @@ -id = $id; - } - - public static function fromString(string $id) : self - { - return new self(Uuid::fromString($id)); - } - - public function __toString() : string - { - return $this->id->toString(); - } -} diff --git a/src/Conticket/Model/Aggregates/Event/Ticket.php b/src/Conticket/Model/Aggregates/Event/Ticket.php deleted file mode 100644 index ff785de..0000000 --- a/src/Conticket/Model/Aggregates/Event/Ticket.php +++ /dev/null @@ -1,102 +0,0 @@ -aggregateId; - } - - public static function fromEventIdAndNameAndDescription(EventId $eventId, string $name, string $description) : self - { - $ticket = new self(); - $ticket->recordThat(TicketWasCreated::fromTicketIdAndEventIdAndNameAndDescription( - new TicketId(Uuid::uuid4()), - $eventId, - $name, - $description - )); - return $ticket; - } - - public function whenTicketWasCreated(TicketWasCreated $ticketWasCreated) - { - $this->aggregateId = $ticketWasCreated->aggregateId(); - $this->eventId = EventId::fromString($ticketWasCreated->eventId()); - $this->name = $ticketWasCreated->name(); - $this->description = $ticketWasCreated->description(); - $this->status = TicketStatus::INACTIVE; - } - - public function setLifespan(\DateTimeImmutable $start, \DateTimeImmutable $end) : void - { - $this->recordThat(TicketLifeSpanWasSet::fromTicketAndStartDateAndEndDate( - $this, $start, $end - )); - } - - public function whenTicketLifespanWasSet(TicketLifespanWasSet $ticketLifespanWasSet) : void - { - $this->lifespan = TicketLifespan::fromStartAndEnd( - new \DateTimeImmutable($ticketLifespanWasSet->start()), - new \DateTimeImmutable($ticketLifespanWasSet->end()) - ); - } - - public function setQuantity(TicketQuantity $ticketQuantity) : void - { - $this->recordThat(TicketQuantityWasSet::fromTicketAndTicketQuantity($this, $ticketQuantity)); - } - - public function whenTicketQuantityWasSet(TicketQuantityWasSet $ticketQuantityWasSet) : void - { - $this->quantity = TicketQuantity::fromInteger($ticketQuantityWasSet->value()); - } - - public function setPrice(TicketPrice $ticketPrice) : void - { - $this->recordThat(TicketPriceWasSet::fromTicketAndTicketPrice($this, $ticketPrice)); - } - - public function whenTicketPriceWasSet(TicketPriceWasSet $ticketPriceWasSet) : void - { - $this->price = TicketPrice::fromAmount($ticketPriceWasSet->value()); - } - -} diff --git a/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php b/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php deleted file mode 100644 index c039692..0000000 --- a/src/Conticket/Model/Aggregates/Event/TicketEndDateMustBeGreaterThanStartDateException.php +++ /dev/null @@ -1,13 +0,0 @@ -start = $start; - $this->end = $end; - } - - public static function fromStartAndEnd(\DateTimeImmutable $start, \DateTimeImmutable $end) : self - { - if ($start > $end) { - throw new TicketEndDateMustBeGreaterThanStartDateException(); - } - - return new self($start, $end); - } - - public function start() : \DateTimeImmutable - { - return $this->start; - } - - public function end() : \DateTimeImmutable - { - return $this->end; - } - - public function expiresOn(){} - public function daysLeft(){} - public function expired(){} -} diff --git a/src/Conticket/Model/Aggregates/Event/TicketPrice.php b/src/Conticket/Model/Aggregates/Event/TicketPrice.php deleted file mode 100644 index 8debe87..0000000 --- a/src/Conticket/Model/Aggregates/Event/TicketPrice.php +++ /dev/null @@ -1,31 +0,0 @@ -value = $value; - } - - public static function fromAmount(string $amount, string $code = self::CURRENCY_DEFAULT) - { - return new self(new Money($amount, new Currency($code))); - } - - public function amount() : string - { - return (string) $this->value->getAmount(); - } -} \ No newline at end of file diff --git a/src/Conticket/Model/Aggregates/Event/TicketQuantity.php b/src/Conticket/Model/Aggregates/Event/TicketQuantity.php deleted file mode 100644 index 5fe2bb9..0000000 --- a/src/Conticket/Model/Aggregates/Event/TicketQuantity.php +++ /dev/null @@ -1,29 +0,0 @@ -value; - } - - public static function fromInteger(integer $value) - { - Assertion::min(1, $value); - - return new self($value); - } - - public function value() : int - { - return $this->value; - } -} diff --git a/src/Conticket/Model/Aggregates/Event/TicketStatus.php b/src/Conticket/Model/Aggregates/Event/TicketStatus.php deleted file mode 100644 index 5c3f828..0000000 --- a/src/Conticket/Model/Aggregates/Event/TicketStatus.php +++ /dev/null @@ -1,39 +0,0 @@ - 'Active', - self::INACTIVE => 'Inactive' - ]; - - public static function toString($statusCode) : string - { - return isset(self::$strings[$statusCode]) ? self::$strings[$statusCode] : null; - } - - private function __construct(){} -} diff --git a/src/Conticket/Model/Events/Event/EventWasCreated.php b/src/Conticket/Model/Events/Event/EventWasCreated.php deleted file mode 100644 index 2e96972..0000000 --- a/src/Conticket/Model/Events/Event/EventWasCreated.php +++ /dev/null @@ -1,45 +0,0 @@ - $name, - 'description' => $description, - ]); - } - - public function name() : string - { - return $this->payload['name']; - } - - public function description() : string - { - return $this->payload['description']; - } -} diff --git a/src/Conticket/Model/Events/Event/TicketLifespanWasSet.php b/src/Conticket/Model/Events/Event/TicketLifespanWasSet.php deleted file mode 100644 index 2497ce2..0000000 --- a/src/Conticket/Model/Events/Event/TicketLifespanWasSet.php +++ /dev/null @@ -1,48 +0,0 @@ -aggregateId(), [ - 'start' => (string) $start->format('Y-m-d H:i:s'), - 'end' => (string) $end->format('Y-m-d H:i:s'), - ]); - } - - public function start() : string - { - return $this->payload['start']; - } - - public function end() : string - { - return $this->payload['end']; - } -} diff --git a/src/Conticket/Model/Events/Event/TicketPriceWasSet.php b/src/Conticket/Model/Events/Event/TicketPriceWasSet.php deleted file mode 100644 index 24e8430..0000000 --- a/src/Conticket/Model/Events/Event/TicketPriceWasSet.php +++ /dev/null @@ -1,41 +0,0 @@ -aggregateId(), [ - 'value' => $ticketPrice->amount() - ]); - } - - public function value() : string - { - return $this->payload['value']; - } -} diff --git a/src/Conticket/Model/Events/Event/TicketQuantityWasSet.php b/src/Conticket/Model/Events/Event/TicketQuantityWasSet.php deleted file mode 100644 index 7df9cb2..0000000 --- a/src/Conticket/Model/Events/Event/TicketQuantityWasSet.php +++ /dev/null @@ -1,41 +0,0 @@ -aggregateId(), [ - 'quantity' => (string) $ticketQuantity->value() - ]); - } - - public function value() : int - { - return (int) $this->payload['value']; - } -} diff --git a/src/Conticket/Model/Events/Event/TicketWasAdded.php b/src/Conticket/Model/Events/Event/TicketWasAdded.php deleted file mode 100644 index 264b7e6..0000000 --- a/src/Conticket/Model/Events/Event/TicketWasAdded.php +++ /dev/null @@ -1,40 +0,0 @@ -aggregateId(), [ - 'ticket_id' => (string)$ticket->aggregateId() - ]); - } - - public function ticketId() : string - { - return $this->payload['ticked_id']; - } -} diff --git a/src/Conticket/Model/Events/Event/TicketWasCreated.php b/src/Conticket/Model/Events/Event/TicketWasCreated.php deleted file mode 100644 index e63ca28..0000000 --- a/src/Conticket/Model/Events/Event/TicketWasCreated.php +++ /dev/null @@ -1,54 +0,0 @@ - (string) $eventId, - 'name' => $name, - 'description' => $description, - ]); - } - - public function eventId() : string - { - return $this->payload['event_id']; - } - - public function name() : string - { - return $this->payload['name']; - } - - public function description() : string - { - return $this->payload['description']; - } -} From db290dcb73df9eae423377df5cc21a92f869f03d Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 14:05:03 -0300 Subject: [PATCH 53/81] composer require --dev --sort-packages malukenho/docheader --- composer.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 57acdbd..e23eb6f 100644 --- a/composer.json +++ b/composer.json @@ -41,10 +41,11 @@ "behat/behat": "3.*@stable", "behat/mink": "*@stable", "behat/mink-extension": "*", - "behat/mink-selenium2-driver": "*", "behat/mink-goutte-driver": "*", - "phpunit/phpunit": "4.7.*", - "phpspec/phpspec": "^2.5" + "behat/mink-selenium2-driver": "*", + "malukenho/docheader": "^0.1.5", + "phpspec/phpspec": "^2.5", + "phpunit/phpunit": "4.7.*" }, "config": { "bin-dir": "bin" From 71a467cdfe41b1d56b80a21420ceaf783d0d812f Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 14:05:33 -0300 Subject: [PATCH 54/81] added `.docheader` template file --- .docheader | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .docheader diff --git a/.docheader b/.docheader new file mode 100644 index 0000000..fefcd81 --- /dev/null +++ b/.docheader @@ -0,0 +1,16 @@ +/* + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the MIT license. + */ From f1ee208552eb7056f69ec5f5268906d5e32b3036 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 14:05:50 -0300 Subject: [PATCH 55/81] fix missing doc header --- .../Domain/Command/CreateConference.php | 16 +++++++++++++++ .../CreateConferenceHandler.php | 16 +++++++++++++++ src/Conference/Domain/Conference.php | 20 +++++++++++++++++-- src/Conference/Domain/ConferenceId.php | 18 +++++++++++++++++ .../Domain/Event/ConferenceWasCreated.php | 18 +++++++++++++++++ .../ConferenceRepositoryInterface.php | 16 +++++++++++++++ .../CreateConferenceHandlerFactory.php | 16 +++++++++++++++ .../CreateConferenceMiddlewareFactory.php | 16 +++++++++++++++ .../ConferenceRepositoryFactory.php | 16 +++++++++++++++ .../Middleware/CreateConferenceMiddleware.php | 16 +++++++++++++++ .../Repository/ConferenceRepository.php | 16 +++++++++++++++ .../Service/CommandBusFactory.php | 16 +++++++++++++++ .../Service/ConnectionFactory.php | 16 +++++++++++++++ .../Service/EventStoreFactory.php | 20 ++++++++++++++++--- 14 files changed, 231 insertions(+), 5 deletions(-) diff --git a/src/Conference/Domain/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php index 0e88929..8f56d94 100644 --- a/src/Conference/Domain/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -1,4 +1,20 @@ conferenceId = ConferenceId::fromString($event->aggregateId()); } @@ -48,7 +64,7 @@ public function popRecordedEvents(): array /** * @return ConferenceId */ - public function conferenceId() : ConferenceId + public function conferenceId(): ConferenceId { return $this->conferenceId; } diff --git a/src/Conference/Domain/ConferenceId.php b/src/Conference/Domain/ConferenceId.php index 322f4d3..0170239 100644 --- a/src/Conference/Domain/ConferenceId.php +++ b/src/Conference/Domain/ConferenceId.php @@ -1,4 +1,22 @@ get(Connection::class), new FQCNMessageFactory(), @@ -29,7 +45,5 @@ public function __invoke(ContainerInterface $container): EventStore ), new ProophActionEventEmitter() ); - - return $eventStore; } } From 2f90c02c3ccd669f69b7dc5c0deda7d3f2a5ca53 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 14:07:37 -0300 Subject: [PATCH 56/81] clean up travis script --- .travis.yml | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 816256d..b4843ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,39 +6,16 @@ env: - BASE_URL=127.0.0.1:8080 php: - - 5.6 - - 7 + - 7.1 matrix: allow_failures: - - php: 7 - -services: mongodb - -before_script: - - echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - - composer selfupdate - - composer install --no-interaction --prefer-dist --no-scripts - - - chmod -R 777 app/cache app/logs - - app/console --env=test cache:warmup - - chmod -R 777 app/cache app/logs - - - app/console doctrine:mongodb:schema:create - - app/console doctrine:mongodb:fixtures:load - - - app/console server:run 127.0.0.1:8080 --no-debug > webserver.log 2>&1 & - - - sh -e /etc/init.d/xvfb start - - export DISPLAY=:99.0 - - wget http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar - - java -jar selenium-server-standalone-2.31.0.jar > /dev/null & - - sleep 5 + - php: 7.1 notifications: email: false script: - ./bin/phpunit -c app + - ./bin/docheader check src/ - ./bin/behat From 9c883452ef490501596d68297154dd3b4895dd24 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Sat, 4 Mar 2017 18:34:06 -0300 Subject: [PATCH 57/81] moving logic from named constructor to private constructor --- .../Domain/Command/CreateConference.php | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Conference/Domain/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php index 8f56d94..7c881fb 100644 --- a/src/Conference/Domain/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -54,30 +54,39 @@ final class CreateConference extends Command */ private $date; - private function __construct() - { - } - - public static function fromRequestData( + private function __construct( ConferenceId $conferenceId, string $name, string $description, string $author, \DateTimeImmutable $date - ): self { - // @todo move to __constructor + ) + { Assertion::notEmpty($name); Assertion::notEmpty($description); Assertion::notEmpty($author); - $self = new self(); - $self->conferenceId = $conferenceId; - $self->name = $name; - $self->description = $description; - $self->author = $author; - $self->date = $date; + $this->conferenceId = $conferenceId; + $this->name = $name; + $this->description = $description; + $this->author = $author; + $this->date = $date; + } - return $self; + public static function fromRequestData( + ConferenceId $conferenceId, + string $name, + string $description, + string $author, + \DateTimeImmutable $date + ): self { + return new self( + $conferenceId, + $name, + $description, + $author, + $date + ); } /** From e26062a1ccdf35223d142833fedf0903d3095c12 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Sat, 4 Mar 2017 18:36:18 -0300 Subject: [PATCH 58/81] fixing cs --- src/Conference/Domain/Command/CreateConference.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Conference/Domain/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php index 7c881fb..f8f6842 100644 --- a/src/Conference/Domain/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -60,8 +60,7 @@ private function __construct( string $description, string $author, \DateTimeImmutable $date - ) - { + ) { Assertion::notEmpty($name); Assertion::notEmpty($description); Assertion::notEmpty($author); From c2038cc03473ca582cf9b05336acf9b3012acd8f Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Sat, 4 Mar 2017 20:47:54 -0300 Subject: [PATCH 59/81] creating new config files and application factory --- config/commands.php | 14 ++++++++ config/repositories.php | 14 ++++++++ config/service-manager.php | 6 ++-- config/services.php | 17 ++------- .../Service/ApplicationFactory.php | 36 +++++++++++++++++++ 5 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 config/commands.php create mode 100644 config/repositories.php create mode 100644 src/Conference/Infrastructure/Service/ApplicationFactory.php diff --git a/config/commands.php b/config/commands.php new file mode 100644 index 0000000..5db7842 --- /dev/null +++ b/config/commands.php @@ -0,0 +1,14 @@ + [ + CreateConference::class => CreateConferenceHandlerFactory::class, + ], + ]; +})(); diff --git a/config/repositories.php b/config/repositories.php new file mode 100644 index 0000000..e43f022 --- /dev/null +++ b/config/repositories.php @@ -0,0 +1,14 @@ + [ + ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class, + ], + ]; +})(); diff --git a/config/service-manager.php b/config/service-manager.php index 94570cd..308e6f4 100644 --- a/config/service-manager.php +++ b/config/service-manager.php @@ -7,8 +7,10 @@ return (function () { return new \Zend\ServiceManager\ServiceManager( array_merge_recursive( - require __DIR__ . '/services.php', - require __DIR__ . '/middlewares.php' + require __DIR__ . '/commands.php', + require __DIR__ . '/middlewares.php', + require __DIR__ . '/repositories.php', + require __DIR__ . '/services.php' ) ); })(); diff --git a/config/services.php b/config/services.php index 57c9347..4b99fba 100644 --- a/config/services.php +++ b/config/services.php @@ -2,13 +2,10 @@ declare(strict_types=1); -use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface; -use Conticket\Conference\Factory\Repository\ConferenceRepositoryFactory; -use Conticket\Conference\Factory\CommandHandler\CreateConferenceHandlerFactory; -use Conticket\Conference\Domain\Command\CreateConference; use Conticket\Conference\Infrastructure\Service\CommandBusFactory; use Conticket\Conference\Infrastructure\Service\ConnectionFactory; use Conticket\Conference\Infrastructure\Service\EventStoreFactory; +use Conticket\Conference\Infrastructure\Service\ApplicationFactory; use Doctrine\DBAL\Connection; use Interop\Container\ContainerInterface; use Prooph\EventStore\EventStore; @@ -20,9 +17,7 @@ return [ // @todo move factories to proper classes 'factories' => [ - Application::class => function (ContainerInterface $container) { - return new Application($container->get(FastRouteRouter::class), $container); - }, + Application::class => ApplicationFactory::class, FastRouteRouter::class => function (ContainerInterface $container) { return new FastRouteRouter(); }, @@ -31,12 +26,6 @@ EventStore::class => EventStoreFactory::class, Connection::class => ConnectionFactory::class, - // @todo move commands/events to another config file - CreateConference::class => CreateConferenceHandlerFactory::class, - - // @todo move repository to another file - ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class, - // @todo move db info to a class to get ENV vars 'db_dsn' => function () { return 'mysql:host=localhost;dbname=conticket'; @@ -45,7 +34,7 @@ return 'root'; }, 'db_password' => function () { - return 'root'; + return null; }, ], ]; diff --git a/src/Conference/Infrastructure/Service/ApplicationFactory.php b/src/Conference/Infrastructure/Service/ApplicationFactory.php new file mode 100644 index 0000000..fd8e5c5 --- /dev/null +++ b/src/Conference/Infrastructure/Service/ApplicationFactory.php @@ -0,0 +1,36 @@ + + */ +final class ApplicationFactory +{ + public function __invoke(ContainerInterface $container): Application + { + return new Application($container->get(FastRouteRouter::class), $container); + } +} \ No newline at end of file From 52b48a6b08fd01ec69e72ee553870c83391ffaf4 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Sat, 4 Mar 2017 20:59:30 -0300 Subject: [PATCH 60/81] creating router factory --- config/services.php | 9 ++--- .../Infrastructure/Service/RouterFactory.php | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/Conference/Infrastructure/Service/RouterFactory.php diff --git a/config/services.php b/config/services.php index 4b99fba..f0efdd8 100644 --- a/config/services.php +++ b/config/services.php @@ -6,22 +6,19 @@ use Conticket\Conference\Infrastructure\Service\ConnectionFactory; use Conticket\Conference\Infrastructure\Service\EventStoreFactory; use Conticket\Conference\Infrastructure\Service\ApplicationFactory; +use Conticket\Conference\Infrastructure\Service\RouterFactory; use Doctrine\DBAL\Connection; -use Interop\Container\ContainerInterface; use Prooph\EventStore\EventStore; use Prooph\ServiceBus\CommandBus; use Zend\Expressive\Application; use Zend\Expressive\Router\FastRouteRouter; + return (function () { return [ - // @todo move factories to proper classes 'factories' => [ Application::class => ApplicationFactory::class, - FastRouteRouter::class => function (ContainerInterface $container) { - return new FastRouteRouter(); - }, - + FastRouteRouter::class => RouterFactory::class, CommandBus::class => CommandBusFactory::class, EventStore::class => EventStoreFactory::class, Connection::class => ConnectionFactory::class, diff --git a/src/Conference/Infrastructure/Service/RouterFactory.php b/src/Conference/Infrastructure/Service/RouterFactory.php new file mode 100644 index 0000000..a6634ca --- /dev/null +++ b/src/Conference/Infrastructure/Service/RouterFactory.php @@ -0,0 +1,36 @@ + + */ +final class RouterFactory +{ + public function __invoke(ContainerInterface $container): FastRouteRouter + { + return new FastRouteRouter(); + } +} \ No newline at end of file From cbb39f02d7c2b07158b3550a0356cb5d2fede5b0 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Sun, 5 Mar 2017 09:35:35 -0300 Subject: [PATCH 61/81] removing router factory, fixing cs in application factory and adding dotenv package --- .env.example | 3 ++ .gitignore | 1 + composer.json | 3 +- config/services.php | 15 ++------ public/index.php | 3 ++ .../Domain/Command/CreateConference.php | 8 +---- .../Service/ApplicationFactory.php | 2 +- .../Service/ConnectionFactory.php | 6 ++-- .../Infrastructure/Service/RouterFactory.php | 36 ------------------- 9 files changed, 16 insertions(+), 61 deletions(-) create mode 100644 .env.example delete mode 100644 src/Conference/Infrastructure/Service/RouterFactory.php diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..4985192 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +DB_DSN=mysql:host=localhost;dbname=conticket +DB_USER=root +DB_PASSWORD= \ No newline at end of file diff --git a/.gitignore b/.gitignore index b2a0a49..8379cb4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ composer.phar composer.lock bin vendor/ +.env app/cache/* app/logs/* app/phpunit.xml diff --git a/composer.json b/composer.json index e23eb6f..dd8d69e 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "ramsey/uuid": "^2.8", "zendframework/zend-expressive": "^1.0", "zendframework/zend-expressive-fastroute": "^1.0", - "zendframework/zend-servicemanager": "^3.2" + "zendframework/zend-servicemanager": "^3.2", + "vlucas/phpdotenv": "^2.4" }, "require-dev": { "behat/behat": "3.*@stable", diff --git a/config/services.php b/config/services.php index f0efdd8..7fc3e89 100644 --- a/config/services.php +++ b/config/services.php @@ -12,27 +12,16 @@ use Prooph\ServiceBus\CommandBus; use Zend\Expressive\Application; use Zend\Expressive\Router\FastRouteRouter; - +use Zend\ServiceManager\Factory\InvokableFactory; return (function () { return [ 'factories' => [ Application::class => ApplicationFactory::class, - FastRouteRouter::class => RouterFactory::class, + FastRouteRouter::class => InvokableFactory::class, CommandBus::class => CommandBusFactory::class, EventStore::class => EventStoreFactory::class, Connection::class => ConnectionFactory::class, - - // @todo move db info to a class to get ENV vars - 'db_dsn' => function () { - return 'mysql:host=localhost;dbname=conticket'; - }, - 'db_user' => function () { - return 'root'; - }, - 'db_password' => function () { - return null; - }, ], ]; })(); diff --git a/public/index.php b/public/index.php index e7d1703..9e205eb 100644 --- a/public/index.php +++ b/public/index.php @@ -7,6 +7,9 @@ (function () { require __DIR__ . '/../vendor/autoload.php'; + /* loading .env variables */ + (new \Dotenv\Dotenv(__DIR__ . '/..'))->load(); + /* @var $serviceManager \Zend\ServiceManager\ServiceManager */ $serviceManager = require __DIR__ . '/../config/service-manager.php'; diff --git a/src/Conference/Domain/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php index f8f6842..f487fc6 100644 --- a/src/Conference/Domain/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -79,13 +79,7 @@ public static function fromRequestData( string $author, \DateTimeImmutable $date ): self { - return new self( - $conferenceId, - $name, - $description, - $author, - $date - ); + return new self($conferenceId, $name, $description, $author, $date); } /** diff --git a/src/Conference/Infrastructure/Service/ApplicationFactory.php b/src/Conference/Infrastructure/Service/ApplicationFactory.php index fd8e5c5..04c612d 100644 --- a/src/Conference/Infrastructure/Service/ApplicationFactory.php +++ b/src/Conference/Infrastructure/Service/ApplicationFactory.php @@ -33,4 +33,4 @@ public function __invoke(ContainerInterface $container): Application { return new Application($container->get(FastRouteRouter::class), $container); } -} \ No newline at end of file +} diff --git a/src/Conference/Infrastructure/Service/ConnectionFactory.php b/src/Conference/Infrastructure/Service/ConnectionFactory.php index 5a575a7..b159023 100644 --- a/src/Conference/Infrastructure/Service/ConnectionFactory.php +++ b/src/Conference/Infrastructure/Service/ConnectionFactory.php @@ -35,9 +35,9 @@ public function __invoke(ContainerInterface $container): Connection $connection = new Connection( [ 'pdo' => new PDO( - $container->get('db_dsn'), - $container->get('db_user'), - $container->get('db_password') + getenv('DB_DSN'), + getenv('DB_USER'), + getenv('DB_PASSWORD') ), ], new Driver() diff --git a/src/Conference/Infrastructure/Service/RouterFactory.php b/src/Conference/Infrastructure/Service/RouterFactory.php deleted file mode 100644 index a6634ca..0000000 --- a/src/Conference/Infrastructure/Service/RouterFactory.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ -final class RouterFactory -{ - public function __invoke(ContainerInterface $container): FastRouteRouter - { - return new FastRouteRouter(); - } -} \ No newline at end of file From 3da502818a754edd6d6d46fffa920c42d4c9414b Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Sun, 5 Mar 2017 09:40:07 -0300 Subject: [PATCH 62/81] adding docheader --- config/commands.php | 16 ++++++++++++++++ config/repositories.php | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/config/commands.php b/config/commands.php index 5db7842..03fdd90 100644 --- a/config/commands.php +++ b/config/commands.php @@ -1,4 +1,20 @@ Date: Sun, 5 Mar 2017 09:50:58 -0300 Subject: [PATCH 63/81] adding eof --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 4985192..e69f3ac 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ DB_DSN=mysql:host=localhost;dbname=conticket DB_USER=root -DB_PASSWORD= \ No newline at end of file +DB_PASSWORD= From 63d110a4a1048078cd977cf2804212dc36f5acb6 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Mon, 6 Mar 2017 18:35:47 -0300 Subject: [PATCH 64/81] fixing middlewares config file --- config/middlewares.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/config/middlewares.php b/config/middlewares.php index 958c34d..69ae790 100644 --- a/config/middlewares.php +++ b/config/middlewares.php @@ -5,8 +5,10 @@ use Conticket\Conference\Infrastructure\Middleware\CreateConferenceMiddleware; use Conticket\Conference\Factory\Middleware\CreateConferenceMiddlewareFactory; -return [ - 'factories' => [ - CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class, - ], -]; +return (function () { + return [ + 'factories' => [ + CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class, + ], + ]; +})(); \ No newline at end of file From a4ffc9df3d53ab406517d7ffab4fd6d03cb90668 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Tue, 7 Mar 2017 22:10:41 -0300 Subject: [PATCH 65/81] adding pdo factory --- config/middlewares.php | 2 +- config/service-manager.php | 4 +-- config/services.php | 15 ++++----- public/index.php | 1 - .../Service/ConnectionFactory.php | 12 +++---- .../Infrastructure/Service/PDOFactory.php | 31 +++++++++++++++++++ 6 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 src/Conference/Infrastructure/Service/PDOFactory.php diff --git a/config/middlewares.php b/config/middlewares.php index 69ae790..a1a49a6 100644 --- a/config/middlewares.php +++ b/config/middlewares.php @@ -11,4 +11,4 @@ CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class, ], ]; -})(); \ No newline at end of file +})(); diff --git a/config/service-manager.php b/config/service-manager.php index 308e6f4..39ff25f 100644 --- a/config/service-manager.php +++ b/config/service-manager.php @@ -7,10 +7,10 @@ return (function () { return new \Zend\ServiceManager\ServiceManager( array_merge_recursive( + require __DIR__ . '/services.php', require __DIR__ . '/commands.php', require __DIR__ . '/middlewares.php', - require __DIR__ . '/repositories.php', - require __DIR__ . '/services.php' + require __DIR__ . '/repositories.php' ) ); })(); diff --git a/config/services.php b/config/services.php index 7fc3e89..d256f4e 100644 --- a/config/services.php +++ b/config/services.php @@ -2,11 +2,11 @@ declare(strict_types=1); +use Conticket\Conference\Infrastructure\Service\ApplicationFactory; use Conticket\Conference\Infrastructure\Service\CommandBusFactory; use Conticket\Conference\Infrastructure\Service\ConnectionFactory; use Conticket\Conference\Infrastructure\Service\EventStoreFactory; -use Conticket\Conference\Infrastructure\Service\ApplicationFactory; -use Conticket\Conference\Infrastructure\Service\RouterFactory; +use Conticket\Conference\Infrastructure\Service\PDOFactory; use Doctrine\DBAL\Connection; use Prooph\EventStore\EventStore; use Prooph\ServiceBus\CommandBus; @@ -17,11 +17,12 @@ return (function () { return [ 'factories' => [ - Application::class => ApplicationFactory::class, - FastRouteRouter::class => InvokableFactory::class, - CommandBus::class => CommandBusFactory::class, - EventStore::class => EventStoreFactory::class, - Connection::class => ConnectionFactory::class, + Application::class => ApplicationFactory::class, + FastRouteRouter::class => InvokableFactory::class, + CommandBus::class => CommandBusFactory::class, + EventStore::class => EventStoreFactory::class, + Connection::class => ConnectionFactory::class, + \PDO::class => PDOFactory::class, ], ]; })(); diff --git a/public/index.php b/public/index.php index 9e205eb..b1a99d2 100644 --- a/public/index.php +++ b/public/index.php @@ -7,7 +7,6 @@ (function () { require __DIR__ . '/../vendor/autoload.php'; - /* loading .env variables */ (new \Dotenv\Dotenv(__DIR__ . '/..'))->load(); /* @var $serviceManager \Zend\ServiceManager\ServiceManager */ diff --git a/src/Conference/Infrastructure/Service/ConnectionFactory.php b/src/Conference/Infrastructure/Service/ConnectionFactory.php index b159023..81858b0 100644 --- a/src/Conference/Infrastructure/Service/ConnectionFactory.php +++ b/src/Conference/Infrastructure/Service/ConnectionFactory.php @@ -21,24 +21,19 @@ namespace Conticket\Conference\Infrastructure\Service; use Doctrine\DBAL\Connection; + use Doctrine\DBAL\Driver\PDOMySql\Driver; use Doctrine\DBAL\Schema\SchemaException; use Interop\Container\ContainerInterface; -use PDO; use Prooph\EventStore\Adapter\Doctrine\Schema\EventStoreSchema; final class ConnectionFactory { public function __invoke(ContainerInterface $container): Connection { - // @todo create service for \PDO - $connection = new Connection( + $connection = new Connection( [ - 'pdo' => new PDO( - getenv('DB_DSN'), - getenv('DB_USER'), - getenv('DB_PASSWORD') - ), + 'pdo' => $container->get(\PDO::class) ], new Driver() ); @@ -51,6 +46,7 @@ public function __invoke(ContainerInterface $container): Connection foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { $connection->exec($sql); } + } catch (SchemaException $ignored) { // this is ignored for now - we don't want to re-create the schema every time } diff --git a/src/Conference/Infrastructure/Service/PDOFactory.php b/src/Conference/Infrastructure/Service/PDOFactory.php new file mode 100644 index 0000000..735919d --- /dev/null +++ b/src/Conference/Infrastructure/Service/PDOFactory.php @@ -0,0 +1,31 @@ + Date: Tue, 7 Mar 2017 22:14:59 -0300 Subject: [PATCH 66/81] sorting packages --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dd8d69e..14017ac 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,10 @@ "prooph/event-store-doctrine-adapter": "^3.3", "prooph/service-bus": "^5.2", "ramsey/uuid": "^2.8", + "vlucas/phpdotenv": "^2.4", "zendframework/zend-expressive": "^1.0", "zendframework/zend-expressive-fastroute": "^1.0", - "zendframework/zend-servicemanager": "^3.2", - "vlucas/phpdotenv": "^2.4" + "zendframework/zend-servicemanager": "^3.2" }, "require-dev": { "behat/behat": "3.*@stable", From 5e382fe1fb726bd7c0d66afa88ae912165323b22 Mon Sep 17 00:00:00 2001 From: lucianoqueiroz Date: Wed, 8 Mar 2017 11:42:08 -0300 Subject: [PATCH 67/81] implementing factory interface in all service factories --- .../Infrastructure/Service/ApplicationFactory.php | 5 +++-- src/Conference/Infrastructure/Service/CommandBusFactory.php | 5 +++-- src/Conference/Infrastructure/Service/ConnectionFactory.php | 6 +++--- src/Conference/Infrastructure/Service/EventStoreFactory.php | 5 +++-- src/Conference/Infrastructure/Service/PDOFactory.php | 5 +++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Conference/Infrastructure/Service/ApplicationFactory.php b/src/Conference/Infrastructure/Service/ApplicationFactory.php index 04c612d..0191b72 100644 --- a/src/Conference/Infrastructure/Service/ApplicationFactory.php +++ b/src/Conference/Infrastructure/Service/ApplicationFactory.php @@ -23,13 +23,14 @@ use Interop\Container\ContainerInterface; use Zend\Expressive\Router\FastRouteRouter; use Zend\Expressive\Application; +use Zend\ServiceManager\Factory\FactoryInterface; /** * @author Luciano Queiroz */ -final class ApplicationFactory +final class ApplicationFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container): Application + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): Application { return new Application($container->get(FastRouteRouter::class), $container); } diff --git a/src/Conference/Infrastructure/Service/CommandBusFactory.php b/src/Conference/Infrastructure/Service/CommandBusFactory.php index f448ac5..5e4c090 100644 --- a/src/Conference/Infrastructure/Service/CommandBusFactory.php +++ b/src/Conference/Infrastructure/Service/CommandBusFactory.php @@ -27,13 +27,14 @@ use Prooph\ServiceBus\CommandBus; use Prooph\ServiceBus\MessageBus; use Prooph\ServiceBus\Plugin\ServiceLocatorPlugin; +use Zend\ServiceManager\Factory\FactoryInterface; /** * @author Jefersson Nathan */ -final class CommandBusFactory +final class CommandBusFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container): CommandBus + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): CommandBus { $commandBus = new CommandBus(); $commandBus->utilize(new ServiceLocatorPlugin($container)); diff --git a/src/Conference/Infrastructure/Service/ConnectionFactory.php b/src/Conference/Infrastructure/Service/ConnectionFactory.php index 81858b0..de99e4a 100644 --- a/src/Conference/Infrastructure/Service/ConnectionFactory.php +++ b/src/Conference/Infrastructure/Service/ConnectionFactory.php @@ -21,15 +21,15 @@ namespace Conticket\Conference\Infrastructure\Service; use Doctrine\DBAL\Connection; - use Doctrine\DBAL\Driver\PDOMySql\Driver; use Doctrine\DBAL\Schema\SchemaException; use Interop\Container\ContainerInterface; use Prooph\EventStore\Adapter\Doctrine\Schema\EventStoreSchema; +use Zend\ServiceManager\Factory\FactoryInterface; -final class ConnectionFactory +final class ConnectionFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container): Connection + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): Connection { $connection = new Connection( [ diff --git a/src/Conference/Infrastructure/Service/EventStoreFactory.php b/src/Conference/Infrastructure/Service/EventStoreFactory.php index c0cb3cb..a6c3f26 100644 --- a/src/Conference/Infrastructure/Service/EventStoreFactory.php +++ b/src/Conference/Infrastructure/Service/EventStoreFactory.php @@ -28,13 +28,14 @@ use Prooph\EventStore\Adapter\Doctrine\DoctrineEventStoreAdapter; use Prooph\EventStore\Adapter\PayloadSerializer\JsonPayloadSerializer; use Prooph\EventStore\EventStore; +use Zend\ServiceManager\Factory\FactoryInterface; /** * @author Jefersson Nathan */ -final class EventStoreFactory +final class EventStoreFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container): EventStore + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): EventStore { return new EventStore( new DoctrineEventStoreAdapter( diff --git a/src/Conference/Infrastructure/Service/PDOFactory.php b/src/Conference/Infrastructure/Service/PDOFactory.php index 735919d..526f9dd 100644 --- a/src/Conference/Infrastructure/Service/PDOFactory.php +++ b/src/Conference/Infrastructure/Service/PDOFactory.php @@ -21,10 +21,11 @@ namespace Conticket\Conference\Infrastructure\Service; use Interop\Container\ContainerInterface; +use Zend\ServiceManager\Factory\FactoryInterface; -final class PDOFactory +final class PDOFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container): \PDO + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): \PDO { return new \PDO(getenv('DB_DSN'), getenv('DB_USER'), getenv('DB_PASSWORD')); } From 28db869254ff8adca9ac35c14ecacf4265d879a6 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 14:38:37 -0300 Subject: [PATCH 68/81] remove change default place for 3th libraries binaries --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 14017ac..f8629c8 100644 --- a/composer.json +++ b/composer.json @@ -47,8 +47,5 @@ "malukenho/docheader": "^0.1.5", "phpspec/phpspec": "^2.5", "phpunit/phpunit": "4.7.*" - }, - "config": { - "bin-dir": "bin" } } From 56f331bf10af11dc917b59583b314e06a052c2cc Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 15:52:50 -0300 Subject: [PATCH 69/81] change tests directory and add filter section to allow code coverage --- phpunit.xml.dist | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 09db690..47da323 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,6 +12,11 @@ backupGlobals="false" > - ./tests/ConticketFunctionalTests + ./tests + + + ./src + + From e5f58cc42d2f5e081becbb3745ccf6cf382db20e Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 15:54:11 -0300 Subject: [PATCH 70/81] update phpunit version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f8629c8..2e84505 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,6 @@ "behat/mink-selenium2-driver": "*", "malukenho/docheader": "^0.1.5", "phpspec/phpspec": "^2.5", - "phpunit/phpunit": "4.7.*" + "phpunit/phpunit": "^5.6" } } From c841a5a994becaa9bdad4ab68fe67f21a2689b7c Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 15:54:51 -0300 Subject: [PATCH 71/81] add tests for conference id --- .../Domain/ConferenceIdTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/ConferenceTest/Domain/ConferenceIdTest.php diff --git a/tests/ConferenceTest/Domain/ConferenceIdTest.php b/tests/ConferenceTest/Domain/ConferenceIdTest.php new file mode 100644 index 0000000..94b1b78 --- /dev/null +++ b/tests/ConferenceTest/Domain/ConferenceIdTest.php @@ -0,0 +1,45 @@ + + */ +final class ConferenceIdTest extends PHPUnit_Framework_TestCase +{ + public function test_conference_id(): void + { + self::assertInstanceOf(ConferenceId::class, ConferenceId::new()); + + $conference = ConferenceId::new(); + + self::assertEquals($conference, ConferenceId::fromString((string) $conference)); + + self::assertInstanceOf(Uuid::class, $conference->uuid()); + self::assertEquals(Uuid::fromString((string) $conference), $conference->uuid()); + } +} From 798e1c27b1d5f94ed696000ac8724c978fe50237 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Fri, 17 Feb 2017 15:55:15 -0300 Subject: [PATCH 72/81] add tests for conference aggregate --- .../ConferenceTest/Domain/ConferenceTest.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/ConferenceTest/Domain/ConferenceTest.php diff --git a/tests/ConferenceTest/Domain/ConferenceTest.php b/tests/ConferenceTest/Domain/ConferenceTest.php new file mode 100644 index 0000000..c0f0245 --- /dev/null +++ b/tests/ConferenceTest/Domain/ConferenceTest.php @@ -0,0 +1,64 @@ + + */ +final class ConferenceTest extends PHPUnit_Framework_TestCase +{ + public function test_it_should_create_new_conference(): void + { + $conferenceId = ConferenceId::new(); + $conferenceName = 'Conference Name'; + $conferenceDescription = 'Conference description'; + $conferenceAuthor = 'Conference author'; + $conferenceDate = new \DateTimeImmutable('now'); + + $conference = Conference::new( + $conferenceId, + $conferenceName, + $conferenceDescription, + $conferenceAuthor, + $conferenceDate + ); + + self::assertInstanceOf(Conference::class, $conference); + + $event = $conference->popRecordedEvents(); + + self::assertCount(1, $event); + + self::assertInstanceOf(ConferenceId::class, $event[0]->getConferenceId()); + self::assertEquals($conferenceId, $event[0]->getConferenceId()); + self::assertSame($conferenceName, $event[0]->getName()); + self::assertSame($conferenceDescription, $event[0]->getDescription()); + self::assertSame($conferenceAuthor, $event[0]->getAuthor()); + self::assertEquals($conferenceDate, $event[0]->getDate()); + } +} From bcbad633b2b0ca5235869282a032b13485866bab Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Thu, 23 Feb 2017 10:15:24 -0300 Subject: [PATCH 73/81] fix bin call location --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b4843ec..9885bed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,6 @@ notifications: email: false script: - - ./bin/phpunit -c app - - ./bin/docheader check src/ - - ./bin/behat + - ./vendor/bin/phpunit -c app + - ./vendor/bin/docheader check src/ + - ./vendor/bin/behat From b5a54236e31614224248c0c6fecead96017c7ab0 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:19:49 -0300 Subject: [PATCH 74/81] remove invalid parameter on phpunit config --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 47da323..736ed82 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,7 +15,7 @@ ./tests - + ./src From 19aca11e3dcde523fa4942397efda30c353834bf Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:20:19 -0300 Subject: [PATCH 75/81] add missing test to get conferenceId --- .../ConferenceTest/Domain/ConferenceTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ConferenceTest/Domain/ConferenceTest.php b/tests/ConferenceTest/Domain/ConferenceTest.php index c0f0245..36460e6 100644 --- a/tests/ConferenceTest/Domain/ConferenceTest.php +++ b/tests/ConferenceTest/Domain/ConferenceTest.php @@ -61,4 +61,24 @@ public function test_it_should_create_new_conference(): void self::assertSame($conferenceAuthor, $event[0]->getAuthor()); self::assertEquals($conferenceDate, $event[0]->getDate()); } + + public function test_it_should_be_able_to_return_conference_id() + { + $conferenceId = ConferenceId::new(); + $conferenceName = 'Conference Name'; + $conferenceDescription = 'Conference description'; + $conferenceAuthor = 'Conference author'; + $conferenceDate = new \DateTimeImmutable('now'); + + $conference = Conference::new( + $conferenceId, + $conferenceName, + $conferenceDescription, + $conferenceAuthor, + $conferenceDate + ); + + self::assertEquals($conferenceId, $conference->conferenceId()); + self::assertSame((string) $conferenceId, (string) $conference->conferenceId()); + } } From 4733a48e0dddbcc23c67ddbb08620b3230a04da4 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:20:53 -0300 Subject: [PATCH 76/81] add tests for create conference command and domain event --- .../Domain/Command/CreateConferenceTest.php | 140 ++++++++++++++++++ .../Domain/Event/ConferenceWasCreatedTest.php | 65 ++++++++ 2 files changed, 205 insertions(+) create mode 100644 tests/ConferenceTest/Domain/Command/CreateConferenceTest.php create mode 100644 tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php diff --git a/tests/ConferenceTest/Domain/Command/CreateConferenceTest.php b/tests/ConferenceTest/Domain/Command/CreateConferenceTest.php new file mode 100644 index 0000000..1358cef --- /dev/null +++ b/tests/ConferenceTest/Domain/Command/CreateConferenceTest.php @@ -0,0 +1,140 @@ + + */ +final class CreateConferenceTest extends PHPUnit_Framework_TestCase +{ + /** + * @var ConferenceId + */ + private $conferenceId; + /** + * @var string + */ + private $conferenceName; + /** + * @var string + */ + private $conferenceDescription; + /** + * @var string + */ + private $conferenceAuthor; + /** + * @var DateTimeImmutable + */ + private $conferenceDate; + + /** + * {@inheritDoc} + */ + public function setUp(): void + { + $this->conferenceId = ConferenceId::new(); + $this->conferenceName = 'Conference name'; + $this->conferenceDescription = 'Conference description'; + $this->conferenceAuthor = 'Conference author'; + $this->conferenceDate = new DateTimeImmutable; + } + + public function test_conference_name_should_not_be_empty(): void + { + $this->setExpectedException(\InvalidArgumentException::class); + + CreateConference::fromRequestData( + $this->conferenceId, + '', + $this->conferenceDescription, + $this->conferenceAuthor, + $this->conferenceDate + ); + } + + public function test_conference_description_should_not_be_empty(): void + { + $this->setExpectedException(\InvalidArgumentException::class); + + CreateConference::fromRequestData( + $this->conferenceId, + $this->conferenceName, + '', + $this->conferenceAuthor, + $this->conferenceDate + ); + } + + public function test_conference_author_should_not_be_empty(): void + { + $this->setExpectedException(\InvalidArgumentException::class); + + CreateConference::fromRequestData( + $this->conferenceId, + $this->conferenceName, + $this->conferenceDescription, + '', + $this->conferenceDate + ); + } + + public function test_create_conference(): void + { + $command = CreateConference::fromRequestData( + $this->conferenceId, + $this->conferenceName, + $this->conferenceDescription, + $this->conferenceAuthor, + $this->conferenceDate + ); + + self::assertSame($this->conferenceId, $command->getConferenceId()); + self::assertSame($this->conferenceName, $command->getName()); + self::assertSame($this->conferenceDescription, $command->getDescription()); + self::assertSame($this->conferenceAuthor, $command->getAuthor()); + self::assertSame($this->conferenceDate, $command->getDate()); + + self::assertSame( + [ + 'name' => $this->conferenceName, + 'description' => $this->conferenceDescription, + 'author' => $this->conferenceAuthor, + 'conferenceId' => (string) $this->conferenceId, + 'date' => $this->conferenceDate->format('U.u'), + ], + $command->payload() + ); + + /* @var $nakedCommand CreateConference */ + $nakedCommand = (new \ReflectionClass(CreateConference::class))->newInstanceWithoutConstructor(); + $nakedCommand->setPayload($command->payload()); + + self::assertEquals($command, $nakedCommand); + } +} diff --git a/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php b/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php new file mode 100644 index 0000000..c2d1e4a --- /dev/null +++ b/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php @@ -0,0 +1,65 @@ + + */ +final class ConferenceWasCreatedTest extends PHPUnit_Framework_TestCase +{ + public function test_it_can_create_event_from_conference_info() + { + $conferenceId = ConferenceId::new(); + $conferenceName = 'Conference Name'; + $conferenceDescription = 'Conference description'; + $conferenceAuthor = 'Conference author'; + $conferenceDate = new \DateTimeImmutable('now'); + + $event = ConferenceWasCreated::fromRequestData( + $conferenceId, + $conferenceName, + $conferenceDescription, + $conferenceAuthor, + $conferenceDate + ); + + self::assertEquals($conferenceId, $event->getConferenceId()); + self::assertSame($conferenceName, $event->getName()); + self::assertSame($conferenceDescription, $event->getDescription()); + self::assertSame($conferenceAuthor, $event->getAuthor()); + self::assertEquals($conferenceDate, $event->getDate()); + + self::assertSame( + [ + 'name' => $conferenceName, + 'description' => $conferenceDescription, + 'conferenceId' => (string) $conferenceId, + 'author' => $conferenceAuthor, + 'date' => $conferenceDate->format('U.u'), + ], + $event->payload() + ); + } +} From 42b34d9a27e70cbccd38d36b7408d5d7375ba7f3 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:21:29 -0300 Subject: [PATCH 77/81] turn payload public for now --- src/Conference/Domain/Command/CreateConference.php | 2 +- src/Conference/Domain/Conference.php | 2 +- src/Conference/Domain/Event/ConferenceWasCreated.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Conference/Domain/Command/CreateConference.php b/src/Conference/Domain/Command/CreateConference.php index f487fc6..6b8400d 100644 --- a/src/Conference/Domain/Command/CreateConference.php +++ b/src/Conference/Domain/Command/CreateConference.php @@ -99,7 +99,7 @@ public function payload(): array /** * {@inheritDoc} */ - protected function setPayload(array $payload): void + public function setPayload(array $payload): void { [ $this->name, diff --git a/src/Conference/Domain/Conference.php b/src/Conference/Domain/Conference.php index e66407c..0969ac7 100644 --- a/src/Conference/Domain/Conference.php +++ b/src/Conference/Domain/Conference.php @@ -52,7 +52,7 @@ public function whenConferenceWasCreated(ConferenceWasCreated $event): void } /** - * @todo move it to a trait + * @todo move it to a trait? * * @return array */ diff --git a/src/Conference/Domain/Event/ConferenceWasCreated.php b/src/Conference/Domain/Event/ConferenceWasCreated.php index b75aff9..75cc4ff 100644 --- a/src/Conference/Domain/Event/ConferenceWasCreated.php +++ b/src/Conference/Domain/Event/ConferenceWasCreated.php @@ -94,7 +94,7 @@ public function payload(): array /** * {@inheritDoc} */ - protected function setPayload(array $payload): void + public function setPayload(array $payload): void { [ $this->name, From 73cf2c8af3f70b63c44a2be0a72c81e36c41c70c Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:32:03 -0300 Subject: [PATCH 78/81] add test to command handler --- .../CreateConferenceHandler.php | 2 +- .../CreateConferenceHandlerTest.php | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php diff --git a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php index 28adb85..85621b8 100644 --- a/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php +++ b/src/Conference/Domain/CommandHandler/CreateConferenceHandler.php @@ -39,7 +39,7 @@ public function __construct(ConferenceRepositoryInterface $repository) $this->repository = $repository; } - public function __invoke(CreateConference $command) + public function __invoke(CreateConference $command): void { $this->repository->store(Conference::new( $command->getConferenceId(), diff --git a/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php b/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php new file mode 100644 index 0000000..98ce3b4 --- /dev/null +++ b/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php @@ -0,0 +1,52 @@ + + */ +final class CreateConferenceHandlerTest extends PHPUnit_Framework_TestCase +{ + public function test_it_should_store_a_new_conference(): void + { + $command = CreateConference::fromRequestData( + $conferenceId = ConferenceId::new(), + $conferenceName = 'Conference name', + $conferenceDescription = 'description', + $conferenceAuthor ='author', + new \DateTimeImmutable() + ); + + /* @var $repository \PHPUnit_Framework_MockObject_MockObject|ConferenceRepositoryInterface*/ + $repository = $this->createMock(ConferenceRepositoryInterface::class); + + $repository->expects(self::once())->method('store'); + + $handler = new CreateConferenceHandler($repository); + $handler->__invoke($command); + } +} From db88b8c29a2ba56cbcdaa3ccf4cb755a60bae7f7 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:35:51 -0300 Subject: [PATCH 79/81] annotate missing exceptions --- .../Factory/Middleware/CreateConferenceMiddlewareFactory.php | 2 ++ tests/ConferenceTest/Domain/ConferenceTest.php | 2 +- tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php b/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php index 4101e13..2084565 100644 --- a/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php +++ b/src/Conference/Factory/Middleware/CreateConferenceMiddlewareFactory.php @@ -33,6 +33,8 @@ final class CreateConferenceMiddlewareFactory * {@inheritDoc} * * @throws \Interop\Container\Exception\ContainerException + * @throws \Psr\Container\ContainerExceptionInterface + * @throws \Psr\Container\NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container): CreateConferenceMiddleware { diff --git a/tests/ConferenceTest/Domain/ConferenceTest.php b/tests/ConferenceTest/Domain/ConferenceTest.php index 36460e6..e5623d4 100644 --- a/tests/ConferenceTest/Domain/ConferenceTest.php +++ b/tests/ConferenceTest/Domain/ConferenceTest.php @@ -62,7 +62,7 @@ public function test_it_should_create_new_conference(): void self::assertEquals($conferenceDate, $event[0]->getDate()); } - public function test_it_should_be_able_to_return_conference_id() + public function test_it_should_be_able_to_return_conference_id(): void { $conferenceId = ConferenceId::new(); $conferenceName = 'Conference Name'; diff --git a/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php b/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php index c2d1e4a..b2381c0 100644 --- a/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php +++ b/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php @@ -29,7 +29,7 @@ */ final class ConferenceWasCreatedTest extends PHPUnit_Framework_TestCase { - public function test_it_can_create_event_from_conference_info() + public function test_it_can_create_event_from_conference_info(): void { $conferenceId = ConferenceId::new(); $conferenceName = 'Conference Name'; From fa0b846c4fd16810f5843e094c760fef5905dfba Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:36:58 -0300 Subject: [PATCH 80/81] remove old phpunit parameter --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9885bed..4aa3a41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,6 @@ notifications: email: false script: - - ./vendor/bin/phpunit -c app + - ./vendor/bin/phpunit - ./vendor/bin/docheader check src/ - ./vendor/bin/behat From d5278e9748b0084c4e3e31f71ae629a0d4b23df1 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Apr 2017 23:39:16 -0300 Subject: [PATCH 81/81] add missing strict_types --- .../Domain/CommandHandler/CreateConferenceHandlerTest.php | 2 ++ tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php b/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php index 98ce3b4..f7b37cb 100644 --- a/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php +++ b/tests/ConferenceTest/Domain/CommandHandler/CreateConferenceHandlerTest.php @@ -16,6 +16,8 @@ * and is licensed under the MIT license. */ +declare(strict_types=1); + namespace ConticketTest\ConferenceTest\Domain\CommandHandler; use Conticket\Conference\Domain\Command\CreateConference; diff --git a/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php b/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php index b2381c0..990f417 100644 --- a/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php +++ b/tests/ConferenceTest/Domain/Event/ConferenceWasCreatedTest.php @@ -16,6 +16,8 @@ * and is licensed under the MIT license. */ +declare(strict_types=1); + namespace ConticketTest\ConferenceTest\Domain\Event; use Conticket\Conference\Domain\ConferenceId;