Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionando Event Sourced Aggregates #31

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
98c5a27
adding new packages, changing symofony to zend-expressive and startin…
lucianoqueiroz Dec 1, 2016
047b7f1
creating ticket aggregate and a value object TicketLifespan for encap…
lucianoqueiroz Dec 1, 2016
c7350eb
adding return to ticket aggregate method constructor
lucianoqueiroz Dec 1, 2016
5db4eff
patching up some fixes of last code review
lucianoqueiroz Dec 1, 2016
2d10867
patching up more fixes
lucianoqueiroz Dec 1, 2016
1deefd3
deleting old files
lucianoqueiroz Dec 2, 2016
afb1b20
renaming method on ticket lifespan object
lucianoqueiroz Dec 2, 2016
8fc1a4e
removing doctrine-mongodb-odm and adding money package
lucianoqueiroz Dec 2, 2016
afc97bd
modelling ticket related value objects and events, improving ticket a…
lucianoqueiroz Dec 2, 2016
640c1ea
Better php version description as it's not semantic version complains
Feb 3, 2017
5ae319e
composer require zendframework/zend-expressive-fastroute
Feb 3, 2017
654acf0
composer require zendframework/zend-servicemanager
Feb 3, 2017
343401e
describe basic factories for router services
Feb 3, 2017
7dcd112
added config file for middleware
Feb 3, 2017
971198d
remove web folder
Feb 3, 2017
e0404ba
added root index file
Feb 3, 2017
432d3b3
create service manager with given configs
Feb 3, 2017
80a419d
sort composer packages
Feb 3, 2017
a0f60e9
register middleware to register a conference
Feb 3, 2017
5a56ced
register router on front controller
Feb 3, 2017
0654cbe
added event to create conference
Feb 3, 2017
604baa7
added identifier for conference aggregate
Feb 3, 2017
8d521bc
added command to create conference
Feb 3, 2017
0f46074
composer require zendframework/zend-servicemanager
Feb 3, 2017
f38a6cc
config proper namespace psr-4
Feb 3, 2017
a33f366
make responsibilities more descriptive
Feb 3, 2017
b9baa21
fix error on conference id implementation
Feb 3, 2017
cb74529
fix middleware factories name
Feb 3, 2017
a173b99
introduce a command bus
Feb 3, 2017
9a440b8
move files to fit psr-4 declaration
Feb 3, 2017
cb93649
middleware example
Feb 3, 2017
33c9aab
create conference middleware factory
Feb 3, 2017
31773ed
add repository for conference aggregate
Feb 3, 2017
f6ed898
command handler for create a conference
Feb 3, 2017
b6f3c8c
added repository factory
Feb 3, 2017
d9da9db
add conference aggregate
Feb 3, 2017
09f9e85
added command handler factory for create conference
Feb 3, 2017
34c5852
describe services on config file
Feb 3, 2017
72e9029
composer require --sort-packages prooph/event-store-doctrine-adapter
Feb 17, 2017
9e3aa6e
fix conference aggregate root namespace
Feb 17, 2017
085523e
register missing services
Feb 17, 2017
06f54b2
allow show errors exceptions on our environment
Feb 17, 2017
2c41c30
fix namespace issues
Feb 17, 2017
f70ed6a
add connection service
Feb 17, 2017
5b27875
add event store factory
Feb 17, 2017
65c717d
creates schema if it doesn't exists
Feb 17, 2017
3ac65bd
simplify repository
Feb 17, 2017
f32a792
fix conference if reference
Feb 17, 2017
28253d7
create conference aggregate
Feb 17, 2017
df8c9bb
add method to respond to `ConferenceWasCreated` domain event
Feb 17, 2017
af4bc72
use transactional method
Feb 17, 2017
4195114
remove code from old structure
Feb 17, 2017
db290dc
composer require --dev --sort-packages malukenho/docheader
Feb 17, 2017
71a467c
added `.docheader` template file
Feb 17, 2017
f1ee208
fix missing doc header
Feb 17, 2017
2f90c02
clean up travis script
Feb 17, 2017
9c88345
moving logic from named constructor to private constructor
lucianoqueiroz Mar 4, 2017
e26062a
fixing cs
lucianoqueiroz Mar 4, 2017
c2038cc
creating new config files and application factory
lucianoqueiroz Mar 4, 2017
52b48a6
creating router factory
lucianoqueiroz Mar 4, 2017
cbb39f0
removing router factory, fixing cs in application factory and adding …
lucianoqueiroz Mar 5, 2017
3da5028
adding docheader
lucianoqueiroz Mar 5, 2017
edb6437
adding eof
lucianoqueiroz Mar 5, 2017
63d110a
fixing middlewares config file
lucianoqueiroz Mar 6, 2017
a4ffc9d
adding pdo factory
lucianoqueiroz Mar 8, 2017
d2fb3cf
sorting packages
lucianoqueiroz Mar 8, 2017
5e382fe
implementing factory interface in all service factories
lucianoqueiroz Mar 8, 2017
b2e51bd
Merge pull request #32 from lucianoqueiroz/improvements/#1
Mar 8, 2017
28db869
remove change default place for 3th libraries binaries
Feb 17, 2017
56f331b
change tests directory and add filter section to allow code coverage
Feb 17, 2017
e5f58cc
update phpunit version
Feb 17, 2017
c841a5a
add tests for conference id
Feb 17, 2017
798e1c2
add tests for conference aggregate
Feb 17, 2017
bcbad63
fix bin call location
Feb 23, 2017
b5a5423
remove invalid parameter on phpunit config
Apr 27, 2017
19aca11
add missing test to get conferenceId
Apr 27, 2017
4733a48
add tests for create conference command and domain event
Apr 27, 2017
42b34d9
turn payload public for now
Apr 27, 2017
73cf2c8
add test to command handler
Apr 27, 2017
db88b8c
annotate missing exceptions
Apr 27, 2017
fa0b846
remove old phpunit parameter
Apr 27, 2017
d5278e9
add missing strict_types
Apr 27, 2017
3ca0b81
Merge pull request #1 from PHPeste/inhancement/#31
lucianoqueiroz Apr 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .docheader
Original file line number Diff line number Diff line change
@@ -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.
*/
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_DSN=mysql:host=localhost;dbname=conticket
DB_USER=root
DB_PASSWORD=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ composer.phar
composer.lock
bin
vendor/
.env
app/cache/*
app/logs/*
app/phpunit.xml
Expand Down
33 changes: 5 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/behat
- ./vendor/bin/phpunit
- ./vendor/bin/docheader check src/
- ./vendor/bin/behat
70 changes: 17 additions & 53 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
],
"autoload": {
"psr-4": {
"": "src/",
"SymfonyStandard\\": "app/SymfonyStandard/"
"Conticket\\": "src/"
}
},
"autoload-dev": {
Expand All @@ -24,64 +23,29 @@
]
},
"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",
"php": "7.0.* || 7.1.*",
"beberlei/assert": "^2.6",
"incenteev/composer-parameter-handler": "~2.0",
"hwi/oauth-bundle": "0.4.*@dev",
"snc/redis-bundle": "~1.1",
"moneyphp/money": "^3.0",
"predis/predis": "~1.0",
"friendsofsymfony/rest-bundle": "^1.7",
"jms/serializer-bundle": "^1.0",
"doctrine/doctrine-fixtures-bundle": "^2.2"
"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",
"vlucas/phpdotenv": "^2.4",
"zendframework/zend-expressive": "^1.0",
"zendframework/zend-expressive-fastroute": "^1.0",
"zendframework/zend-servicemanager": "^3.2"
},
"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"
]
},
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
"behat/mink-selenium2-driver": "*",
"malukenho/docheader": "^0.1.5",
"phpspec/phpspec": "^2.5",
"phpunit/phpunit": "^5.6"
}
}
30 changes: 30 additions & 0 deletions config/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* 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.
*/

