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

StdInProducerControllerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 45
rs 10
1
<?php
2
3
namespace RabbitMqModule\Controller;
4
5
use Zend\Test\PHPUnit\Controller\AbstractConsoleControllerTestCase;
6
7
/**
8
 * Class StdInProducerControllerTest
9
 * @package RabbitMqModule\Controller
10
 */
11
class StdInProducerControllerTest 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 testDispatchWithTestProducer()
21
    {
22
        $producer = $this->getMockBuilder('RabbitMqModule\Producer')
23
            ->setMethods(['publish'])
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
        $producer
27
            ->expects(static::once())
28
            ->method('publish')
29
            ->with(
30
                static::equalTo('msg'),
31
                static::equalTo('bar')
32
            );
33
34
        $serviceManager = $this->getApplicationServiceLocator();
35
        $serviceManager->setAllowOverride(true);
36
        $serviceManager->setService('rabbitmq_module.producer.foo', $producer);
37
38
        ob_start();
39
        $this->dispatch('rabbitmq-module stdin-producer foo --route=bar msg');
40
        ob_end_clean();
41
42
        $this->assertResponseStatusCode(0);
43
    }
44
45
    public function testDispatchWithInvalidTestProducer()
46
    {
47
        ob_start();
48
        $this->dispatch('rabbitmq-module stdin-producer foo --route=bar msg');
49
        $output = ob_get_clean();
50
51
        static::assertRegExp('/No producer with name "foo" found/', $output);
52
53
        $this->assertResponseStatusCode(1);
54
    }
55
}
56