Skip to content

Commit

Permalink
introduced event sourced aggregates & entities
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbem committed May 8, 2022
1 parent 6281b92 commit 4c7c7ba
Show file tree
Hide file tree
Showing 135 changed files with 2,204 additions and 1,886 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
52 changes: 41 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ jobs:
uses: actions/checkout@v2
- name: Docker pull
run: docker-compose pull php
- name: Docker caching
uses: satackey/[email protected]
continue-on-error: true
- name: Start PHP container
run: docker-compose up --detach --build --no-deps php
- name: Run composer validate
run: docker-compose run --rm --no-deps php composer validate --strict --no-interaction --ansi
run: docker-compose exec -T php composer validate --strict --no-interaction --ansi
run-php-cs-fixer:
name: php-cs-fixer
runs-on: ubuntu-latest
Expand All @@ -19,16 +24,21 @@ jobs:
uses: actions/checkout@v2
- name: Docker pull
run: docker-compose pull php
- name: Docker caching
uses: satackey/[email protected]
continue-on-error: true
- name: Composer caching
uses: actions/cache@v2
with:
path: ./build/.composer
key: ${{ runner.os }}-composer-v1-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-v1-
- name: Start PHP container
run: docker-compose up --detach --build --no-deps php
- name: Install dependencies
run: docker-compose run --rm --no-deps php composer --no-scripts install --no-interaction --ansi
run: docker-compose exec -T php composer --no-scripts install --no-interaction --ansi
- name: Run php-cs-fixer
run: docker-compose run --rm --no-deps php bin/php-cs-fixer fix --diff --dry-run --ansi --config=.php-cs-fixer.dist.php
run: docker-compose exec -T php bin/php-cs-fixer fix --diff --dry-run --ansi --config=.php-cs-fixer.dist.php
run-phpunit:
name: phpunit
runs-on: ubuntu-latest
Expand All @@ -37,22 +47,32 @@ jobs:
uses: actions/checkout@v2
- name: Docker pull
run: docker-compose pull
- name: Docker caching
uses: satackey/[email protected]
continue-on-error: true
- name: Composer caching
uses: actions/cache@v2
with:
path: ./build/.composer
key: ${{ runner.os }}-composer-v1-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-v1-
- name: Start containers
run: docker-compose up --detach --build
- name: Install dependencies
run: docker-compose run --rm php composer install --no-scripts --no-interaction --ansi
run: docker-compose exec -T php composer install --no-scripts --no-interaction --ansi
- name: Run phpunit
run: docker-compose run --rm php xphp bin/phpunit --color=always --configuration=phpunit.xml.dist
- name: Upload coverage report to codecov.io
uses: codecov/codecov-action@v1
run: docker-compose exec -T php xphp -dxdebug.mode=coverage bin/phpunit --color=always --configuration=phpunit.xml.dist
- name: Upload coverage report to Codecov.io
uses: codecov/codecov-action@v2
with:
files: ./build/.phpunit/clover.xml
fail_ci_if_error: true
verbose: true
# - name: Upload coverage report to GitHub.com
# uses: actions/upload-artifact@v2
# with:
# name: Code Coverage Report
# path: build/.phpunit/code-coverage/*
run-rector:
name: rector
runs-on: ubuntu-latest
Expand All @@ -61,16 +81,21 @@ jobs:
uses: actions/checkout@v2
- name: Docker pull
run: docker-compose pull php
- name: Docker caching
uses: satackey/[email protected]
continue-on-error: true
- name: Composer caching
uses: actions/cache@v2
with:
path: ./build/.composer
key: ${{ runner.os }}-composer-v1-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-v1-
- name: Start PHP container
run: docker-compose up --detach --build --no-deps php
- name: Install dependencies
run: docker-compose run --rm --no-deps php composer install --no-interaction --ansi
run: docker-compose exec -T php composer install --no-interaction --ansi
- name: Run rector
run: docker-compose run --rm --no-deps php bin/rector --no-progress-bar --dry-run --ansi
run: docker-compose exec -T php bin/rector --no-progress-bar --dry-run --ansi
run-deptrac:
name: deptrac
runs-on: ubuntu-latest
Expand All @@ -79,13 +104,18 @@ jobs:
uses: actions/checkout@v2
- name: Docker pull
run: docker-compose pull php
- name: Docker caching
uses: satackey/[email protected]
continue-on-error: true
- name: Composer caching
uses: actions/cache@v2
with:
path: ./build/.composer
key: ${{ runner.os }}-composer-v1-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-v1-
- name: Start PHP container
run: docker-compose up --detach --build --no-deps php
- name: Install dependencies
run: docker-compose run --rm --no-deps php composer install --no-scripts --no-interaction --ansi
run: docker-compose exec -T php composer install --no-scripts --no-interaction --ansi
- name: Run deptrac
run: docker-compose run --rm --no-deps php bin/deptrac --no-progress --no-interaction --cache-file=./build/.deptrac/.deptrac.cache --ansi
run: docker-compose exec -T php bin/deptrac --no-progress --no-interaction --cache-file=./build/.deptrac/.deptrac.cache --ansi
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$config = new PhpCsFixer\Config();
$finder = PhpCsFixer\Finder::create();
$finder
// The vendor directory is excluded by default.
->exclude('.github')
->exclude('bin')
->exclude('build')
Expand Down Expand Up @@ -30,6 +31,7 @@
'php_unit_dedicate_assert_internal_type' => true,
'php_unit_mock' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'no_extra_blank_lines' => true,
'header_comment' => [
'comment_type' => 'PHPDoc',
'location' => 'after_open',
Expand All @@ -46,7 +48,6 @@
],
]
)
//The vendor directory is excluded by default.
->setFinder($finder)
;

