Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Merge f9ee2a4 into b9de523
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Feb 12, 2020
2 parents b9de523 + f9ee2a4 commit b7e359a
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
.php_cs.cache
composer.lock
phpunit.xml
.phpunit.result.cache
14 changes: 2 additions & 12 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -28,12 +28,7 @@ public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('sonata_notification');

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('sonata_notification')->children();
} else {
$rootNode = $treeBuilder->getRootNode()->children();
}
$rootNode = $treeBuilder->getRootNode()->children();

$backendInfo = <<<'EOF'
Other backends you can use:
Expand Down Expand Up @@ -192,12 +187,7 @@ protected function getQueueNode()
{
$treeBuilder = new TreeBuilder('queues');

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$node = $treeBuilder->root('queues');
} else {
$node = $treeBuilder->getRootNode();
}
$node = $treeBuilder->getRootNode();

$queuesInfo = <<<'EOF'
Example for using RabbitMQ
Expand Down
49 changes: 25 additions & 24 deletions tests/Backend/AMQPBackendDispatcherTest.php
Expand Up @@ -15,6 +15,7 @@

use Enqueue\AmqpLib\AmqpConnectionFactory;
use Interop\Amqp\AmqpContext;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Sonata\NotificationBundle\Backend\AMQPBackend;
use Sonata\NotificationBundle\Backend\AMQPBackendDispatcher;
Expand All @@ -33,7 +34,7 @@ protected function setUp(): void
AmqpConnectionFactoryStub::$context = null;
}

public function testThrowIfSettingsMissFactoryClassOptionOnGetContext()
public function testThrowIfSettingsMissFactoryClassOptionOnGetContext(): void
{
$dispatcher = new AMQPBackendDispatcher([], [], 'default', []);

Expand All @@ -42,7 +43,7 @@ public function testThrowIfSettingsMissFactoryClassOptionOnGetContext()
$dispatcher->getContext();
}

public function testThrowIfFactoryClassIsNotRealClass()
public function testThrowIfFactoryClassIsNotRealClass(): void
{
$dispatcher = new AMQPBackendDispatcher(['factory_class' => 'anInvalidClass'], [], 'default', []);

Expand All @@ -51,7 +52,7 @@ public function testThrowIfFactoryClassIsNotRealClass()
$dispatcher->getContext();
}

public function testThrowIfFactoryClassIsNotInstanceOfAmqpConnectionFactoryInterface()
public function testThrowIfFactoryClassIsNotInstanceOfAmqpConnectionFactoryInterface(): void
{
$dispatcher = new AMQPBackendDispatcher(['factory_class' => \stdClass::class], [], 'default', []);

Expand All @@ -60,7 +61,7 @@ public function testThrowIfFactoryClassIsNotInstanceOfAmqpConnectionFactoryInter
$dispatcher->getContext();
}

