|
| 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