|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bruli\EventBusBundleTests\Behaviour; |
|
4
|
|
|
|
|
5
|
|
|
use Bruli\EventBusBundleTests\Infrastructure\Application; |
|
6
|
|
|
use Bruli\EventBusBundleTests\Behaviour\SingleCommand; |
|
7
|
|
|
use Bruli\EventBusBundleTests\Behaviour\SingleCommandHandler; |
|
8
|
|
|
use Mockery\Mock; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
class CommandBusTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Application |
|
17
|
|
|
*/ |
|
18
|
|
|
private $app; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var InputInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $input; |
|
23
|
|
|
/** |
|
24
|
|
|
* @var OutputInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $outputInterface; |
|
27
|
|
|
|
|
28
|
|
|
protected function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->app = new Application(); |
|
31
|
|
|
$this->input = \Mockery::mock(InputInterface::class); |
|
32
|
|
|
$this->outputInterface = \Mockery::mock(OutputInterface::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @test |
|
37
|
|
|
*/ |
|
38
|
|
|
public function itShouldHandleSingleHandler() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->app->setCommand(new SingleCommand()); |
|
41
|
|
|
|
|
42
|
|
|
$this->app->doRun($this->input, $this->outputInterface); |
|
43
|
|
|
|
|
44
|
|
|
$filename = __DIR__ . '/' . SingleCommandHandler::FILE_TEST; |
|
45
|
|
|
$this->assertTrue(file_exists($filename)); |
|
46
|
|
|
|
|
47
|
|
|
unlink($filename); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
*/ |
|
53
|
|
|
public function itShouldHandleWithPreMiddleWare() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->app->setCommand(new WithPreMiddleWareCommand()); |
|
56
|
|
|
|
|
57
|
|
|
$this->app->doRun($this->input, $this->outputInterface); |
|
58
|
|
|
|
|
59
|
|
|
$handlerFilename = __DIR__ . '/' . WithPreMiddleWareHandler::FILE_TEST; |
|
60
|
|
|
$preHandlerFilename = __DIR__.'/'. PreMiddleWareHandler::FILE_TEST; |
|
61
|
|
|
$this->assertTrue(file_exists($handlerFilename)); |
|
62
|
|
|
$this->assertTrue(file_exists($preHandlerFilename)); |
|
63
|
|
|
|
|
64
|
|
|
unlink($handlerFilename); |
|
65
|
|
|
unlink($preHandlerFilename); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|