Expand Down
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
Streak
------
![Streak](docs/images/logo.png)

-------------------------------

[![CI](https://github.com/streakphp/streak/actions/workflows/ci.yaml/badge.svg)](https://github.com/streakphp/streak/actions/workflows/ci.yaml)
[![codecov](https://codecov.io/gh/streakphp/streak/branch/master/graph/badge.svg)](https://codecov.io/gh/streakphp/streak)

Running test
------------
Running checks & tests locally
------------------------------

`docker-compose up --detach --build`

`docker-compose exec -T php composer validate --strict --no-interaction --ansi`

`docker-compose exec -T php composer install --no-scripts --no-interaction --ansi`

`docker-compose exec -T php xphp -dxdebug.mode=coverage bin/phpunit --color=always --configuration=phpunit.xml.dist`

`docker-compose run -T php bin/phpunit`

`docker-compose exec -T php bin/rector --dry-run --ansi`

`docker-compose exec -T php bin/deptrac --no-interaction --cache-file=./build/.deptrac/.deptrac.cache --ansi`

`docker-compose run --rm php bin/phpunit`
`docker-compose exec -T php bin/php-cs-fixer fix --diff --dry-run --ansi --config=.php-cs-fixer.dist.php`
22 changes: 21 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
codecov:
branch: master
max_report_age: 24
require_ci_to_pass: yes

comment:
layout: "reach, diff, flags, files"
behavior: new
require_changes: false
require_base: true
require_head: true

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: yes
macro: yes

coverage:
precision: 2
round: down
range: "70...100"
range: "90...100"

status:
project:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"friendsofphp/php-cs-fixer": "^3.0",
"php-amqplib/rabbitmq-bundle": "^2.6.0",
"phpunit/phpunit": "^9.5.4",
"rector/rector": "^0.10.19",
"rector/rector": "0.12.18",
"qossmic/deptrac-shim": "^0.13.0"
},
"config": {
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
version: '3'
version: '3.7'
services:

php:
image: streakphp/php80-cli:latest
init: true
volumes:
- .:/var/www/project
- ./docker/php/etc/php/8.0/cli/php.ini:/etc/php/8.0/cli/php.ini
working_dir: /var/www/project
entrypoint: tail -f /dev/null # keep container alive for development
depends_on:
- postgres
- redis
environment:
COMPOSER_ALLOW_SUPERUSER: 1
COMPOSER_NO_INTERACTION: 1
COMPOSER_CACHE_DIR: /var/www/project/build/.composer
XDEBUG_MODE: 'develop,debug,coverage'

postgres:
image: postgres:13-alpine
Expand Down
Binary file added docs/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
colors="true"
cacheResultFile="build/.phpunit/.phpunit.result.cache"
bootstrap="tests/bootstrap.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/.phpunit/clover.xml"/>
<!-- <html outputDirectory="build/.phpunit/code-coverage" lowUpperBound="35" highLowerBound="70"/>-->
<!-- <html outputDirectory="build/.phpunit/code-coverage" lowUpperBound="60" highLowerBound="90"/>-->
<text outputFile="php://stdout" showUncoveredFiles="true"/>
</report>
</coverage>
Expand Down
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
]);

// Run Rector only on changed files
$parameters->set(Option::ENABLE_CACHE, true);
$parameters->set(Option::CACHE_DIR, __DIR__ . '/build/.rector');

$services = $configurator->services();
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Sensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
interface Sensor extends Producer
{
public function sensorId(): Sensor\Id;
public function id(): Sensor\Id;

public function process(...$messages): void;
}
4 changes: 2 additions & 2 deletions src/Application/Sensor/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Streak\Application\Sensor;

use Streak\Domain\Event\Producer;
use Streak\Domain;

/**
* @author Alan Gabriel Bem <[email protected]>
*/
interface Id extends Producer\Id
interface Id extends Domain\Id
{
}
13 changes: 1 addition & 12 deletions src/Application/Sensor/Identification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Streak\Application\Sensor;

use Streak\Application\Sensor;
use Streak\Domain;

/**
* @author Alan Gabriel Bem <[email protected]>
Expand All @@ -28,21 +27,11 @@ public function __construct(Sensor\Id $id)
$this->identifyBy($id);
}

public function sensorId(): Sensor\Id
public function id(): Sensor\Id
{
return $this->id;
}

public function producerId(): Domain\Id
{
return $this->sensorId();
}

public function id(): Domain\Id
{
return $this->sensorId();
}

protected function identifyBy(Sensor\Id $id): void
{
$this->id = $id;
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Sensor/Processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Streak\Application\Sensor;

use Streak\Application\Sensor;
use Streak\Domain\Event;
use Streak\Domain\Id;

/**
* @author Alan Gabriel Bem <[email protected]>
Expand All @@ -27,7 +27,7 @@ trait Processing
private $events = [];
private $last;

abstract public function producerId(): Id;
abstract public function id(): Sensor\Id;

final public function last(): ?Event\Envelope
{
Expand Down Expand Up @@ -140,7 +140,7 @@ final public function process(...$messages): void
}

if (false === $routed) {
throw new \InvalidArgumentException();
throw new \InvalidArgumentException('No method found to process message.');
}
}
} catch (\Throwable $e) {
Expand All @@ -156,6 +156,6 @@ final public function process(...$messages): void

private function addEvent(Event $event): void
{
$this->pending[] = Event\Envelope::new($event, $this->producerId());
$this->pending[] = Event\Envelope::new($event, $this->id());
}
}
2 changes: 1 addition & 1 deletion src/Domain/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
*/
interface Aggregate extends Domain\Entity
{
public function aggregateId(): Domain\Aggregate\Id;
public function id(): Domain\Aggregate\Id;
}
6 changes: 4 additions & 2 deletions src/Domain/Aggregate/Comparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

/**
* @author Alan Gabriel Bem <[email protected]>
*
* @see \Streak\Domain\Aggregate\ComparisonTest
*/
trait Comparison
{
use Entity\Comparison;

abstract public function aggregateId(): Aggregate\Id;
abstract public function id(): Aggregate\Id;

final public function equals(object $aggregate): bool
{
Expand All @@ -36,7 +38,7 @@ final public function equals(object $aggregate): bool
return false;
}

if (!$this->aggregateId()->equals($aggregate->aggregateId())) {
if (!$this->id()->equals($aggregate->id())) {
return false;
}

Expand Down
Loading

0 comments on commit 4c7c7ba

Please sign in to comment.