Skip to content

Commit a0d92ea

Browse files
committed
init
0 parents  commit a0d92ea

14 files changed

+776
-0
lines changed

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 queue-interop
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Queue Interoperability
2+
3+
This package could come in handy for everyone who wants to build an implementation and make sure it meets its requirements.
4+
The spec class is nothing special but a Phpunit test case. It has to be extended and the abstract methods are implemented.
5+
After you can use them as tests for your transport. Some of the specs require an interaction with a real broker.
6+
7+
## Example
8+
9+
Here's an example of the spec for Gearman connection factory class:
10+
11+
```php
12+
<?php
13+
14+
namespace Enqueue\Gearman\Tests\Spec;
15+
16+
use Enqueue\Gearman\GearmanConnectionFactory;
17+
use Interop\Queue\Spec\PsrConnectionFactorySpec;
18+
19+
class GearmanConnectionFactoryTest extends PsrConnectionFactorySpec
20+
{
21+
protected function createConnectionFactory()
22+
{
23+
return new GearmanConnectionFactory();
24+
}
25+
}
26+
```
27+
28+
## License
29+
30+
[MIT license](LICENSE)

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "queue-interop/queue-spec",
3+
"type": "library",
4+
"license": "MIT",
5+
"require": {
6+
"queue-interop/queue-interop": "^0.1"
7+
},
8+
"autoload": {
9+
"psr-4": {
10+
"Interop\\Queue\\Spec": "src/"
11+
}
12+
},
13+
"extra": {
14+
"branch-alias": {
15+
"dev-master": "0.5.x-dev"
16+
}
17+
}
18+
}

src/PsrConnectionFactorySpec.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Interop\Queue\Spec;
4+
5+
use Interop\Queue\PsrConnectionFactory;
6+
use Interop\Queue\PsrContext;
7+
use PHPUnit\Framework\TestCase;
8+
9+
abstract class PsrConnectionFactorySpec extends TestCase
10+
{
11+
public function testShouldImplementPsrConnectionFactoryInterface()
12+
{
13+
$this->assertInstanceOf(PsrConnectionFactory::class, $this->createConnectionFactory());
14+
}
15+
16+
public function testShouldReturnContextOnCreateContextMethodCall()
17+
{
18+
$factory = $this->createConnectionFactory();
19+
20+
$this->assertInstanceOf(PsrContext::class, $factory->createContext());
21+
}
22+
23+
/**
24+
* @return PsrConnectionFactory
25+
*/
26+
abstract protected function createConnectionFactory();
27+
}

