Skip to content

Commit afe8d6a

Browse files
author
Mikhail Bakulin
committed
New PHP versions added to the build
1 parent d6a81db commit afe8d6a

File tree

3 files changed

+163
-156
lines changed

3 files changed

+163
-156
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ language: php
33
php:
44
- 7.0
55
- 7.1
6+
- 7.2
7+
- 7.3
68

79
install:
810
- composer clear-cache
@@ -17,5 +19,5 @@ after_success:
1719

1820
cache:
1921
directories:
20-
- vendor
21-
- $HOME/.cache/composer
22+
- vendor
23+
- $HOME/.cache/composer

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=7.0",
14+
"php": "7.0",
1515
"yiisoft/yii2": "^2.0",
1616
"php-amqplib/php-amqplib": "^2.7"
1717
},

tests/controllers/RabbitMQControllerTest.php

Lines changed: 158 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -8,161 +8,166 @@
88
use mikemadisonweb\rabbitmq\Configuration;
99
use mikemadisonweb\rabbitmq\controllers\RabbitMQController;
1010
use mikemadisonweb\rabbitmq\tests\TestCase;
11+
use yii\base\InvalidConfigException;
1112
use yii\console\Controller;
1213

1314
class RabbitMQControllerTest extends TestCase
1415
{
15-
protected $controller;
16-
17-
public function setUp()
18-
{
19-
$this->loadExtension([
20-
'components' => [
21-
'rabbitmq' => [
22-
'class' => Configuration::class,
23-
'connections' => [
24-
[
25-
'host' => 'unreal',
26-
],
27-
],
28-
],
29-
],
30-
]);
31-
$this->controller = $this->getMockBuilder(RabbitMQController::class)
32-
->setConstructorArgs([Configuration::EXTENSION_CONTROLLER_ALIAS, \Yii::$app])
33-
->setMethods(['stderr', 'stdout'])
34-
->getMock();
35-
}
36-
37-
public function testConsumeAction()
38-
{
39-
// Check console flags existence
40-
$this->assertTrue(isset($this->controller->optionAliases()['l']));
41-
$this->assertTrue(isset($this->controller->optionAliases()['m']));
42-
$this->assertSame('messagesLimit', $this->controller->optionAliases()['m']);
43-
$this->assertSame('memoryLimit', $this->controller->optionAliases()['l']);
44-
$this->assertTrue(in_array('messagesLimit', $this->controller->options('consume'), true));
45-
$this->assertTrue(in_array('memoryLimit', $this->controller->options('consume'), true));
46-
47-
// Invalid consumer name
48-
$response = $this->controller->runAction('consume', ['unknown']);
49-
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
50-
51-
// Valid consumer name
52-
$name = 'valid';
53-
$consumer = $this->getMockBuilder(Consumer::class)
54-
->disableOriginalConstructor()
55-
->setMethods(['getConsumerTag', 'consume'])
56-
->getMock();
57-
\Yii::$container->set(sprintf(Configuration::CONSUMER_SERVICE_NAME, $name), $consumer);
58-
$this->controller->debug = 'false';
59-
$this->controller->memoryLimit = '1024';
60-
$response = $this->controller->runAction('consume', [$name]);
61-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
62-
}
63-
64-
public function testPublishAction()
65-
{
66-
// Invalid producer name
67-
$response = $this->controller->runAction('publish', ['unknown', 'unknown']);
68-
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
69-
70-
// No data
71-
$name = 'valid';
72-
$producer = $this->getMockBuilder(Producer::class)
73-
->disableOriginalConstructor()
74-
->setMethods(['publish'])
75-
->getMock();
76-
\Yii::$container->set(sprintf(Configuration::PRODUCER_SERVICE_NAME, $name), $producer);
77-
$response = $this->controller->runAction('publish', [$name, 'does not matter']);
78-
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
79-
}
80-
81-
public function testDeclareAllAction()
82-
{
83-
$routing = $this->createMock(Routing::class);
84-
$routing->expects($this->exactly(2))
85-
->method('declareAll')
86-
->willReturnOnConsecutiveCalls(false, true);
87-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
88-
$response = $this->controller->runAction('declare-all');
89-
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
90-
$response = $this->controller->runAction('declare-all');
91-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
92-
}
93-
94-
public function testDeclareQueueAction()
95-
{
96-
$routing = $this->createMock(Routing::class);
97-
$routing->expects($this->exactly(2))
98-
->method('isQueueExists')
99-
->willReturnOnConsecutiveCalls(true, false);
100-
$routing->expects($this->once())
101-
->method('declareQueue');
102-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
103-
$response = $this->controller->runAction('declare-queue', ['queue-name']);
104-
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
105-
$response = $this->controller->runAction('declare-queue', ['queue-name']);
106-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
107-
}
108-
109-
public function testDeclareExchangeAction()
110-
{
111-
$routing = $this->createMock(Routing::class);
112-
$routing->expects($this->exactly(2))
113-
->method('isExchangeExists')
114-
->willReturnOnConsecutiveCalls(true, false);
115-
$routing->expects($this->once())
116-
->method('declareExchange');
117-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
118-
$response = $this->controller->runAction('declare-exchange', ['exchange-name']);
119-
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
120-
$response = $this->controller->runAction('declare-exchange', ['exchange-name']);
121-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
122-
}
123-
124-
public function testDeleteAllAction()
125-
{
126-
$this->controller->interactive = false;
127-
$routing = $this->createMock(Routing::class);
128-
$routing->expects($this->once())
129-
->method('deleteAll')
130-
->willReturnOnConsecutiveCalls(false, true);
131-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
132-
$response = $this->controller->runAction('delete-all');
133-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
134-
}
135-
136-
public function testDeleteQueueAction()
137-
{
138-
$this->controller->interactive = false;
139-
$routing = $this->createMock(Routing::class);
140-
$routing->expects($this->once())
141-
->method('deleteQueue');
142-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
143-
$response = $this->controller->runAction('delete-queue', ['queue-name']);
144-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
145-
}
146-
147-
public function testDeleteExchangeAction()
148-
{
149-
$this->controller->interactive = false;
150-
$routing = $this->createMock(Routing::class);
151-
$routing->expects($this->once())
152-
->method('deleteExchange');
153-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
154-
$response = $this->controller->runAction('delete-exchange', ['exchange-name']);
155-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
156-
}
157-
158-
public function testPurgeQueueAction()
159-
{
160-
$this->controller->interactive = false;
161-
$routing = $this->createMock(Routing::class);
162-
$routing->expects($this->once())
163-
->method('purgeQueue');
164-
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
165-
$response = $this->controller->runAction('purge-queue', ['queue-name']);
166-
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
167-
}
16+
protected $controller;
17+
18+
public function setUp()
19+
{
20+
$this->loadExtension(
21+
[
22+
'components' => [
23+
'rabbitmq' => [
24+
'class' => Configuration::class,
25+
'connections' => [
26+
[
27+
'host' => 'unreal',
28+
],
29+
],
30+
],
31+
],
32+
]
33+
);
34+
$this->controller = $this->getMockBuilder(RabbitMQController::class)
35+
->setConstructorArgs([Configuration::EXTENSION_CONTROLLER_ALIAS, \Yii::$app])
36+
->setMethods(['stderr', 'stdout'])
37+
->getMock();
38+
}
39+
40+
public function testConsumeAction()
41+
{
42+
// Check console flags existence
43+
$this->assertTrue(isset($this->controller->optionAliases()['l']));
44+
$this->assertTrue(isset($this->controller->optionAliases()['m']));
45+
$this->assertSame('messagesLimit', $this->controller->optionAliases()['m']);
46+
$this->assertSame('memoryLimit', $this->controller->optionAliases()['l']);
47+
$this->assertTrue(in_array('messagesLimit', $this->controller->options('consume'), true));
48+
$this->assertTrue(in_array('memoryLimit', $this->controller->options('consume'), true));
49+
50+
// Invalid consumer name
51+
$this->expectException(InvalidConfigException::class);
52+
$response = $this->controller->runAction('consume', ['unknown']);
53+
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
54+
55+
// Valid consumer name
56+
$name = 'valid';
57+
$consumer = $this->getMockBuilder(Consumer::class)
58+
->disableOriginalConstructor()
59+
->setMethods(['getConsumerTag', 'consume'])
60+
->getMock();
61+
\Yii::$container->set(sprintf(Configuration::CONSUMER_SERVICE_NAME, $name), $consumer);
62+
$this->controller->debug = 'false';
63+
$this->controller->memoryLimit = '1024';
64+
$response = $this->controller->runAction('consume', [$name]);
65+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
66+
}
67+
68+
public function testPublishAction()
69+
{
70+
// Invalid producer name
71+
$this->expectException(InvalidConfigException::class);
72+
$response = $this->controller->runAction('publish', ['unknown', 'unknown']);
73+
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
74+
75+
// No data
76+
$name = 'valid';
77+
$producer = $this->getMockBuilder(Producer::class)
78+
->disableOriginalConstructor()
79+
->setMethods(['publish'])
80+
->getMock();
81+
\Yii::$container->set(sprintf(Configuration::PRODUCER_SERVICE_NAME, $name), $producer);
82+
$response = $this->controller->runAction('publish', [$name, 'does not matter']);
83+
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
84+
}
85+
86+
public function testDeclareAllAction()
87+
{
88+
$routing = $this->createMock(Routing::class);
89+
$routing->expects($this->exactly(2))
90+
->method('declareAll')
91+
->willReturnOnConsecutiveCalls(false, true);
92+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
93+
$response = $this->controller->runAction('declare-all');
94+
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
95+
$response = $this->controller->runAction('declare-all');
96+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
97+
}
98+
99+
public function testDeclareQueueAction()
100+
{
101+
$routing = $this->createMock(Routing::class);
102+
$routing->expects($this->exactly(2))
103+
->method('isQueueExists')
104+
->willReturnOnConsecutiveCalls(true, false);
105+
$routing->expects($this->once())
106+
->method('declareQueue');
107+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
108+
$response = $this->controller->runAction('declare-queue', ['queue-name']);
109+
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
110+
$response = $this->controller->runAction('declare-queue', ['queue-name']);
111+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
112+
}
113+
114+
public function testDeclareExchangeAction()
115+
{
116+
$routing = $this->createMock(Routing::class);
117+
$routing->expects($this->exactly(2))
118+
->method('isExchangeExists')
119+
->willReturnOnConsecutiveCalls(true, false);
120+
$routing->expects($this->once())
121+
->method('declareExchange');
122+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
123+
$response = $this->controller->runAction('declare-exchange', ['exchange-name']);
124+
$this->assertSame(Controller::EXIT_CODE_ERROR, $response);
125+
$response = $this->controller->runAction('declare-exchange', ['exchange-name']);
126+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
127+
}
128+
129+
public function testDeleteAllAction()
130+
{
131+
$this->controller->interactive = false;
132+
$routing = $this->createMock(Routing::class);
133+
$routing->expects($this->once())
134+
->method('deleteAll')
135+
->willReturnOnConsecutiveCalls(false, true);
136+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
137+
$response = $this->controller->runAction('delete-all');
138+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
139+
}
140+
141+
public function testDeleteQueueAction()
142+
{
143+
$this->controller->interactive = false;
144+
$routing = $this->createMock(Routing::class);
145+
$routing->expects($this->once())
146+
->method('deleteQueue');
147+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
148+
$response = $this->controller->runAction('delete-queue', ['queue-name']);
149+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
150+
}
151+
152+
public function testDeleteExchangeAction()
153+
{
154+
$this->controller->interactive = false;
155+
$routing = $this->createMock(Routing::class);
156+
$routing->expects($this->once())
157+
->method('deleteExchange');
158+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
159+
$response = $this->controller->runAction('delete-exchange', ['exchange-name']);
160+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
161+
}
162+
163+
public function testPurgeQueueAction()
164+
{
165+
$this->controller->interactive = false;
166+
$routing = $this->createMock(Routing::class);
167+
$routing->expects($this->once())
168+
->method('purgeQueue');
169+
\Yii::$container->setSingleton(Configuration::ROUTING_SERVICE_NAME, $routing);
170+
$response = $this->controller->runAction('purge-queue', ['queue-name']);
171+
$this->assertSame(Controller::EXIT_CODE_NORMAL, $response);
172+
}
168173
}

0 commit comments

Comments
 (0)