Skip to content

Commit 79d9826

Browse files
authored
Merge pull request #30 from driftphp/feature/add-static-bus-creation-methods
Buses are now built inside static methods
2 parents b7cb37d + f006263 commit 79d9826

8 files changed

Lines changed: 186 additions & 3 deletions

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"Drift\\CommandBus\\Tests\\Bus\\QueryHandlerTest::testQueryBus":4,"Drift\\CommandBus\\Tests\\Bus\\QueryHandlerTest::testBusesInjection":5,"Drift\\CommandBus\\Tests\\Bus\\CommandHandlerTest::testBusesInjection":4,"Drift\\CommandBus\\Tests\\Bus\\AsyncCommandHandlerTest::testQueryBus":4},"times":{"Drift\\CommandBus\\Tests\\Bus\\DiscriminableBusTest::testQueryBus":0.003,"Drift\\CommandBus\\Tests\\Bus\\QueryHandlerTest::testQueryBus":0.002,"Drift\\CommandBus\\Tests\\Bus\\QueryHandlerTest::testBadCommand":0,"Drift\\CommandBus\\Tests\\Bus\\QueryHandlerTest::testBusesInjection":0,"Drift\\CommandBus\\Tests\\Bus\\CommandHandlerTest::testQueryBus":0.002,"Drift\\CommandBus\\Tests\\Bus\\CommandHandlerTest::testBusesInjection":0.001,"Drift\\CommandBus\\Tests\\Bus\\AsyncCommandHandlerTest::testQueryBus":0,"Drift\\CommandBus\\Tests\\Bus\\AsyncCommandHandlerTest::testBusesInjection":0.002}}

Tests/Async/RedisAsyncTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
namespace Drift\CommandBus\Tests\Async;
1717