src/PsrContextSpec.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace Interop\Queue\Spec;
4+
5+
use Interop\Queue\PsrConsumer;
6+
use Interop\Queue\PsrContext;
7+
use Interop\Queue\PsrMessage;
8+
use Interop\Queue\PsrProducer;
9+
use Interop\Queue\PsrQueue;
10+
use Interop\Queue\PsrTopic;
11+
use PHPUnit\Framework\TestCase;
12+
13+
abstract class PsrContextSpec extends TestCase
14+
{
15+
public function testShouldImplementPsrContextInterface()
16+
{
17+
$this->assertInstanceOf(PsrContext::class, $this->createContext());
18+
}
19+
20+
public function testShouldCreateEmptyMessageOnCreateMessageMethodCallWithoutArguments()
21+
{
22+
$context = $this->createContext();
23+
24+
$message = $context->createMessage();
25+
26+
$this->assertInstanceOf(PsrMessage::class, $message);
27+
$this->assertSame('', $message->getBody());
28+
$this->assertSame([], $message->getHeaders());
29+
$this->assertSame([], $message->getProperties());
30+
}
31+
32+
public function testShouldCreateMessageOnCreateMessageMethodCallWithArguments()
33+
{
34+
$context = $this->createContext();
35+
36+
$message = $context->createMessage('theBody', ['foo' => 'fooVal'], ['bar' => 'barVal']);
37+
38+
$this->assertInstanceOf(PsrMessage::class, $message);
39+
$this->assertSame('theBody', $message->getBody());
40+
$this->assertSame(['bar' => 'barVal'], $message->getHeaders());
41+
$this->assertSame(['foo' => 'fooVal'], $message->getProperties());
42+
}
43+
44+
public function testShouldCreateTopicWithGivenName()
45+
{
46+
$context = $this->createContext();
47+
48+
$topic = $context->createTopic('theName');
49+
50+
$this->assertInstanceOf(PsrTopic::class, $topic);
51+
$this->assertSame('theName', $topic->getTopicName());
52+
}
53+
54+
public function testShouldCreateQueueWithGivenName()
55+
{
56+
$context = $this->createContext();
57+
58+
$topic = $context->createTopic('theName');
59+
60+
$this->assertInstanceOf(PsrQueue::class, $topic);
61+
$this->assertSame('theName', $topic->getTopicName());
62+
}
63+
64+
public function testShouldCreateProducerOnCreateProducerMethodCall()
65+
{
66+
$context = $this->createContext();
67+
68+
$producer = $context->createProducer();
69+
70+
$this->assertInstanceOf(PsrProducer::class, $producer);
71+
}
72+
73+
public function testShouldCreateConsumerOnCreateConsumerMethodCall()
74+
{
75+
$context = $this->createContext();
76+
77+
$consumer = $context->createConsumer($context->createQueue('aQueue'));
78+
79+
$this->assertInstanceOf(PsrConsumer::class, $consumer);
80+
}
81+
82+
/**
83+
* @return PsrContext
84+
*/
85+
abstract protected function createContext();
86+
}

