Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ parameters:
path: tests/Unit/Message/Translator/ReplaceEventTranslatorTest.php

-
message: '#^Method class@anonymous/tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest\.php\:212\:\:profileVisited\(\) has parameter \$message with no type specified\.$#'
message: '#^Method class@anonymous/tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest\.php\:211\:\:profileVisited\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/Unit/Metadata/Subscriber/AttributeSubscriberMetadataFactoryTest.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function metadata(string $subscriber): SubscriberMetadata
throw DuplicateSubscribeMethod::duplicateEvent(
$subscriber,
$eventClass,
$subscribeMethods[$eventClass][0]->name,
$subscribeMethods[$eventClass]->name,
$method->getName(),
);
}

$subscribeMethods[$eventClass][] = $this->subscribeMethod($method);
$subscribeMethods[$eventClass] = $this->subscribeMethod($method);
}

if ($method->getAttributes(OnFailed::class)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Subscriber/SubscriberMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
public readonly string $id,
public readonly string $group = Subscription::DEFAULT_GROUP,
public readonly RunMode $runMode = RunMode::FromBeginning,
/** @var array<class-string|"*", list<SubscribeMethodMetadata>> */
/** @var array<class-string|"*", SubscribeMethodMetadata> */
public readonly array $subscribeMethods = [],
public readonly string|null $setupMethod = null,
public readonly string|null $teardownMethod = null,
Expand Down
14 changes: 9 additions & 5 deletions src/Subscription/Subscriber/MetadataSubscriberAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_merge;

/** @template T of object */
final class MetadataSubscriberAccessor implements SubscriberAccessor, RealSubscriberAccessor
Expand Down Expand Up @@ -115,10 +114,15 @@ public function subscribeMethods(string $eventClass): array
return $this->subscribeCache[$eventClass];
}

$methods = array_merge(
$this->metadata->subscribeMethods[$eventClass] ?? [],
$this->metadata->subscribeMethods[Subscribe::ALL] ?? [],
);
$methods = [];

if (array_key_exists($eventClass, $this->metadata->subscribeMethods)) {
$methods[] = $this->metadata->subscribeMethods[$eventClass];
}

if (array_key_exists(Subscribe::ALL, $this->metadata->subscribeMethods)) {
$methods[] = $this->metadata->subscribeMethods[Subscribe::ALL];
}

$this->subscribeCache[$eventClass] = array_map(
fn (SubscribeMethodMetadata $method): Closure => $this->createClosure($eventClass, $method),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ public function drop(): void

self::assertEquals(
[
ProfileVisited::class => [
new SubscribeMethodMetadata('handle', []),
],
ProfileVisited::class => new SubscribeMethodMetadata('handle', []),
],
$metadata->subscribeMethods,
);
Expand All @@ -141,8 +139,8 @@ public function handle(): void

self::assertEquals(
[
ProfileVisited::class => [new SubscribeMethodMetadata('handle', [])],
ProfileCreated::class => [new SubscribeMethodMetadata('handle', [])],
ProfileVisited::class => new SubscribeMethodMetadata('handle', []),
ProfileCreated::class => new SubscribeMethodMetadata('handle', []),
],
$metadata->subscribeMethods,
);
Expand All @@ -163,7 +161,7 @@ public function handle(): void

self::assertEquals(
[
'*' => [new SubscribeMethodMetadata('handle', [])],
'*' => new SubscribeMethodMetadata('handle', []),
],
$metadata->subscribeMethods,
);
Expand All @@ -189,17 +187,18 @@ public function profileCreated(ProfileCreated $profileCreated, string $aggregate

self::assertEquals(
[
ProfileVisited::class => [
new SubscribeMethodMetadata('profileVisited', [
new ArgumentMetadata('message', Message::class),
]),
],
ProfileCreated::class => [
new SubscribeMethodMetadata('profileCreated', [
ProfileVisited::class => new SubscribeMethodMetadata(
'profileVisited',
[new ArgumentMetadata('message', Message::class)],
),

ProfileCreated::class => new SubscribeMethodMetadata(
'profileCreated',
[
new ArgumentMetadata('profileCreated', ProfileCreated::class),
new ArgumentMetadata('aggregateId', 'string'),
]),
],
],
),
],
$metadata->subscribeMethods,
);
Expand Down
Loading