Skip to content

Commit

Permalink
Fix tests after composer update and cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
codeliner committed Nov 9, 2018
1 parent c0f109b commit 52cacfd
Show file tree
Hide file tree
Showing 86 changed files with 498 additions and 402 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"bookdown/bookdown": "1.x-dev",
"webuni/commonmark-table-extension": "^0.6.1",
"webuni/commonmark-attributes-extension": "^0.5.0",
"prooph/php-cs-fixer-config": "^0.1.1",
"prooph/php-cs-fixer-config": "^0.2",
"satooshi/php-coveralls": "^1.0",
"malukenho/docheader": "^0.1.4"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/CustomMessages/Aggregate/UserDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace ProophExample\CustomMessages\Aggregate;

use Prooph\Common\Messaging\Message;
use Prooph\EventMachine\EventMachine;
use Prooph\EventMachine\EventMachineDescription;
use ProophExample\CustomMessages\Api\Command;
Expand Down Expand Up @@ -60,12 +59,12 @@ private static function describeRegisterUser(EventMachine $eventMachine): void
// Note: Our custom command is passed to the function
->handle(function (RegisterUser $registerUser) {
//We can return a custom event
yield new UserRegistered((array)$registerUser);
yield new UserRegistered((array) $registerUser);
})
->recordThat(Event::USER_WAS_REGISTERED)
// The custom event is passed to the apply function
->apply(function (UserRegistered $event) {
return new UserState((array)$event);
return new UserState((array) $event);
});
}

Expand All @@ -85,6 +84,7 @@ private static function describeChangeUsername(EventMachine $eventMachine): void
// Same here, UsernameChanged is NOT the first event, so current user state is passed
->apply(function (UserState $user, UsernameChanged $event) {
$user->username = $event->newName;

return $user;
});
}
Expand Down
5 changes: 3 additions & 2 deletions examples/CustomMessages/Api/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public static function createFromNameAndPayload(string $commandName, array $payl

public static function nameOf($command): string
{
$map = array_flip(self::CLASS_MAP);
return $map[get_class($command)];
$map = \array_flip(self::CLASS_MAP);

return $map[\get_class($command)];
}

private function __construct()
Expand Down
5 changes: 3 additions & 2 deletions examples/CustomMessages/Api/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public static function createFromNameAndPayload(string $commandName, array $payl

public static function nameOf($event): string
{
$map = array_flip(self::CLASS_MAP);
return $map[get_class($event)];
$map = \array_flip(self::CLASS_MAP);

return $map[\get_class($event)];
}

private function __construct()
Expand Down
8 changes: 8 additions & 0 deletions examples/CustomMessages/Command/ChangeUsername.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php
/**
* This file is part of the proophsoftware/event-machine.
* (c) 2017-2018 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ProophExample\CustomMessages\Command;
Expand Down
8 changes: 8 additions & 0 deletions examples/CustomMessages/Event/UsernameChanged.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php
/**
* This file is part of the proophsoftware/event-machine.
* (c) 2017-2018 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ProophExample\CustomMessages\Event;
Expand Down
14 changes: 7 additions & 7 deletions examples/CustomMessages/ExampleCustomMessagePort.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class ExampleCustomMessagePort implements Port
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public function deserialize(Message $message)
{
Expand All @@ -35,17 +35,17 @@ public function deserialize(Message $message)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function serializePayload($customMessage): array
{
//Since, we use objects with public properties as custom messages, casting to array is enough
//In a production setting, you should use your own immutable messages and a serializer
return (array)$customMessage;
return (array) $customMessage;
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function decorateEvent($customEvent): MessageBag
{
Expand All @@ -57,7 +57,7 @@ public function decorateEvent($customEvent): MessageBag
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function getAggregateIdFromCustomCommand(string $aggregateIdPayloadKey, $customCommand): string
{
Expand All @@ -66,7 +66,7 @@ public function getAggregateIdFromCustomCommand(string $aggregateIdPayloadKey, $
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function callCustomCommandPreProcessor($customCommand, $preProcessor)
{
Expand All @@ -75,7 +75,7 @@ public function callCustomCommandPreProcessor($customCommand, $preProcessor)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function callCustomContextProvider($customCommand, $contextProvider)
{
Expand Down
8 changes: 8 additions & 0 deletions examples/CustomMessages/Util/ApplyPayload.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php
/**
* This file is part of the proophsoftware/event-machine.
* (c) 2017-2018 prooph software GmbH <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ProophExample\CustomMessages\Util;
Expand Down
11 changes: 6 additions & 5 deletions examples/OOPStyle/Aggregate/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function register(RegisterUser $command): self
$self->recordThat(new UserRegistered([
'userId' => $command->userId,
'username' => $command->username,
'email' => $command->email
'email' => $command->email,
]));

return $self;
Expand All @@ -57,20 +57,21 @@ public function changeName(ChangeUsername $command): void
$this->recordThat(new UsernameChanged([
'userId' => $this->userId,
'oldName' => $this->username,
'newName' => $command->username
'newName' => $command->username,
]));
}

public function popRecordedEvents(): array
{
$events = $this->recordedEvents;
$this->recordedEvents = [];

return $events;
}

public function apply($event): void
{
switch (get_class($event)) {
switch (\get_class($event)) {
case UserRegistered::class:
/** @var UserRegistered $event */
$this->userId = $event->userId;
Expand All @@ -82,13 +83,13 @@ public function apply($event): void
$this->username = $event->newName;
break;
default:
throw new RuntimeException("Unknown event: " . get_class($event));
throw new RuntimeException('Unknown event: ' . \get_class($event));
}
}

