Skip to content

Commit 77b3905

Browse files
committed
add spec for producer
1 parent 51b266c commit 77b3905

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/PsrProducerSpec.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Interop\Queue\Spec;
4+
5+
use Interop\Queue\CompletionListener;
6+
use Interop\Queue\PsrMessage;
7+
use Interop\Queue\PsrProducer;
8+
use PHPUnit\Framework\TestCase;
9+
10+
abstract class PsrProducerSpec extends TestCase
11+
{
12+
public function testShouldImplementPsrContextInterface()
13+
{
14+
$this->assertInstanceOf(PsrProducer::class, $this->createProducer());
15+
}
16+
17+
public function testShouldReturnNullIfCompletionListenerWasNotPreviouslySet()
18+
{
19+
$producer = $this->createProducer();
20+
21+
$this->assertNull($producer->getCompletionListener());
22+
}
23+
24+
public function testShouldReturnPreviouslySetCompletionListener()
25+
{
26+
$completionListener = $this->createMock(CompletionListener::class);
27+
28+
$producer = $this->createProducer();
29+
$producer->setCompletionListener($completionListener);
30+
31+
$this->assertSame($completionListener, $producer->getCompletionListener());
32+
}
33+
34+
public function testShouldAllowResetPreviouslySetCompletionListener()
35+
{
36+
$producer = $this->createProducer();
37+
38+
$producer->setCompletionListener($this->createMock(CompletionListener::class));
39+
40+
// guard
41+
$this->assertNotNull($producer->getCompletionListener());
42+
43+
$producer->setCompletionListener(null);
44+
45+
$this->assertNull($producer->getCompletionListener());
46+
}
47+
48+
public function testShouldReturnDefaultDeliveryDelayIfNotPreviouslySet()
49+
{
50+
$producer = $this->createProducer();
51+
52+
$this->assertSame(PsrMessage::DEFAULT_DELIVERY_DELAY, $producer->getDeliveryDelay());
53+
}
54+
55+
public function testShouldReturnPreviouslySetDeliveryDelay()
56+
{
57+
$producer = $this->createProducer();
58+
59+
$producer->setDeliveryDelay(123.45);
60+
61+
$this->assertSame(123.45, $producer->getDeliveryDelay());
62+
}
63+
64+
/**
65+
* @return PsrProducer
66+
*/
67+
abstract protected function createProducer();
68+
}

0 commit comments

Comments
 (0)