Skip to content

Commit

Permalink
Fix integration with the framework
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed May 7, 2024
1 parent 12b822a commit ad847fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Console/src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function () use ($method) {

return $core instanceof HandlerInterface
? (int)$core->handle(new CallContext(
Target::fromReflectionMethod(new \ReflectionMethod(static::class, $method)),
Target::fromPair($this, $method),
$arguments,
))
: (int)$core->callAction(static::class, $method, $arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/Events/src/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function dispatch(object $event): object
return $this->isLegacy
? $this->core->callAction($event::class, 'dispatch', ['event' => $event])
: $this->core->handle(new CallContext(
Target::fromReflectionMethod(new \ReflectionMethod($event::class, 'dispatch')),
Target::fromPair($event, 'dispatch'),
['event' => $event],
));
}
Expand Down
13 changes: 13 additions & 0 deletions src/Hmvc/tests/Interceptors/Unit/Context/TargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,25 @@ public function testCreateFromPair(string $controller, string $action, bool $has
self::assertSame([$controller, $action], $target->getPath());
$reflection = $target->getReflection();
self::assertSame($hasReflection, $reflection !== null);
self::assertNull($target->getObject());
if ($hasReflection) {
self::assertInstanceOf(\ReflectionMethod::class, $reflection);
self::assertSame($action, $reflection->getName());
}
}

public function testCreateFromObject(): void
{
$service = new TestService();
$target = Target::fromPair($service, 'parentMethod');

self::assertSame([TestService::class, 'parentMethod'], $target->getPath());
$reflection = $target->getReflection();
self::assertInstanceOf(\ReflectionMethod::class, $reflection);
self::assertSame('parentMethod', $reflection->getName());
self::assertSame($service, $target->getObject());
}

public function testCreateFromPathStringDefaultSeparator(): void
{
$str = 'foo.bar.baz';
Expand Down

0 comments on commit ad847fd

Please sign in to comment.