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

Refactor to use amphp and event-store v8 #51

Merged
merged 8 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ language: php
matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.4
env:
- DEPENDENCIES=""
- EXECUTE_CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.1
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- php: 7.2
env:
- DEPENDENCIES=""
- php: 7.2
- php: 7.4
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"

Expand All @@ -29,9 +23,10 @@ before_script:
- phpenv config-rm xdebug.ini
- composer self-update
- composer update --prefer-dist $DEPENDENCIES
- mkdir -p build/logs

script:
- if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml; else ./vendor/bin/phpunit; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/kahlan --coverage=4 --clover=./build/logs/clover.xml; else ./vendor/bin/kahlan; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/docheader check src/ tests/ examples/; fi

Expand Down
19 changes: 7 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,18 @@
"prooph"
],
"require": {
"php": "^7.1",
"prooph/event-store": "^7.3.1",
"prooph/pdo-event-store": "^1.6",
"prooph/snapshot-store": "^1.2",
"phunkie/phunkie": "0.10.1"
"php": "^7.4",
"amphp/amp": "^2.4.3",
"prooph/event-store": "dev-master",
"phunkie/phunkie": "0.11.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpspec/prophecy": "^1.7",
"prooph/php-cs-fixer-config": "^0.2.1",
"kahlan/kahlan": "^4.7.4",
"prooph/event-store-client": "dev-master",
"prooph/php-cs-fixer-config": "^0.3.1",
"php-coveralls/php-coveralls": "^2.1",
"malukenho/docheader": "^0.1.4"
},
"suggest": {
"prooph/pdo-snapshot-store": "For PDO as snapshot store",
"prooph/mongodb-snapshot-store": "For MongoDB as snapshot store"
},
"autoload": {
"psr-4": {
"Prooph\\Micro\\": "src/"
Expand Down
7 changes: 4 additions & 3 deletions examples/Infrastructure/InMemoryEmailGuard.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* This file is part of the prooph/micro.
* (c) 2017-2017 prooph software GmbH <[email protected]>
* (c) 2017-2017 Sascha-Oliver Prolic <[email protected]>
* (c) 2017-2020 prooph software GmbH <[email protected]>
* (c) 2017-2020 Sascha-Oliver Prolic <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -20,7 +21,7 @@ final class InMemoryEmailGuard implements UniqueEmailGuard

public function isUnique(string $email): bool
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this return Promise<bool> now?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

{
$isUnique = ! in_array($email, $this->knownEmails);
$isUnique = ! \in_array($email, $this->knownEmails);

if ($isUnique) {
$this->knownEmails[] = $email;
Expand Down
36 changes: 0 additions & 36 deletions examples/Infrastructure/UserAggregateDefinition.php

This file was deleted.

70 changes: 70 additions & 0 deletions examples/Infrastructure/UserSpecification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* This file is part of the prooph/micro.
* (c) 2017-2020 prooph software GmbH <[email protected]>
* (c) 2017-2020 Sascha-Oliver Prolic <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Prooph\MicroExample\Infrastructure;

use Phunkie\Types\ImmList;
use Prooph\EventStore\EventData;
use Prooph\EventStore\EventId;
use Prooph\EventStore\ResolvedEvent;
use Prooph\EventStore\Util\Json;
use Prooph\Micro\CommandSpecification;
use Prooph\MicroExample\Model\Event\UserNameChanged;
use Prooph\MicroExample\Model\Event\UserRegistered;
use Prooph\MicroExample\Model\Event\UserRegisteredWithDuplicateEmail;
use Prooph\MicroExample\Model\User;

final class UserSpecification extends CommandSpecification
{
public function mapToEventData(object $event): EventData
{
return new EventData(
EventId::generate(),
$event->messageName(),
true,
Json::encode($event->payload()),
Json::encode(['causation_name' => $this->command->messageName()])
);
}

public function mapToEvent(ResolvedEvent $resolvedEvent): object
{
switch ($resolvedEvent->originalEvent()->eventType()) {
case 'username-changed':
return new UserNameChanged(Json::decode($resolvedEvent->originalEvent()->data()));
case 'user-registered':
return new UserRegistered(Json::decode($resolvedEvent->originalEvent()->data()));
case 'user-registered-with-duplicate-email':
return new UserRegisteredWithDuplicateEmail(Json::decode($resolvedEvent->originalEvent()->data()));
default:
throw new \UnexpectedValueException(
'Unknown event type ' . $resolvedEvent->originalEvent()->eventType() . ' returned'
);
}
}

public function initialState()
{
return [];
}

public function streamName(): string
{
return 'user-' . $this->command->payload()['id'];
}

public function apply($state, ImmList $events)
{
return User\apply($state, $events);
}
}
61 changes: 0 additions & 61 deletions examples/Infrastructure/factories.php

This file was deleted.

32 changes: 22 additions & 10 deletions examples/Model/Command/ChangeUserName.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* This file is part of the prooph/micro.
* (c) 2017-2017 prooph software GmbH <[email protected]>
* (c) 2017-2017 Sascha-Oliver Prolic <[email protected]>
* (c) 2017-2020 prooph software GmbH <[email protected]>
* (c) 2017-2020 Sascha-Oliver Prolic <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,20 +13,31 @@

namespace Prooph\MicroExample\Model\Command;

use Prooph\Common\Messaging\Command;
use Prooph\Common\Messaging\PayloadConstructable;
use Prooph\Common\Messaging\PayloadTrait;

final class ChangeUserName extends Command implements PayloadConstructable
final class ChangeUserName
{
use PayloadTrait;
protected array $payload;

public function __construct(array $payload = [])
{
$this->payload = $payload;
}

public function messageName(): string
{
return 'change-username';
}

public function payload(): array
{
return $this->payload;
}

public function userId(): string
public function id(): string
{
return $this->payload()['id'];
}

public function username(): string
public function name(): string
{
return $this->payload()['name'];
}
Expand Down
28 changes: 0 additions & 28 deletions examples/Model/Command/InvalidCommand.php

This file was deleted.

32 changes: 22 additions & 10 deletions examples/Model/Command/RegisterUser.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* This file is part of the prooph/micro.
* (c) 2017-2017 prooph software GmbH <[email protected]>
* (c) 2017-2017 Sascha-Oliver Prolic <[email protected]>
* (c) 2017-2020 prooph software GmbH <[email protected]>
* (c) 2017-2020 Sascha-Oliver Prolic <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,20 +13,31 @@

namespace Prooph\MicroExample\Model\Command;

use Prooph\Common\Messaging\Command;
use Prooph\Common\Messaging\PayloadConstructable;
use Prooph\Common\Messaging\PayloadTrait;

final class RegisterUser extends Command implements PayloadConstructable
final class RegisterUser
{
use PayloadTrait;
protected array $payload;

public function __construct(array $payload = [])
{
$this->payload = $payload;
}

public function messageName(): string
{
return 'register-user';
}

public function payload(): array
{
return $this->payload;
}

public function userId(): string
public function id(): string
{
return $this->payload()['id'];
}

public function userName(): string
public function name(): string
{
return $this->payload()['name'];
}
Expand Down
Loading