Completed
Push — master ( be1f89...dd7c75 )
by Artem
13:35
created

SetupFabricControllerTest::testDispatch()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 35
rs 8.8571
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
namespace RabbitMqModule\Controller;
4
5
use Zend\Test\PHPUnit\Controller\AbstractConsoleControllerTestCase;
6
7
/**
8
 * Class SetupFabricControllerTest
9
 * @package RabbitMqModule\Controller
10
 */
11
class SetupFabricControllerTest extends AbstractConsoleControllerTestCase
12
{
13
    protected function setUp()
14
    {
15
        $config = include __DIR__.'/../../TestConfiguration.php.dist';
16
        $this->setApplicationConfig($config);
17
        parent::setUp();
18
    }
19
20
    public function testDispatch()
21
    {
22
        $serviceManager = $this->getApplicationServiceLocator();
23
        $serviceManager->setAllowOverride(true);
24
25
        $service = static::getMockBuilder('RabbitMqModule\\Service\\SetupFabricAwareInterface')
26
            ->getMockForAbstractClass();
27
        $service->expects(static::exactly(4))
28
            ->method('setupFabric');
29
        $someOtherService = new \ArrayObject();
30
        $serviceManager->setService('rabbitmq_module.consumer.foo-consumer1', $service);
31
        $serviceManager->setService('rabbitmq_module.consumer.foo-consumer2', $service);
32
        $serviceManager->setService('rabbitmq_module.producer.bar-producer1', $service);
33
        $serviceManager->setService('rabbitmq_module.producer.bar-producer2', $service);
34
        $serviceManager->setService('rabbitmq_module.producer.bar-producer-fake', $someOtherService);
35
36
        /** @var array $configuration */
37
        $configuration = $serviceManager->get('Configuration');
38
        $configuration['rabbitmq_module']['consumer'] = [
39
            'foo-consumer1' => [],
40
            'foo-consumer2' => [],
41
        ];
42
        $configuration['rabbitmq_module']['producer'] = [
43
            'bar-producer1' => [],
44
            'bar-producer2' => [],
45
            'bar-producer-fake' => [],
46
        ];
47
        $serviceManager->setService('Configuration', $configuration);
48
49
        ob_start();
50
        $this->dispatch('rabbitmq-module setup-fabric');
51
        ob_end_clean();
52
53
        $this->assertResponseStatusCode(0);
54
    }
55
56
    public function testDispatchWithInvalidConfigKeys()
57
    {
58
        $serviceManager = $this->getApplicationServiceLocator();
59
        $serviceManager->setAllowOverride(true);
60
61
        /** @var array $configuration */
62
        $configuration = $serviceManager->get('Configuration');
63
        $configuration['rabbitmq_module'] = null;
64
        $serviceManager->setService('Configuration', $configuration);
65
66
        ob_start();
67
        $this->dispatch('rabbitmq-module setup-fabric');
68
        ob_end_clean();
69
70
        $this->assertResponseStatusCode(1);
71
    }
72
}
73