Skip to content

Commit 26a34b9

Browse files
committed
remove RABBITMQ_HOST,PORT etc env vars.
1 parent 9510412 commit 26a34b9

6 files changed

Lines changed: 20 additions & 55 deletions

MongodbExtensionTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace Enqueue\Test;
44

55
use Enqueue\Mongodb\MongodbConnectionFactory;
6+
use Enqueue\Mongodb\MongodbContext;
67

78
trait MongodbExtensionTrait
89
{
9-
protected function buildMongodbContext()
10+
protected function buildMongodbContext(): MongodbContext
1011
{
1112
if (false == $env = getenv('MONGO_DSN')) {
1213
$this->markTestSkipped('The MONGO_DSN env is not available. Skip tests');

RabbitManagementExtensionTrait.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
namespace Enqueue\Test;
44

5+
use Enqueue\Dsn\Dsn;
6+
57
trait RabbitManagementExtensionTrait
68
{
79
/**
810
* @param string $queueName
911
*/
1012
private function removeQueue($queueName)
1113
{
12-
$rabbitmqHost = getenv('RABBITMQ_HOST');
13-
$rabbitmqUser = getenv('RABBITMQ_USER');
14-
$rabbitmqPassword = getenv('RABBITMQ_PASSWORD');
15-
$rabbitmqVhost = getenv('RABBITMQ_VHOST');
14+
$dsn = new Dsn(getenv('RABBITMQ_AMQP_DSN'));
1615

1716
$url = sprintf(
1817
'http://%s:15672/api/queues/%s/%s',
19-
$rabbitmqHost,
20-
urlencode($rabbitmqVhost),
18+
$dsn->getHost(),
19+
urlencode(ltrim($dsn->getPath(), '/')),
2120
$queueName
2221
);
2322

@@ -26,7 +25,7 @@ private function removeQueue($queueName)
2625
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
2726
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2827
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
29-
curl_setopt($ch, CURLOPT_USERPWD, $rabbitmqUser.':'.$rabbitmqPassword);
28+
curl_setopt($ch, CURLOPT_USERPWD, $dsn->getUser().':'.$dsn->getPassword());
3029
curl_setopt($ch, CURLOPT_HTTPHEADER, [
3130
'Content-Type' => 'application/json',
3231
]);
@@ -46,15 +45,12 @@ private function removeQueue($queueName)
4645
*/
4746
private function removeExchange($exchangeName)
4847
{
49-
$rabbitmqHost = getenv('RABBITMQ_HOST');
50-
$rabbitmqUser = getenv('RABBITMQ_USER');
51-
$rabbitmqPassword = getenv('RABBITMQ_PASSWORD');
52-
$rabbitmqVhost = getenv('RABBITMQ_VHOST');
48+
$dsn = new Dsn(getenv('RABBITMQ_AMQP_DSN'));
5349

5450
$url = sprintf(
5551
'http://%s:15672/api/exchanges/%s/%s',
56-
$rabbitmqHost,
57-
urlencode($rabbitmqVhost),
52+
$dsn->getHost(),
53+
urlencode(ltrim($dsn->getPath(), '/')),
5854
$exchangeName
5955
);
6056

@@ -63,7 +59,7 @@ private function removeExchange($exchangeName)
6359
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
6460
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
6561
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
66-
curl_setopt($ch, CURLOPT_USERPWD, $rabbitmqUser.':'.$rabbitmqPassword);
62+
curl_setopt($ch, CURLOPT_USERPWD, $dsn->getUser().':'.$dsn->getPassword());
6763
curl_setopt($ch, CURLOPT_HTTPHEADER, [
6864
'Content-Type' => 'application/json',
6965
]);

RabbitmqAmqpExtension.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,7 @@ trait RabbitmqAmqpExtension
1212
*/
1313
private function buildAmqpContext()
1414
{
15-
if (false == getenv('RABBITMQ_HOST')) {
16-
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');
17-
}
18-
19-
$config = [
20-
'host' => getenv('RABBITMQ_HOST'),
21-
'port' => getenv('RABBITMQ_AMQP__PORT'),
22-
'user' => getenv('RABBITMQ_USER'),
23-
'pass' => getenv('RABBITMQ_PASSWORD'),
24-
'vhost' => getenv('RABBITMQ_VHOST'),
25-
];
26-
27-
return (new AmqpConnectionFactory($config))->createContext();
28-
}
29-
30-
/**
31-
* @return AmqpContext
32-
*/
33-
private function buildAmqpContextFromDsn()
34-
{
35-
if (false == $dsn = getenv('AMQP_DSN')) {
15+
if (false == $dsn = getenv('RABBITMQ_AMQP_DSN')) {
3616
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');
3717
}
3818

RabbitmqStompExtension.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,12 @@
77

88
trait RabbitmqStompExtension
99
{
10-
/**
11-
* @return StompContext
12-
*/
13-
private function buildStompContext()
10+
private function buildStompContext(): StompContext
1411
{
15-
if (false == getenv('RABBITMQ_HOST')) {
12+
if (false == $dsn = getenv('RABITMQ_STOMP_DSN')) {
1613
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');
1714
}
1815

19-
$config = [
20-
'host' => getenv('RABBITMQ_HOST'),
21-
'port' => getenv('RABBITMQ_STOMP_PORT'),
22-
'login' => getenv('RABBITMQ_USER'),
23-
'password' => getenv('RABBITMQ_PASSWORD'),
24-
'vhost' => getenv('RABBITMQ_VHOST'),
25-
'sync' => true,
26-
];
27-
28-
return (new StompConnectionFactory($config))->createContext();
16+
return (new StompConnectionFactory($dsn))->createContext();
2917
}
3018
}

SqsExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
trait SqsExtension
99
{
10-
/**
11-
* @return SqsContext
12-
*/
13-
private function buildSqsContext()
10+
private function buildSqsContext(): SqsContext
1411
{
1512
if (false == getenv('AWS_SQS_ENDPOINT') && false == getenv('AWS_SQS_KEY')) {
1613
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"source": "https://github.com/php-enqueue/enqueue-dev",
1010
"docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md"
1111
},
12+
"require": {
13+
"enqueue/dsn": "0.9.x-dev"
14+
},
1215
"autoload": {
1316
"psr-4": { "Enqueue\\Test\\": "" }
1417
},

0 commit comments

Comments
 (0)