public function testShouldPassExpectedOptionsToAmqpConnectionFactoryConstructor()
public function testShouldPassExpectedOptionsToAmqpConnectionFactoryConstructor(): void
{
$dispatcher = new AMQPBackendDispatcher(
[
Expand All @@ -87,7 +88,7 @@ public function testShouldPassExpectedOptionsToAmqpConnectionFactoryConstructor(
], AmqpConnectionFactoryStub::$config);
}

public function testShouldReturnExpectedAmqpContext()
public function testShouldReturnExpectedAmqpContext(): void
{
$expectedContext = $this->createMock(AmqpContext::class);

Expand All @@ -112,7 +113,7 @@ public function testShouldReturnExpectedAmqpContext()
$this->assertSame($expectedContext, $actualContext);
}

public function testQueue()
public function testQueue(): void
{
$mock = $this->getMockQueue('foo', 'message.type.foo', $this->once());
$mock2 = $this->getMockQueue('bar', 'message.type.foo', $this->never());
Expand All @@ -123,15 +124,15 @@ public function testQueue()
$dispatcher->createAndPublish('message.type.foo', []);
}

public function testDefaultQueue()
public function testDefaultQueue(): void
{
$mock = $this->getMockQueue('foo', 'message.type.foo', $this->once());
$fooBackend = ['type' => 'default', 'backend' => $mock];
$dispatcher = $this->getDispatcher([$fooBackend]);
$dispatcher->createAndPublish('some.other.type', []);
}

public function testDefaultQueueNotFound()
public function testDefaultQueueNotFound(): void
{
$mock = $this->getMockQueue('foo', 'message.type.foo', $this->never());
$fooBackend = ['type' => 'message.type.foo', 'backend' => $mock];
Expand All @@ -141,7 +142,7 @@ public function testDefaultQueueNotFound()
$dispatcher->createAndPublish('some.other.type', []);
}

public function testInvalidQueue()
public function testInvalidQueue(): void
{
$mock = $this->getMockQueue('foo', 'message.type.bar');
$dispatcher = $this->getDispatcher(
Expand All @@ -153,7 +154,7 @@ public function testInvalidQueue()
$dispatcher->createAndPublish('message.type.bar', []);
}

public function testAllQueueInitializeOnce()
public function testAllQueueInitializeOnce(): void
{
$queues = [
['queue' => 'foo', 'routing_key' => 'message.type.foo'],
Expand All @@ -176,7 +177,20 @@ public function testAllQueueInitializeOnce()
$dispatcher->createAndPublish('message.type.foo', []);
}

protected function getMockQueue($queue, $type, $called = null)
protected function getDispatcher(array $backends, array $queues = [['queue' => 'foo', 'routing_key' => 'message.type.foo']]): AMQPBackendDispatcher
{
$settings = [
'host' => 'foo',
'port' => 'port',
'user' => 'user',
'pass' => 'pass',
'vhost' => '/',
];

return new AMQPBackendDispatcher($settings, $queues, 'default', $backends);
}

private function getMockQueue($queue, $type, $called = null): MockObject
{
$methods = ['createAndPublish', 'initialize'];
$args = ['', 'foo', false, 'message.type.foo'];
Expand All @@ -193,17 +207,4 @@ protected function getMockQueue($queue, $type, $called = null)

return $mock;
}

protected function getDispatcher(array $backends, array $queues = [['queue' => 'foo', 'routing_key' => 'message.type.foo']])
{
$settings = [
'host' => 'foo',
'port' => 'port',
'user' => 'user',
'pass' => 'pass',
'vhost' => '/',
];

return new AMQPBackendDispatcher($settings, $queues, 'default', $backends);
}
}
17 changes: 7 additions & 10 deletions tests/Backend/AMQPBackendTest.php
Expand Up @@ -49,7 +49,7 @@ protected function setUp(): void
AmqpConnectionFactoryStub::$config = null;
}

public function testInitializeWithNoDeadLetterExchangeAndNoDeadLetterRoutingKey()
public function testInitializeWithNoDeadLetterExchangeAndNoDeadLetterRoutingKey(): void
{
$backend = $this->buildBackend();

Expand Down Expand Up @@ -98,7 +98,7 @@ public function testInitializeWithNoDeadLetterExchangeAndNoDeadLetterRoutingKey(
$backend->initialize();
}

public function testInitializeWithDeadLetterExchangeAndNoDeadLetterRoutingKey()
public function testInitializeWithDeadLetterExchangeAndNoDeadLetterRoutingKey(): void
{
$backend = $this->buildBackend(false, self::DEAD_LETTER_EXCHANGE);

Expand Down Expand Up @@ -152,7 +152,7 @@ public function testInitializeWithDeadLetterExchangeAndNoDeadLetterRoutingKey()
$backend->initialize();
}

public function testInitializeWithDeadLetterExchangeAndDeadLetterRoutingKey()
public function testInitializeWithDeadLetterExchangeAndDeadLetterRoutingKey(): void
{
$backend = $this->buildBackend(false, self::DEAD_LETTER_EXCHANGE, self::DEAD_LETTER_ROUTING_KEY);

Expand Down Expand Up @@ -198,7 +198,7 @@ public function testInitializeWithDeadLetterExchangeAndDeadLetterRoutingKey()
$backend->initialize();
}

public function testInitializeWithTTL()
public function testInitializeWithTTL(): void
{
$backend = $this->buildBackend(false, null, null, self::TTL);

Expand Down Expand Up @@ -237,7 +237,7 @@ public function testInitializeWithTTL()
$backend->initialize();
}

public function testGetIteratorWithNoPrefetchCount()
public function testGetIteratorWithNoPrefetchCount(): void
{
$backend = $this->buildBackend();

Expand Down Expand Up @@ -272,7 +272,7 @@ public function testGetIteratorWithNoPrefetchCount()
$this->assertInstanceOf(AMQPMessageIterator::class, $iterator);
}

public function testGetIteratorWithPrefetchCount()
public function testGetIteratorWithPrefetchCount(): void
{
$backend = $this->buildBackend(false, null, null, null, self::PREFETCH_COUNT);

Expand Down Expand Up @@ -307,10 +307,7 @@ public function testGetIteratorWithPrefetchCount()
$this->assertInstanceOf(AMQPMessageIterator::class, $iterator);
}

/**
* @return AMQPBackend
*/
protected function buildBackend($recover = false, $deadLetterExchange = null, $deadLetterRoutingKey = null, $ttl = null, $prefetchCount = null)
protected function buildBackend($recover = false, $deadLetterExchange = null, $deadLetterRoutingKey = null, $ttl = null, $prefetchCount = null): AMQPBackend
{
$backend = new AMQPBackend(
self::EXCHANGE,
Expand Down
2 changes: 1 addition & 1 deletion tests/Backend/BackendHealthCheckTest.php
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void
}
}

public function testCheck()
public function testCheck(): void
{
$result = new Success('Test check', 'OK');

Expand Down
2 changes: 1 addition & 1 deletion tests/Backend/MessageManagerBackendDispatcherTest.php
Expand Up @@ -24,7 +24,7 @@
*/
class MessageManagerBackendDispatcherTest extends TestCase
{
public function testCreate()
public function testCreate(): void
{
$testBackend = $this->createMock(MessageManagerBackend::class);

Expand Down
12 changes: 6 additions & 6 deletions tests/Backend/MessageManagerBackendTest.php
Expand Up @@ -26,7 +26,7 @@

class MessageManagerBackendTest extends TestCase
{
public function testCreateAndPublish()
public function testCreateAndPublish(): void
{
$message = new Message();
$modelManager = $this->createMock(MessageManagerInterface::class);
Expand All @@ -43,7 +43,7 @@ public function testCreateAndPublish()
$this->assertSame(['message' => 'salut'], $message->getBody());
}

public function testHandleSuccess()
public function testHandleSuccess(): void
{
$message = new Message();
$modelManager = $this->createMock(MessageManagerInterface::class);
Expand All @@ -61,7 +61,7 @@ public function testHandleSuccess()
$this->assertNotNull($message->getCompletedAt());
}

public function testHandleError()
public function testHandleError(): void
{
$message = new Message();
$modelManager = $this->createMock(MessageManagerInterface::class);
Expand All @@ -88,14 +88,14 @@ public function testHandleError()
/**
* @dataProvider statusProvider
*/
public function testStatus($counts, $expectedStatus, $message)
public function testStatus($counts, $expectedStatus, $message): void
{
if (!class_exists(Success::class)) {
$this->markTestSkipped('The class ZendDiagnostics\Result\Success does not exist');
}

$modelManager = $this->createMock(MessageManagerInterface::class);
$modelManager->expects($this->exactly(1))->method('countStates')->willReturn($counts);
$modelManager->expects($this->once())->method('countStates')->willReturn($counts);

$backend = new MessageManagerBackend($modelManager, [
MessageInterface::STATE_IN_PROGRESS => 10,
Expand All @@ -110,7 +110,7 @@ public function testStatus($counts, $expectedStatus, $message)
$this->assertSame($message, $status->getMessage());
}

public static function statusProvider()
public static function statusProvider(): array
{
if (!class_exists(Success::class)) {
return [[1, 1, 1]];
Expand Down
14 changes: 7 additions & 7 deletions tests/Backend/PostponeRuntimeBackendTest.php
Expand Up @@ -26,7 +26,7 @@
*/
class PostponeRuntimeBackendTest extends TestCase
{
public function testIteratorContainsPublishedMessages()
public function testIteratorContainsPublishedMessages(): void
{
$backend = new PostponeRuntimeBackend(
$this->createMock(EventDispatcherInterface::class),
Expand Down Expand Up @@ -55,7 +55,7 @@ public function testIteratorContainsPublishedMessages()
}
}

public function testNoMessagesOnEvent()
public function testNoMessagesOnEvent(): void
{
$backend = $this->getMockBuilder(PostponeRuntimeBackend::class)
->setMethods(['handle'])
Expand All @@ -70,7 +70,7 @@ public function testNoMessagesOnEvent()
$backend->onEvent();
}

public function testLiveEnvironment()
public function testLiveEnvironment(): void
{
$dispatcher = new EventDispatcher();
$backend = new PostponeRuntimeBackend($dispatcher, true);
Expand All @@ -96,7 +96,7 @@ public function testLiveEnvironment()
$this->assertSame(MessageInterface::STATE_DONE, $message->getState());
}

public function testRecursiveMessage()
public function testRecursiveMessage(): void
{
$dispatcher = new EventDispatcher();
$backend = new PostponeRuntimeBackend($dispatcher, true);
Expand All @@ -111,7 +111,7 @@ public function testRecursiveMessage()
$phpunit->passed1 = false;
$phpunit->passed2 = false;

$dispatcher->addListener('notification.demo1', static function (ConsumerEventInterface $event) use ($phpunit, $message1, $message2, $backend, $dispatcher) {
$dispatcher->addListener('notification.demo1', static function (ConsumerEventInterface $event) use ($phpunit, $message1, $message2, $backend) {
$phpunit->assertSame($message1, $event->getMessage());

$phpunit->passed1 = true;
Expand All @@ -134,7 +134,7 @@ public function testRecursiveMessage()
$this->assertSame(MessageInterface::STATE_DONE, $message2->getState());
}

public function testStatusIsOk()
public function testStatusIsOk(): void
{
if (!class_exists(Success::class)) {
$this->markTestSkipped('The class ZendDiagnostics\Result\Success does not exist');
Expand All @@ -149,7 +149,7 @@ public function testStatusIsOk()
$this->assertInstanceOf(Success::class, $status);
}

public function testOnCliPublishHandlesDirectly()
public function testOnCliPublishHandlesDirectly(): void
{
$backend = $this->getMockBuilder(PostponeRuntimeBackend::class)
->setMethods(['handle'])
Expand Down

0 comments on commit b7e359a

Please sign in to comment.