declare(strict_types=1);

use Conticket\Conference\Factory\CommandHandler\CreateConferenceHandlerFactory;
use Conticket\Conference\Domain\Command\CreateConference;

return (function () {
return [
'factories' => [
CreateConference::class => CreateConferenceHandlerFactory::class,
],
];
})();
14 changes: 14 additions & 0 deletions config/middlewares.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Conticket\Conference\Infrastructure\Middleware\CreateConferenceMiddleware;
use Conticket\Conference\Factory\Middleware\CreateConferenceMiddlewareFactory;

return (function () {
return [
'factories' => [
CreateConferenceMiddleware::class => CreateConferenceMiddlewareFactory::class,
],
];
})();
30 changes: 30 additions & 0 deletions config/repositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* 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.
*/

declare(strict_types=1);

use Conticket\Conference\Domain\Repository\ConferenceRepositoryInterface;
use Conticket\Conference\Factory\Repository\ConferenceRepositoryFactory;

return (function () {
return [
'factories' => [
ConferenceRepositoryInterface::class => ConferenceRepositoryFactory::class,
],
];
})();
16 changes: 16 additions & 0 deletions config/service-manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

// NOTE: Encapsulate in an IIFE to avoid future mistakes with
// variables in global space.
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'
)
);
})();
28 changes: 28 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

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\PDOFactory;
use Doctrine\DBAL\Connection;
use Prooph\EventStore\EventStore;
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 => InvokableFactory::class,
CommandBus::class => CommandBusFactory::class,
EventStore::class => EventStoreFactory::class,
Connection::class => ConnectionFactory::class,
\PDO::class => PDOFactory::class,
],
];
})();
7 changes: 6 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
backupGlobals="false"
>
<testsuite name="Conticket functional tests">
<directory suffix=".phpt">./tests/ConticketFunctionalTests</directory>
<directory suffix=".php">./tests</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
25 changes: 25 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Conticket\Conference\Infrastructure\Middleware\CreateConferenceMiddleware;

