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
|
|
View Code Duplication |
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->assertFalse(file_exists($preHandlerFilename)); |
62
|
|
|
$this->assertTrue(file_exists($handlerFilename)); |
63
|
|
|
|
64
|
|
|
unlink($handlerFilename); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
* @group active |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function itShouldHandleWithPostMiddleWare() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$this->app->setCommand(new WithPostMiddleWareCommand()); |
74
|
|
|
|
75
|
|
|
$this->app->doRun($this->input, $this->outputInterface); |
76
|
|
|
|
77
|
|
|
$handlerFilename = __DIR__ . '/' . WithPostMiddleWareHandler::FILE_TEST; |
78
|
|
|
$postHandlerFilename = __DIR__.'/'. PostMiddleWareHandler::FILE_TEST; |
79
|
|
|
$this->assertFalse(file_exists($handlerFilename)); |
80
|
|
|
$this->assertTrue(file_exists($postHandlerFilename)); |
81
|
|
|
|
82
|
|
|
unlink($postHandlerFilename); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.