|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gendoria\CommandQueue\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Gendoria\CommandQueue\Command\CommandInterface; |
|
6
|
|
|
use Gendoria\CommandQueue\CommandProcessor\CommandProcessorInterface; |
|
7
|
|
|
use Gendoria\CommandQueue\Exception\MultipleProcessorsException; |
|
8
|
|
|
use Gendoria\CommandQueue\ProcessorFactory; |
|
9
|
|
|
use Gendoria\CommandQueue\ProcessorNotFoundException; |
|
10
|
|
|
use InvalidArgumentException; |
|
11
|
|
|
use PHPUnit_Framework_TestCase; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Description of ProcessorFactoryTest |
|
15
|
|
|
* |
|
16
|
|
|
* @author Tomasz Struczyński <[email protected]> |
|
17
|
|
|
* @group CommandQueue |
|
18
|
|
|
*/ |
|
19
|
|
|
class ProcessorFactoryTest extends PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testProcessor() |
|
22
|
|
|
{ |
|
23
|
|
|
$service = $this->getMockBuilder(CommandProcessorInterface::class)->getMock(); |
|
24
|
|
|
$command = $this->getMockBuilder(CommandInterface::class)->getMock(); |
|
25
|
|
|
$service->expects($this->any()) |
|
26
|
|
|
->method('supports') |
|
27
|
|
|
->with($command) |
|
28
|
|
|
->will($this->returnValue(true)); |
|
29
|
|
|
|
|
30
|
|
|
$processor = new ProcessorFactory(); |
|
31
|
|
|
$processor->registerProcessorForCommand(get_class($command), $service); |
|
32
|
|
|
$this->assertEquals($service, $processor->getProcessor($command)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testNotExistingCommand() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setExpectedException(InvalidArgumentException::class, 'Registering service for non existing command class.'); |
|
38
|
|
|
$service = $this->getMockBuilder(CommandProcessorInterface::class)->getMock(); |
|
39
|
|
|
$processor = new ProcessorFactory(); |
|
40
|
|
|
$processor->registerProcessorForCommand('dummy', $service); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testInvalidCommand() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->setExpectedException(InvalidArgumentException::class, 'Command class has to implement CommandInterface interface.'); |
|
46
|
|
|
$service = $this->getMockBuilder(CommandProcessorInterface::class)->getMock(); |
|
47
|
|
|
$command = $this->getMockBuilder('stdClass')->getMock(); |
|
48
|
|
|
$processor = new ProcessorFactory(); |
|
49
|
|
|
$processor->registerProcessorForCommand(get_class($command), $service); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testNoProcessor() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->setExpectedException(ProcessorNotFoundException::class); |
|
55
|
|
|
$command = $this->getMockBuilder(CommandInterface::class)->getMock(); |
|
56
|
|
|
$processor = new ProcessorFactory(); |
|
57
|
|
|
$processor->getProcessor($command); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testMultipleProcessorException() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->setExpectedException(MultipleProcessorsException::class); |
|
63
|
|
|
$command = $this->getMockBuilder(CommandInterface::class)->getMock(); |
|
64
|
|
|
$service = $this->getMockBuilder(CommandProcessorInterface::class)->getMock(); |
|
65
|
|
|
$processor = new ProcessorFactory(); |
|
66
|
|
|
$processor->registerProcessorForCommand(get_class($command), $service); |
|
67
|
|
|
$processor->registerProcessorForCommand(get_class($command), $service); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testHasProcessor() |
|
71
|
|
|
{ |
|
72
|
|
|
$command = $this->getMockBuilder(CommandInterface::class)->getMock(); |
|
73
|
|
|
$service = $this->getMockBuilder(CommandProcessorInterface::class)->getMock(); |
|
74
|
|
|
$processor = new ProcessorFactory(); |
|
75
|
|
|
$processor->registerProcessorForCommand(get_class($command), $service); |
|
76
|
|
|
$this->assertTrue($processor->hasProcessor(get_class($command))); |
|
77
|
|
|
$this->assertFalse($processor->hasProcessor('__nonExistingClass__')); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|