Skip to content

Commit d3cdb33

Browse files
committed
[amqp] fixes
1 parent 1ff6a4b commit d3cdb33

File tree

2 files changed

+121
-118
lines changed

2 files changed

+121
-118
lines changed

Tests/Functional/UseCasesTest.php

Lines changed: 111 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -14,89 +14,106 @@
1414
*/
1515
class UseCasesTest extends WebTestCase
1616
{
17+
public function setUp()
18+
{
19+
// do not call parent::setUp.
20+
// parent::setUp();
21+
}
22+
1723
public function provideEnqueueConfigs()
1824
{
19-
return [
20-
['amqp' => [
21-
'transport' => [
22-
'default' => 'amqp',
23-
'amqp' => [
24-
'host' => getenv('SYMFONY__RABBITMQ__HOST'),
25-
'port' => getenv('SYMFONY__RABBITMQ__AMQP__PORT'),
26-
'user' => getenv('SYMFONY__RABBITMQ__USER'),
27-
'pass' => getenv('SYMFONY__RABBITMQ__PASSWORD'),
28-
'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'),
29-
'lazy' => false,
30-
]
31-
]
32-
]],
33-
['stomp' => [
34-
'transport' => [
35-
'default' => 'stomp',
36-
'stomp' => [
37-
'host' => getenv('SYMFONY__RABBITMQ__HOST'),
38-
'port' => getenv('SYMFONY__RABBITMQ__STOMP__PORT'),
39-
'login' => getenv('SYMFONY__RABBITMQ__USER'),
40-
'password' => getenv('SYMFONY__RABBITMQ__PASSWORD'),
41-
'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'),
42-
'lazy' => false,
43-
]
44-
]
45-
]],
46-
['predis' => [
47-
'transport' => [
48-
'default' => 'redis',
49-
'redis' => [
50-
'host' => getenv('SYMFONY__REDIS__HOST'),
51-
'port' => (int) getenv('SYMFONY__REDIS__PORT'),
52-
'vendor' => 'predis',
53-
'lazy' => false,
54-
]
55-
]
56-
]],
57-
['phpredis' => [
58-
'transport' => [
59-
'default' => 'redis',
60-
'redis' => [
61-
'host' => getenv('SYMFONY__REDIS__HOST'),
62-
'port' => (int) getenv('SYMFONY__REDIS__PORT'),
63-
'vendor' => 'phpredis',
64-
'lazy' => false,
65-
]
66-
]
67-
]],
68-
['fs' => [
69-
'transport' => [
70-
'default' => 'fs',
71-
'fs' => [
72-
'store_dir' => sys_get_temp_dir(),
73-
]
74-
]
75-
]],
76-
['dbal' => [
77-
'transport' => [
78-
'default' => 'dbal',
79-
'dbal' => [
80-
'dbname' => getenv('SYMFONY__DB__NAME'),
81-
'user' => getenv('SYMFONY__DB__USER'),
82-
'password' => getenv('SYMFONY__DB__PASSWORD'),
83-
'host' => getenv('SYMFONY__DB__HOST'),
84-
'port' => getenv('SYMFONY__DB__PORT'),
85-
'driver' => getenv('SYMFONY__DB__DRIVER'),
86-
]
87-
]
88-
]],
89-
['sqs' => [
90-
'transport' => [
91-
'default' => 'sqs',
92-
'sqs' => [
93-
'key' => getenv('AWS__SQS__KEY'),
94-
'secret' => getenv('AWS__SQS__SECRET'),
95-
'region' => getenv('AWS__SQS__REGION'),
96-
]
97-
]
98-
]],
99-
];
25+
yield 'amqp' => [[
26+
'transport' => [
27+
'default' => 'amqp',
28+
'amqp' => [
29+
'host' => getenv('SYMFONY__RABBITMQ__HOST'),
30+
'port' => getenv('SYMFONY__RABBITMQ__AMQP__PORT'),
31+
'user' => getenv('SYMFONY__RABBITMQ__USER'),
32+
'pass' => getenv('SYMFONY__RABBITMQ__PASSWORD'),
33+
'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'),
34+
'lazy' => false,
35+
],
36+
],
37+
]];
38+
39+
yield 'amqp_dsn' => [[
40+
'transport' => [
41+
'default' => 'amqp',
42+
'amqp' => getenv('AMQP_DSN'),
43+
],
44+
]];
45+
46+
yield 'stomp' => [[
47+
'transport' => [
48+
'default' => 'stomp',
49+
'stomp' => [
50+
'host' => getenv('SYMFONY__RABBITMQ__HOST'),
51+
'port' => getenv('SYMFONY__RABBITMQ__STOMP__PORT'),
52+
'login' => getenv('SYMFONY__RABBITMQ__USER'),
53+
'password' => getenv('SYMFONY__RABBITMQ__PASSWORD'),
54+
'vhost' => getenv('SYMFONY__RABBITMQ__VHOST'),
55+
'lazy' => false,
56+
],
57+
],
58+
]];
59+
60+
yield 'predis' => [[
61+
'transport' => [
62+
'default' => 'redis',
63+
'redis' => [
64+
'host' => getenv('SYMFONY__REDIS__HOST'),
65+
'port' => (int) getenv('SYMFONY__REDIS__PORT'),
66+
'vendor' => 'predis',
67+
'lazy' => false,
68+
],
69+
],
70+
]];
71+
72+
yield 'phpredis' => [[
73+
'transport' => [
74+
'default' => 'redis',
75+
'redis' => [
76+
'host' => getenv('SYMFONY__REDIS__HOST'),
77+
'port' => (int) getenv('SYMFONY__REDIS__PORT'),
78+
'vendor' => 'phpredis',
79+
'lazy' => false,
80+
],
81+
],
82+
]];
83+
84+
yield 'fs' => [[
85+
'transport' => [
86+
'default' => 'fs',
87+
'fs' => [
88+
'store_dir' => sys_get_temp_dir(),
89+
],
90+
],
91+
]];
92+
93+
yield 'dbal' => [[
94+
'transport' => [
95+
'default' => 'dbal',
96+
'dbal' => [
97+
'dbname' => getenv('SYMFONY__DB__NAME'),
98+
'user' => getenv('SYMFONY__DB__USER'),
99+
'password' => getenv('SYMFONY__DB__PASSWORD'),
100+
'host' => getenv('SYMFONY__DB__HOST'),
101+
'port' => getenv('SYMFONY__DB__PORT'),
102+
'driver' => getenv('SYMFONY__DB__DRIVER'),
103+
],
104+
],
105+
]];
106+
107+
yield 'sqs' => [[
108+
'transport' => [
109+
'default' => 'sqs',
110+
'sqs' => [
111+
'key' => getenv('AWS__SQS__KEY'),
112+
'secret' => getenv('AWS__SQS__SECRET'),
113+
'region' => getenv('AWS__SQS__REGION'),
114+
],
115+
],
116+
]];
100117
}
101118

102119
/**
@@ -167,19 +184,13 @@ public function testTransportConsumeMessagesCommandShouldConsumeMessage(array $e
167184
}
168185

169186
/**
170-
* @return ProducerInterface|object
187+
* @return string
171188
*/
172-
private function getMessageProducer()
189+
public static function getKernelClass()
173190
{
174-
return $this->container->get('enqueue.client.producer');
175-
}
191+
include_once __DIR__.'/app/CustomAppKernel.php';
176192

177-
/**
178-
* @return PsrContext|object
179-
*/
180-
private function getPsrContext()
181-
{
182-
return $this->container->get('enqueue.transport.context');
193+
return CustomAppKernel::class;
183194
}
184195

185196
protected function customSetUp(array $enqueueConfig)
@@ -209,7 +220,7 @@ protected function customSetUp(array $enqueueConfig)
209220
/**
210221
* {@inheritdoc}
211222
*/
212-
protected static function createKernel(array $options = array())
223+
protected static function createKernel(array $options = [])
213224
{
214225
/** @var CustomAppKernel $kernel */
215226
$kernel = parent::createKernel($options);
@@ -220,18 +231,18 @@ protected static function createKernel(array $options = array())
220231
}
221232

222233
/**
223-
* @return string
234+
* @return ProducerInterface|object
224235
*/
225-
public static function getKernelClass()
236+
private function getMessageProducer()
226237
{
227-
include_once __DIR__.'/app/CustomAppKernel.php';
228-
229-
return CustomAppKernel::class;
238+
return $this->container->get('enqueue.client.producer');
230239
}
231240

232-
public function setUp()
241+
/**
242+
* @return PsrContext|object
243+
*/
244+
private function getPsrContext()
233245
{
234-
// do not call parent::setUp.
235-
// parent::setUp();
246+
return $this->container->get('enqueue.transport.context');
236247
}
237248
}

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use Enqueue\Bundle\DependencyInjection\Configuration;
66
use Enqueue\Bundle\Tests\Unit\Mocks\FooTransportFactory;
7-
use Enqueue\Symfony\DefaultTransportFactory;
87
use Enqueue\Null\Symfony\NullTransportFactory;
8+
use Enqueue\Symfony\DefaultTransportFactory;
99
use Enqueue\Test\ClassExtensionTrait;
10+
use PHPUnit\Framework\TestCase;
1011
use Symfony\Component\Config\Definition\ConfigurationInterface;
1112
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1213
use Symfony\Component\Config\Definition\Processor;
13-
use PHPUnit\Framework\TestCase;
1414

1515
class ConfigurationTest extends TestCase
1616
{
@@ -28,10 +28,8 @@ public function testCouldBeConstructedWithFactoriesAsFirstArgument()
2828

2929
public function testThrowIfTransportNotConfigured()
3030
{
31-
$this->setExpectedException(
32-
InvalidConfigurationException::class,
33-
'The child node "transport" at path "enqueue" must be configured.'
34-
);
31+
$this->expectException(InvalidConfigurationException::class);
32+
$this->expectExceptionMessage('The child node "transport" at path "enqueue" must be configured.');
3533

3634
$configuration = new Configuration([]);
3735

@@ -59,10 +57,8 @@ public function testThrowExceptionIfFooTransportConfigInvalid()
5957

6058
$processor = new Processor();
6159

62-
$this->setExpectedException(
63-
InvalidConfigurationException::class,
64-
'The path "enqueue.transport.foo.foo_param" cannot contain an empty value, but got null.'
65-
);
60+
$this->expectException(InvalidConfigurationException::class);
61+
$this->expectExceptionMessage('The path "enqueue.transport.foo.foo_param" cannot contain an empty value, but got null.');
6662

6763
$processor->processConfiguration($configuration, [[
6864
'transport' => [
@@ -160,10 +156,8 @@ public function testShouldSetDefaultConfigurationForClient()
160156

161157
public function testThrowExceptionIfRouterTopicIsEmpty()
162158
{
163-
$this->setExpectedException(
164-
InvalidConfigurationException::class,
165-
'The path "enqueue.client.router_topic" cannot contain an empty value, but got "".'
166-
);
159+
$this->expectException(InvalidConfigurationException::class);
160+
$this->expectExceptionMessage('The path "enqueue.client.router_topic" cannot contain an empty value, but got "".');
167161

168162
$configuration = new Configuration([new DefaultTransportFactory()]);
169163

@@ -180,10 +174,8 @@ public function testThrowExceptionIfRouterTopicIsEmpty()
180174

181175
public function testThrowExceptionIfRouterQueueIsEmpty()
182176
{
183-
$this->setExpectedException(
184-
InvalidConfigurationException::class,
185-
'The path "enqueue.client.router_queue" cannot contain an empty value, but got "".'
186-
);
177+
$this->expectException(InvalidConfigurationException::class);
178+
$this->expectExceptionMessage('The path "enqueue.client.router_queue" cannot contain an empty value, but got "".');
187179

188180
$configuration = new Configuration([new DefaultTransportFactory()]);
189181

0 commit comments

Comments
 (0)