public function toArray(): array
{
return (array)$this;
return (array) $this;
}

private function recordThat($event): void
Expand Down
16 changes: 8 additions & 8 deletions examples/OOPStyle/ExampleOOPPort.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ final class ExampleOOPPort implements Port
use DetermineVariableType;

/**
* @inheritdoc
* {@inheritdoc}
*/
public function callAggregateFactory(string $aggregateType, callable $aggregateFactory, $customCommand, $context = null)
{
return $aggregateFactory($customCommand, $context);
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function callAggregateWithCommand($aggregate, $customCommand, $context = null): void
{
switch (get_class($customCommand)) {
switch (\get_class($customCommand)) {
case ChangeUsername::class:
/** @var User $aggregate */
$aggregate->changeName($customCommand);
break;
default:
throw new InvalidArgumentException("Unknown command: " . self::getType($customCommand));
throw new InvalidArgumentException('Unknown command: ' . self::getType($customCommand));
}
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function popRecordedEvents($aggregate): array
{
Expand All @@ -54,7 +54,7 @@ public function popRecordedEvents($aggregate): array
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function applyEvent($aggregate, $customEvent): void
{
Expand All @@ -63,7 +63,7 @@ public function applyEvent($aggregate, $customEvent): void
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function serializeAggregate($aggregate): array
{
Expand All @@ -72,7 +72,7 @@ public function serializeAggregate($aggregate): array
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function reconstituteAggregate(string $aggregateType, iterable $events)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/Standard/Aggregate/CachableUserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class CachableUserFunction
{
public static function registerUser(Message $registerUser)
{
if (! array_key_exists('shouldFail', $registerUser->payload()) || ! $registerUser->payload()['shouldFail']) {
if (! \array_key_exists('shouldFail', $registerUser->payload()) || ! $registerUser->payload()['shouldFail']) {
//We just turn the command payload into event payload by yielding it
yield [Event::USER_WAS_REGISTERED, $registerUser->payload()];
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/Aggregate/AggregateTestHistoryEventEnricher.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function enrichHistory(array $history, array $aggregateDefinitions
$arId = $event->payload()[$aggregateDefinition['aggregateIdentifier']] ?? null;

if (! $arId) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Event with name %s does not contain an aggregate identifier. Expected key was %s',
$event->messageName(),
$aggregateDefinition['aggregateIdentifier']
Expand All @@ -44,7 +44,7 @@ public static function enrichHistory(array $history, array $aggregateDefinitions

$aggregateMap[$aggregateDefinition['aggregateType']][$arId][] = $event;

$event = $event->withAddedMetadata('_aggregate_version', count($aggregateMap[$aggregateDefinition['aggregateType']][$arId]));
$event = $event->withAddedMetadata('_aggregate_version', \count($aggregateMap[$aggregateDefinition['aggregateType']][$arId]));

$enrichedHistory[] = $event;
}
Expand All @@ -55,7 +55,7 @@ public static function enrichHistory(array $history, array $aggregateDefinitions
private static function getAggregateDescriptionByEvent(string $eventName, array $aggregateDescriptions): ?array
{
foreach ($aggregateDescriptions as $description) {
if (array_key_exists($eventName, $description['eventApplyMap'])) {
if (\array_key_exists($eventName, $description['eventApplyMap'])) {
return $description;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregate/ClosureAggregateTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function extractPendingStreamEvents($anEventSourcedAggregateRoot): array
$callInterceptor = $this->callInterceptor;

$this->pendingEventsExtractor = function () use ($callInterceptor): array {
return array_map(function (Message $event) use ($callInterceptor) {
return \array_map(function (Message $event) use ($callInterceptor) {
return $callInterceptor->prepareNetworkTransmission($event);
}, $this->popRecordedEvents());
};
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregate/Exception/AggregateNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AggregateNotFound extends \RuntimeException
{
public static function with(string $aggregateType, string $aggregateId): self
{
return new self(sprintf(
return new self(\sprintf(
'Aggregate of type %s with id %s not found.',
$aggregateType,
$aggregateId
Expand Down
5 changes: 2 additions & 3 deletions src/Aggregate/GenericAggregateRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ protected static function reconstituteFromHistory(
array $eventApplyMap,
CallInterceptor $callInterceptor,
\Iterator $historyEvents
): self
{
): self {
$instance = new self($aggregateId, $aggregateType, $eventApplyMap, $callInterceptor);
$instance->replay($historyEvents);

Expand All @@ -92,7 +91,7 @@ public function __construct(string $aggregateId, AggregateType $aggregateType,
*/
public function recordThat(Message $event): void
{
if (! array_key_exists($event->messageName(), $this->eventApplyMap)) {
if (! \array_key_exists($event->messageName(), $this->eventApplyMap)) {
throw new \RuntimeException('Wrong event recording detected. Unknown event passed to GenericAggregateRoot: ' . $event->messageName());
}

Expand Down
Loading

0 comments on commit 52cacfd

Please sign in to comment.