(function () {
require __DIR__ . '/../vendor/autoload.php';

(new \Dotenv\Dotenv(__DIR__ . '/..'))->load();

/* @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(CreateConferenceMiddleware::PATH, CreateConferenceMiddleware::class);

$app->pipeRoutingMiddleware();
$app->pipeDispatchMiddleware();
$app->raiseThrowables();
$app->run();
})();
30 changes: 30 additions & 0 deletions spec/Conticket/Model/Aggregates/Event/EventSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare(strict_types=1);

namespace spec\Conticket\Model\Aggregates\Event;

use Conticket\Model\Aggregates\Event\EventId;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Conticket\Model\Aggregates\Event\Event;

class EventSpec extends ObjectBehavior
{

public function let()
{
$this->beConstructedThrough('fromNameAndDescription', [
'Event specification by example',
'Description of event specified by example'
]);
}

public function it_is_initializable()
{
$this->shouldHaveType(Event::class);
}

public function it_should_return_event_id()
{
$this->aggregateId()->shouldReturnAnInstanceOf(EventId::class);
}
}
36 changes: 36 additions & 0 deletions spec/Conticket/Model/Aggregates/Event/TicketLifespanSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace spec\Conticket\Model\Aggregates\Event;

use Conticket\Model\Aggregates\Event\TicketLifespan;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Conticket\Model\Aggregates\Event\TicketEndDateMustBeGreaterThanStartDateException;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much space in here, remove one line

final class TicketLifespanSpec extends ObjectBehavior
{
public function it_is_initializable()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:void

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man, this Spec classes get broken when we set the return to :void

{
$this->shouldHaveType(TicketLifespan::class);
}

public function it_throws_an_exception_when_start_date_is_greater_than_end_date()
{
$this->shouldThrow(TicketEndDateMustBeGreaterThanStartDateException::class);
$this->beConstructedThrough('fromStartAndEnd', [
new \DateTimeImmutable('2016-01-01'),
new \DateTimeImmutable('2015-01-01'),
]);
}

public function it_should_return_immutable_datetime_objects_on_start_and_end_methods()
{
$this->beConstructedThrough('fromStartAndEnd', [
new \DateTimeImmutable('2016-01-01'),
new \DateTimeImmutable('2016-04-01'),
]);
$this->start()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
$this->end()->shouldReturnAnInstanceOf(\DateTimeImmutable::class);
}
}
Loading