1818
/**
19-
* Class RedisAsyncAdapterTest.
19+
* Class RedisAsyncTest.
2020
*/
21-
class RedisAsyncAdapterTest extends AsyncAdapterTest
21+
class RedisAsyncTest extends AsyncAdapterTest
2222
{
2323
/**
2424
* {@inheritdoc}

Tests/AsyncService.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the DriftPHP Project
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Drift\CommandBus\Tests;
17+
18+
use Drift\CommandBus\Bus\AsyncCommandBus;
19+
use Drift\CommandBus\Bus\CommandBus;
20+
use Drift\CommandBus\Bus\InlineCommandBus;
21+
use Drift\CommandBus\Bus\QueryBus;
22+
23+
/**
24+
* Class AsyncService.
25+
*/
26+
class AsyncService
27+
{
28+
private CommandBus $commandBus;
29+
private AsyncCommandBus $asyncCommandBus;
30+
private InlineCommandBus $inlineCommandBus;
31+
private QueryBus $queryBus;
32+
33+
/**
34+
* @param CommandBus $commandBus
35+
* @param AsyncCommandBus $asyncCommandBus
36+
* @param InlineCommandBus $inlineCommandBus
37+
* @param QueryBus $queryBus
38+
*/
39+
public function __construct(
40+
CommandBus $commandBus,
41+
AsyncCommandBus $asyncCommandBus,
42+
InlineCommandBus $inlineCommandBus,
43+
QueryBus $queryBus
44+
) {
45+
$this->commandBus = $commandBus;
46+
$this->asyncCommandBus = $asyncCommandBus;
47+
$this->inlineCommandBus = $inlineCommandBus;
48+
$this->queryBus = $queryBus;
49+
}
50+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the DriftPHP Project
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Drift\CommandBus\Tests\Bus;
17+
18+
use Drift\CommandBus\Tests\AsyncService;
19+
use Drift\CommandBus\Tests\BusFunctionalTest;
20+
use Drift\CommandBus\Tests\CommandHandler\ChangeAThingHandler;
21+
use Drift\CommandBus\Tests\Context;
22+
use Drift\CommandBus\Tests\Service;
23+
24+
/**
25+
* Class AsyncCommandHandlerTest.
26+
*/
27+
class AsyncCommandHandlerTest extends BusFunctionalTest
28+
{
29+
/**
30+
* Decorate configuration.
31+
*
32+
* @param array $configuration
33+
*
34+
* @return array
35+
*/
36+
protected static function decorateConfiguration(array $configuration): array
37+
{
38+
$configuration['services'][AsyncService::class] = [];
39+
$configuration['services'][Service::class] = [];
40+
$configuration['services'][Context::class] = [];
41+
$configuration['services'][ChangeAThingHandler::class] = [
42+
'tags' => [
43+
['name' => 'command_handler', 'method' => 'handle'],
44+
['name' => 'another_tag', 'method' => 'anotherMethod'],
45+
],
46+
];
47+
48+
$configuration['command_bus']['command-bus']['async_adapter'] = [
49+
'adapter' => 'in_memory',
50+
'in_memory' => [],
51+
];
52+
53+
return $configuration;
54+
}
55+
56+
/**
57+
* Buses injection.
58+
*/
59+
public function testBusesInjection()
60+
{
61+
$this->expectNotToPerformAssertions();
62+
$this->get(Service::class);
63+
$this->get(AsyncService::class);
64+
}
65+
}

Tests/Bus/CommandHandlerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Drift\CommandBus\Tests\Command\ChangeAThing;
2323
use Drift\CommandBus\Tests\CommandHandler\ChangeAThingHandler;
2424
use Drift\CommandBus\Tests\Context;
25+
use Drift\CommandBus\Tests\Service;
2526

2627
/**
2728
* Class CommandHandlerTest.
@@ -37,6 +38,7 @@ class CommandHandlerTest extends BusFunctionalTest
3738
*/
3839
protected static function decorateConfiguration(array $configuration): array
3940
{
41+
$configuration['services'][Service::class] = [];
4042
$configuration['services'][Context::class] = [];
4143
$configuration['services'][ChangeAThingHandler::class] = [
4244
'tags' => [
@@ -91,4 +93,13 @@ public function testQueryBus()
9193
->getMiddlewareList()
9294
);
9395
}
96+
97+
/**
98+
* Buses injection.
99+
*/
100+
public function testBusesInjection()
101+
{
102+
$this->expectNotToPerformAssertions();
103+
$this->get(Service::class);
104+
}
94105
}

Tests/Bus/QueryHandlerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Drift\CommandBus\Tests\Context;
2323
use Drift\CommandBus\Tests\Query\GetAThing;
2424
use Drift\CommandBus\Tests\QueryHandler\GetAThingHandler;
25+
use Drift\CommandBus\Tests\Service;
2526

2627
/**
2728
* Class QueryHandlerTest.
@@ -37,6 +38,7 @@ class QueryHandlerTest extends BusFunctionalTest
3738
*/
3839
protected static function decorateConfiguration(array $configuration): array
3940
{
41+
$configuration['services'][Service::class] = [];
4042
$configuration['services'][Context::class] = [];
4143
$configuration['services'][GetAThingHandler::class] = [
4244
'tags' => [
@@ -89,4 +91,13 @@ public function testBadCommand()
8991

9092
await($promise, $this->getLoop());
9193
}
94+
95+
/**
96+
* Buses injection.
97+
*/
98+
public function testBusesInjection()
99+
{
100+
$this->expectNotToPerformAssertions();
101+
$this->get(Service::class);
102+
}
92103
}

Tests/Bus/QueryHandlerWithMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Class QueryHandlerWithMiddleware.
3333
*/
34-
class QueryHandlerWithMiddleware extends BusFunctionalTest
34+
class QueryHandlerWithMiddlewareTest extends BusFunctionalTest
3535
{
3636
/**
3737
* Decorate configuration.

Tests/Service.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the DriftPHP Project
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Drift\CommandBus\Tests;
17+
18+
use Drift\CommandBus\Bus\CommandBus;
19+
use Drift\CommandBus\Bus\InlineCommandBus;
20+
use Drift\CommandBus\Bus\QueryBus;
21+
22+
/**
23+
* Class Service.
24+
*/
25+
class Service
26+
{
27+
private CommandBus $commandBus;
28+
private InlineCommandBus $inlineCommandBus;
29+
private QueryBus $queryBus;
30+
31+
/**
32+
* @param CommandBus $commandBus
33+
* @param InlineCommandBus $inlineCommandBus
34+
* @param QueryBus $queryBus
35+
*/
36+
public function __construct(
37+
CommandBus $commandBus,
38+
InlineCommandBus $inlineCommandBus,
39+
QueryBus $queryBus
40+
) {
41+
$this->commandBus = $commandBus;
42+
$this->inlineCommandBus = $inlineCommandBus;
43+
$this->queryBus = $queryBus;
44+
}
45+
}

0 commit comments

Comments
 (0)