-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35d6f69
commit 1b7f34b
Showing
12 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/Unit/CommandBus/Handler/DefaultHandlerFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\CommandBus\Handler; | ||
|
||
use Patchlevel\EventSourcing\CommandBus\Handler\CreateAggregateHandler; | ||
use Patchlevel\EventSourcing\CommandBus\Handler\DefaultHandlerFactory; | ||
use Patchlevel\EventSourcing\CommandBus\Handler\UpdateAggregateHandler; | ||
use Patchlevel\EventSourcing\Repository\RepositoryManager; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @covers \Patchlevel\EventSourcing\CommandBus\Handler\DefaultHandlerFactory */ | ||
final class DefaultHandlerFactoryTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testCreateHandler(): void | ||
{ | ||
$repositoryManager = $this->prophesize(RepositoryManager::class); | ||
$container = $this->prophesize(ContainerInterface::class); | ||
|
||
$handlerFactory = new DefaultHandlerFactory( | ||
$repositoryManager->reveal(), | ||
$container->reveal(), | ||
); | ||
|
||
$handler = $handlerFactory->createHandler( | ||
'aggregateClass', | ||
'method', | ||
); | ||
|
||
$this->assertInstanceOf(CreateAggregateHandler::class, $handler); | ||
} | ||
|
||
public function testUpdateHandler(): void | ||
{ | ||
$repositoryManager = $this->prophesize(RepositoryManager::class); | ||
$container = $this->prophesize(ContainerInterface::class); | ||
|
||
$handlerFactory = new DefaultHandlerFactory( | ||
$repositoryManager->reveal(), | ||
$container->reveal(), | ||
); | ||
|
||
$handler = $handlerFactory->updateHandler( | ||
'aggregateClass', | ||
'method', | ||
); | ||
|
||
$this->assertInstanceOf(UpdateAggregateHandler::class, $handler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\CommandBus; | ||
|
||
use Patchlevel\EventSourcing\CommandBus\HandlerDescriptor; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithHandlers; | ||
use PHPUnit\Framework\Attributes\RequiresPhp; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\CommandBus\HandlerDescriptor */ | ||
final class HandlerDescriptorTest extends TestCase | ||
{ | ||
public function testObjectMethod(): void | ||
{ | ||
$aggregate = ProfileWithHandlers::createEmpty(); | ||
|
||
$descriptor = new HandlerDescriptor($aggregate->changeName(...)); | ||
|
||
self::assertEquals($aggregate->changeName(...), $descriptor->callable()); | ||
self::assertEquals('Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithHandlers::changeName', $descriptor->name()); | ||
} | ||
|
||
public function testStaticObjectMethod(): void | ||
{ | ||
$descriptor = new HandlerDescriptor([ProfileWithHandlers::class, 'create']); | ||
|
||
self::assertEquals(ProfileWithHandlers::create(...), $descriptor->callable()); | ||
self::assertEquals('Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithHandlers::create', $descriptor->name()); | ||
} | ||
|
||
#[RequiresPhp('>= 8.2')] | ||
public function testAnonymousFunction(): void | ||
{ | ||
$handler = static function (): void { | ||
}; | ||
|
||
$descriptor = new HandlerDescriptor($handler(...)); | ||
|
||
self::assertEquals($handler(...), $descriptor->callable()); | ||
self::assertEquals('Closure', $descriptor->name()); | ||
} | ||
|
||
public function testAnonymousClass(): void | ||
{ | ||
$handler = new class { | ||
public function __invoke(): void | ||
{ | ||
} | ||
}; | ||
|
||
$descriptor = new HandlerDescriptor($handler->__invoke(...)); | ||
|
||
self::assertEquals($handler->__invoke(...), $descriptor->callable()); | ||
self::assertStringContainsString('class@anonymous', $descriptor->name()); | ||
self::assertStringContainsString(__FILE__, $descriptor->name()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters