Skip to content

Commit a00d619

Browse files
committed
[amqp] add spec tests
1 parent dd4dceb commit a00d619

8 files changed

Lines changed: 266 additions & 2 deletions

‎pkg/amqp-ext/AmqpConnectionFactory.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private function parseDsn($dsn)
150150
], $dsnConfig);
151151

152152
if ('amqp' !== $dsnConfig['scheme']) {
153-
throw new \LogicException('The given DSN scheme "%s" is not supported. Could be "amqp" only.');
153+
throw new \LogicException(sprintf('The given DSN scheme "%s" is not supported. Could be "amqp" only.', $dsnConfig['scheme']));
154154
}
155155

156156
if ($dsnConfig['query']) {

‎pkg/amqp-ext/Tests/AmqpConnectionFactoryConfigTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testThrowNeitherArrayStringNorNullGivenAsConfig()
2424
public function testThrowIfSchemeIsNotAmqp()
2525
{
2626
$this->expectException(\LogicException::class);
27-
$this->expectExceptionMessage('The given DSN scheme "%s" is not supported. Could be "amqp" only.');
27+
$this->expectExceptionMessage('The given DSN scheme "http" is not supported. Could be "amqp" only.');
2828

2929
new AmqpConnectionFactory('http://example.com');
3030
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Enqueue\AmqpExt\Tests\Spec;
4+
5+
use Enqueue\AmqpExt\AmqpConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\Psr\PsrContext;
8+
use Enqueue\Psr\Spec\SendToAndReceiveFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class AmqpSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new AmqpConnectionFactory(getenv('AMQP_DSN'));
21+
22+
return $factory->createContext();
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param AmqpContext $context
29+
*/
30+
protected function createQueue(PsrContext $context, $queueName)
31+
{
32+
$queue = $context->createQueue($queueName);
33+
$context->declareQueue($queue);
34+
$context->purge($queue);
35+
36+
return $queue;
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Enqueue\AmqpExt\Tests\Spec;
4+
5+
use Enqueue\AmqpExt\AmqpConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\Psr\PsrContext;
8+
use Enqueue\Psr\Spec\SendToAndReceiveFromTopicSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class AmqpSendToAndReceiveFromTopicTest extends SendToAndReceiveFromTopicSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new AmqpConnectionFactory(getenv('AMQP_DSN'));
21+
22+
return $factory->createContext();
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param AmqpContext $context
29+
*/
30+
protected function createTopic(PsrContext $context, $topicName)
31+
{
32+
$topic = $context->createTopic($topicName);
33+
$topic->setType(\AMQP_EX_TYPE_FANOUT);
34+
$topic->addFlag(\AMQP_DURABLE);
35+
$context->declareTopic($topic);
36+
37+
return $topic;
38+
}
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Enqueue\AmqpExt\Tests\Spec;
4+
5+
use Enqueue\AmqpExt\AmqpConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\Psr\PsrContext;
8+
use Enqueue\Psr\Spec\SendToAndReceiveNoWaitFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class AmqpSendToAndReceiveNoWaitFromQueueTest extends SendToAndReceiveNoWaitFromQueueSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new AmqpConnectionFactory(getenv('AMQP_DSN'));
21+
22+
return $factory->createContext();
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param AmqpContext $context
29+
*/
30+
protected function createQueue(PsrContext $context, $queueName)
31+
{
32+
$queue = $context->createQueue($queueName);
33+
$context->declareQueue($queue);
34+
$context->purge($queue);
35+
36+
return $queue;
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Enqueue\AmqpExt\Tests\Spec;
4+
5+
use Enqueue\AmqpExt\AmqpConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\Psr\PsrContext;
8+
use Enqueue\Psr\Spec\SendToAndReceiveNoWaitFromTopicSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class AmqpSendToAndReceiveNoWaitFromTopicTest extends SendToAndReceiveNoWaitFromTopicSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new AmqpConnectionFactory(getenv('AMQP_DSN'));
21+
22+
return $factory->createContext();
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param AmqpContext $context
29+
*/
30+
protected function createTopic(PsrContext $context, $topicName)
31+
{
32+
$topic = $context->createTopic($topicName);
33+
$topic->setType(\AMQP_EX_TYPE_FANOUT);
34+
$topic->addFlag(\AMQP_DURABLE);
35+
$context->declareTopic($topic);
36+
37+
return $topic;
38+
}
39+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Enqueue\AmqpExt\Tests\Spec;
4+
5+
use Enqueue\AmqpExt\AmqpConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\Psr\PsrContext;
8+
use Enqueue\Psr\Spec\SendToTopicAndReceiveFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class AmqpSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new AmqpConnectionFactory(getenv('AMQP_DSN'));
21+
22+
return $factory->createContext();
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param AmqpContext $context
29+
*/
30+
protected function createQueue(PsrContext $context, $queueName)
31+
{
32+
$queue = $context->createQueue($queueName);
33+
$context->declareQueue($queue);
34+
$context->purge($queue);
35+
36+
$context->bind($context->createTopic($queueName), $queue);
37+
38+
return $queue;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*
44+
* @param AmqpContext $context
45+
*/
46+
protected function createTopic(PsrContext $context, $topicName)
47+
{
48+
$topic = $context->createTopic($topicName);
49+
$topic->setType(\AMQP_EX_TYPE_FANOUT);
50+
$topic->addFlag(\AMQP_DURABLE);
51+
$context->declareTopic($topic);
52+
53+
return $topic;
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Enqueue\AmqpExt\Tests\Spec;
4+
5+
use Enqueue\AmqpExt\AmqpConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\Psr\PsrContext;
8+
use Enqueue\Psr\Spec\SendToTopicAndReceiveNoWaitFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class AmqpSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiveNoWaitFromQueueSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new AmqpConnectionFactory(getenv('AMQP_DSN'));
21+
22+
return $factory->createContext();
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*
28+
* @param AmqpContext $context
29+
*/
30+
protected function createQueue(PsrContext $context, $queueName)
31+
{
32+
$queue = $context->createQueue($queueName);
33+
$context->declareQueue($queue);
34+
$context->purge($queue);
35+
36+
$context->bind($context->createTopic($queueName), $queue);
37+
38+
return $queue;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*
44+
* @param AmqpContext $context
45+
*/
46+
protected function createTopic(PsrContext $context, $topicName)
47+
{
48+
$topic = $context->createTopic($topicName);
49+
$topic->setType(\AMQP_EX_TYPE_FANOUT);
50+
$topic->addFlag(\AMQP_DURABLE);
51+
$context->declareTopic($topic);
52+
53+
return $topic;
54+
}
55+
}

0 commit comments

Comments
 (0)