|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bruli\EventBusBundleTests\Behaviour; |
|
4
|
|
|
|
|
5
|
|
|
use Bruli\EventBusBundleTests\Infrastructure\CommandApplication; |
|
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 CommandApplication |
|
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 CommandApplication(); |
|
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
|
|
|
$preSecondHandlerFileName = __DIR__. '/' . PreSecondMiddleWareHandler::FILE_TEST; |
|
62
|
|
|
$this->assertFalse(file_exists($preHandlerFilename)); |
|
63
|
|
|
$this->assertFalse(file_exists($preSecondHandlerFileName)); |
|
64
|
|
|
$this->assertTrue(file_exists($handlerFilename)); |
|
65
|
|
|
|
|
66
|
|
|
unlink($handlerFilename); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @test |
|
71
|
|
|
* @group active |
|
72
|
|
|
*/ |
|
73
|
|
|
public function itShouldHandleWithPostMiddleWare() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->app->setCommand(new WithPostMiddleWareCommand()); |
|
76
|
|
|
|
|
77
|
|
|
$this->app->doRun($this->input, $this->outputInterface); |
|
78
|
|
|
|
|
79
|
|
|
$handlerFilename = __DIR__ . '/' . WithPostMiddleWareHandler::FILE_TEST; |
|
80
|
|
|
$handlerSecondFilename = __DIR__.'/'.WithPostMiddleWareHandler::FILE_SECOND_TEST; |
|
81
|
|
|
$postHandlerFilename = __DIR__.'/'. PostMiddleWareHandler::FILE_TEST; |
|
82
|
|
|
$postSecondHandlerFilename = __DIR__.'/'. PostSecondMiddleWareHandler::FILE_TEST; |
|
83
|
|
|
$this->assertFalse(file_exists($handlerFilename)); |
|
84
|
|
|
$this->assertFalse(file_exists($handlerSecondFilename)); |
|
85
|
|
|
$this->assertTrue(file_exists($postHandlerFilename)); |
|
86
|
|
|
$this->assertTrue(file_exists($postSecondHandlerFilename)); |
|
87
|
|
|
|
|
88
|
|
|
unlink($postHandlerFilename); |
|
89
|
|
|
unlink($postSecondHandlerFilename); |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|