|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare (strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace HMLB\UserBundle\Tests\Command; |
|
6
|
|
|
|
|
7
|
|
|
use HMLB\DDD\Entity\Identity; |
|
8
|
|
|
use HMLB\DDD\Persistence\PersistentMessage; |
|
9
|
|
|
use HMLB\DDDBundle\Repository\PersistentCommandRepository; |
|
10
|
|
|
use HMLB\UserBundle\Message\Trace\Context; |
|
11
|
|
|
use HMLB\UserBundle\Message\Trace\Trace; |
|
12
|
|
|
use HMLB\UserBundle\Message\TraceableCommand; |
|
13
|
|
|
use SimpleBus\Message\Bus\MessageBus; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Trait TraceableCommandTestingCapabilities. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Hugues Maignol <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
trait TraceableCommandTestingCapabilities |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @param MessageBus $commandBus |
|
24
|
|
|
* @param PersistentMessage $command |
|
25
|
|
|
* @param PersistentCommandRepository $commandRepository |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function handleCommandAndAssertTraced( |
|
28
|
|
|
MessageBus $commandBus, |
|
29
|
|
|
PersistentMessage $command, |
|
30
|
|
|
PersistentCommandRepository $commandRepository |
|
31
|
|
|
) { |
|
32
|
|
|
$commandBus->handle($command); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertInstanceOf(Identity::class, $command->getId()); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$foundCommand = $commandRepository->get($command->getId()); |
|
37
|
|
|
$this->assertSame($command, $foundCommand); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
if (!$command instanceof TraceableCommand) { |
|
40
|
|
|
$this->fail(sprintf('The message %s is not Traceable', get_class($command))); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
$this->assertInstanceOf(Trace::class, $trace = $command->getTrace()); |
|
|
|
|
|
|
43
|
|
|
$this->assertInstanceOf(Context::class, $trace->getContext()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.