Skip to content

Commit

Permalink
Merge pull request #51 from prooph/amphp
Browse files Browse the repository at this point in the history
Refactor to use amphp and event-store v8
  • Loading branch information
prolic committed Jun 9, 2020
2 parents 5b083e7 + cbe45af commit e99c964
Show file tree
Hide file tree
Showing 36 changed files with 869 additions and 2,143 deletions.
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
13 changes: 8 additions & 5 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 @@ -12,20 +13,22 @@

namespace Prooph\MicroExample\Infrastructure;

use Amp\Promise;
use Amp\Success;
use Prooph\MicroExample\Model\UniqueEmailGuard;

final class InMemoryEmailGuard implements UniqueEmailGuard
{
private $knownEmails = [];

public function isUnique(string $email): bool
public function isUnique(string $email): Promise
{
$isUnique = ! in_array($email, $this->knownEmails);
$isUnique = ! \in_array($email, $this->knownEmails);

if ($isUnique) {
$this->knownEmails[] = $email;
}

return $isUnique;
return new Success($isUnique);
}
}
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.

Loading

0 comments on commit e99c964

Please sign in to comment.