src/PsrMessageSpec.php

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?php
2+
3+
namespace Interop\Queue\Spec;
4+
5+
use Interop\Queue\PsrMessage;
6+
use PHPUnit\Framework\TestCase;
7+
8+
abstract class PsrMessageSpec extends TestCase
9+
{
10+
public function testShouldImplementMessageInterface()
11+
{
12+
$this->assertInstanceOf(PsrMessage::class, $this->createMessage());
13+
}
14+
15+
public function testShouldSetRedeliveredToFalseInConstructor()
16+
{
17+
$message = $this->createMessage();
18+
19+
$this->assertFalse($message->isRedelivered());
20+
}
21+
22+
public function testShouldReturnEmptyStringIfNotPreviouslySetOnGetBody()
23+
{
24+
$message = $this->createMessage();
25+
26+
$this->assertSame('', $message->getBody());
27+
}
28+
29+
public function testShouldReturnPreviouslySetBody()
30+
{
31+
$message = $this->createMessage();
32+
33+
$message->setBody('theBody');
34+
35+
$this->assertSame('theBody', $message->getBody());
36+
}
37+
38+
public function testShouldReturnEmptyArrayIfPropertiesNotPreviouslySetOnGetProperties()
39+
{
40+
$message = $this->createMessage();
41+
42+
$this->assertSame([], $message->getProperties());
43+
}
44+
45+
public function testShouldReturnPreviouslySetProperties()
46+
{
47+
$message = $this->createMessage();
48+
49+
$message->setProperties(['foo' => 'fooVal', 'bar' => 'barVal']);
50+
51+
$this->assertSame(['foo' => 'fooVal', 'bar' => 'barVal'], $message->getProperties());
52+
}
53+
54+
public function testShouldReturnPreviouslySetProperty()
55+
{
56+
$message = $this->createMessage();
57+
58+
$message->setProperty('bar', 'barVal');
59+
60+
$this->assertSame(['bar' => 'barVal'], $message->getProperties());
61+
}
62+
63+
public function testShouldReturnSinglePreviouslySetProperty()
64+
{
65+
$message = $this->createMessage();
66+
67+
$this->assertSame(null, $message->getProperty('bar'));
68+
$this->assertSame('default', $message->getProperty('bar', 'default'));
69+
70+
$message->setProperty('bar', 'barVal');
71+
$this->assertSame('barVal', $message->getProperty('bar'));
72+
}
73+
74+
public function testShouldReturnEmptyArrayIfHeadersNotPreviouslySetOnGetHeaders()
75+
{
76+
$message = $this->createMessage();
77+
78+
$this->assertSame([], $message->getHeaders());
79+
}
80+
81+
public function testShouldReturnPreviouslySetHeaders()
82+
{
83+
$message = $this->createMessage();
84+
85+
$message->setHeaders(['foo' => 'fooVal', 'bar' => 'barVal']);
86+
87+
$this->assertSame(['foo' => 'fooVal', 'bar' => 'barVal'], $message->getHeaders());
88+
}
89+
90+
public function testShouldReturnPreviouslySetHeader()
91+
{
92+
$message = $this->createMessage();
93+
94+
$message->setHeader('bar', 'barVal');
95+
96+
$this->assertSame(['bar' => 'barVal'], $message->getHeaders());
97+
}
98+
99+
public function testShouldReturnSinglePreviouslySetHeader()
100+
{
101+
$message = $this->createMessage();
102+
103+
$this->assertSame(null, $message->getHeader('bar'));
104+
$this->assertSame('default', $message->getHeader('bar', 'default'));
105+
106+
$message->setHeader('bar', 'barVal');
107+
$this->assertSame('barVal', $message->getHeader('bar'));
108+
}
109+
110+
public function testShouldReturnFalseIfNotPreviouslySetOnIsRedelivered()
111+
{
112+
$message = $this->createMessage();
113+
114+
$this->assertFalse($message->isRedelivered());
115+
}
116+
117+
public function testShouldReturnPreviouslySetRedelivered()
118+
{
119+
$message = $this->createMessage();
120+
121+
$message->setRedelivered(true);
122+
$this->assertSame(true, $message->isRedelivered());
123+
124+
$message->setRedelivered(false);
125+
$this->assertSame(false, $message->isRedelivered());
126+
}
127+
128+
public function testShouldReturnNullIfNotPreviouslySetCorrelationId()
129+
{
130+
$message = $this->createMessage();
131+
132+
$this->assertNull($message->getCorrelationId());
133+
}
134+
135+
public function testShouldReturnPreviouslySetCorrelationId()
136+
{
137+
$message = $this->createMessage();
138+
$message->setCorrelationId('theCorrelationId');
139+
140+
$this->assertSame('theCorrelationId', $message->getCorrelationId());
141+
}
142+
143+
public function testShouldReturnNullIfNotPreviouslySetMessageId()
144+
{
145+
$message = $this->createMessage();
146+
147+
$this->assertNull($message->getMessageId());
148+
}
149+
150+
public function testShouldReturnPreviouslySetMessageId()
151+
{
152+
$message = $this->createMessage();
153+
$message->setMessageId('theMessageId');
154+
155+
$this->assertSame('theMessageId', $message->getMessageId());
156+
}
157+
158+
public function testShouldReturnNullIfNotPreviouslySetTimestamp()
159+
{
160+
$message = $this->createMessage();
161+
162+
$this->assertNull($message->getTimestamp());
163+
}
164+
165+
public function testShouldReturnPreviouslySetTimestampAsInt()
166+
{
167+
$message = $this->createMessage();
168+
$message->setTimestamp('123');
169+
170+
$this->assertSame(123, $message->getTimestamp());
171+
}
172+
173+
public function testShouldReturnNullIfNotPreviouslySetReplyTo()
174+
{
175+
$message = $this->createMessage();
176+
177+
$this->assertNull($message->getReplyTo());
178+
}
179+
180+
public function testShouldReturnPreviouslySetReplyTo()
181+
{
182+
$message = $this->createMessage();
183+
$message->setReplyTo('theReply');
184+
185+
$this->assertSame('theReply', $message->getReplyTo());
186+
}
187+
188+
/**
189+
* @return PsrMessage
190+
*/
191+
abstract protected function createMessage();
192+
}

0 commit comments

Comments
 (0)