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

Commit

Permalink
Merge 3.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Dec 24, 2017
2 parents e6067cb + caa8176 commit 97d58e1
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Api/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function postMessageAction(Request $request)

$view = FOSRestView::create($message);

if (class_exists('FOS\RestBundle\Context\Context')) {
if (class_exists(Context::class)) {
$serializationContext = new Context();
if (method_exists($serializationContext, 'enableMaxDepth')) {
$serializationContext->enableMaxDepth();
Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/Compiler/NotificationCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sonata\NotificationBundle\DependencyInjection\Compiler;

use Sonata\NotificationBundle\Event\IterateEvent;
use Sonata\NotificationBundle\Event\IterationListener;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function process(ContainerBuilder $container): void
/*
* NEXT_MAJOR: Remove check for ServiceClosureArgument and the addListenerService method call.
*/
if (class_exists('Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument')) {
if (class_exists(ServiceClosureArgument::class)) {
$definition->addMethodCall(
'addListener',
[
Expand Down Expand Up @@ -89,7 +90,7 @@ public function process(ContainerBuilder $container): void
$definition = $container->getDefinition($serviceId);

$class = new \ReflectionClass($definition->getClass());
if (!$class->implementsInterface('Sonata\NotificationBundle\Event\IterationListener')) {
if (!$class->implementsInterface(IterationListener::class)) {
throw new RuntimeException(
'Iteration listeners must implement Sonata\NotificationBundle\Event\IterationListener'
);
Expand Down
9 changes: 6 additions & 3 deletions src/DependencyInjection/SonataNotificationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
namespace Sonata\NotificationBundle\DependencyInjection;

use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector;
use Sonata\NotificationBundle\Backend\AMQPBackend;
use Sonata\NotificationBundle\Backend\MessageManagerBackend;
use Sonata\NotificationBundle\Model\MessageInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
Expand All @@ -42,7 +45,7 @@ public function load(array $configs, ContainerBuilder $container): void
/*
* NEXT_MAJOR: Remove the check for ServiceClosureArgument as well as core_legacy.xml.
*/
if (class_exists('Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument')) {
if (class_exists(ServiceClosureArgument::class)) {
$loader->load('core.xml');
} else {
$loader->load('core_legacy.xml');
Expand Down Expand Up @@ -309,7 +312,7 @@ protected function createDoctrineQueueBackend(ContainerBuilder $container, $mana
$id = 'sonata.notification.backend.doctrine.'.$key;
}

$definition = new Definition('Sonata\NotificationBundle\Backend\MessageManagerBackend', [$manager, $checkLevel, $pause, $maxAge, $batchSize, $types]);
$definition = new Definition(MessageManagerBackend::class, [$manager, $checkLevel, $pause, $maxAge, $batchSize, $types]);
$definition->setPublic(false);

$container->setDefinition($id, $definition);
Expand Down Expand Up @@ -432,7 +435,7 @@ protected function createAMQPBackend(ContainerBuilder $container, $exchange, $na
$id = 'sonata.notification.backend.rabbitmq.'.$this->amqpCounter++;

$definition = new Definition(
'Sonata\NotificationBundle\Backend\AMQPBackend',
AMQPBackend::class,
[
$exchange,
$name,
Expand Down
3 changes: 2 additions & 1 deletion src/SonataNotificationBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Sonata\CoreBundle\Form\FormHelper;
use Sonata\NotificationBundle\DependencyInjection\Compiler\NotificationCompilerPass;
use Sonata\NotificationBundle\Form\Type\MessageSerializationType;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand Down Expand Up @@ -49,7 +50,7 @@ public function boot(): void
public function registerFormMapping(): void
{
FormHelper::registerFormTypeMapping([
'sonata_notification_api_form_message' => 'Sonata\NotificationBundle\Form\Type\MessageSerializationType',
'sonata_notification_api_form_message' => MessageSerializationType::class,
]);
}
}
3 changes: 2 additions & 1 deletion tests/Backend/AMQPBackendDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Interop\Amqp\AmqpContext;
use MyProject\Proxies\__CG__\stdClass;
use PHPUnit\Framework\TestCase;
use Sonata\NotificationBundle\Backend\AMQPBackend;
use Sonata\NotificationBundle\Backend\AMQPBackendDispatcher;
use Sonata\NotificationBundle\Exception\BackendNotFoundException;
use Sonata\NotificationBundle\Tests\Mock\AmqpConnectionFactoryStub;
Expand Down Expand Up @@ -180,7 +181,7 @@ protected function getMockQueue($queue, $type, $called = null)
{
$methods = ['createAndPublish', 'initialize'];
$args = ['', 'foo', false, 'message.type.foo'];
$mock = $this->getMockBuilder('Sonata\NotificationBundle\Backend\AMQPBackend')
$mock = $this->getMockBuilder(AMQPBackend::class)
->setConstructorArgs($args)
->setMethods($methods)
->getMock();
Expand Down
5 changes: 3 additions & 2 deletions tests/Backend/BackendHealthCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

use PHPUnit\Framework\TestCase;
use Sonata\NotificationBundle\Backend\BackendHealthCheck;
use Sonata\NotificationBundle\Backend\BackendInterface;
use ZendDiagnostics\Result\Success;

class BackendHealthCheckTest extends TestCase
{
public function setUp(): void
{
if (!class_exists('ZendDiagnostics\Result\Success')) {
if (!class_exists(Success::class)) {
$this->markTestSkipped('ZendDiagnostics\Result\Success does not exist');
}
}
Expand All @@ -30,7 +31,7 @@ public function testCheck(): void
{
$result = new Success('Test check', 'OK');

$backend = $this->createMock('Sonata\NotificationBundle\Backend\BackendInterface');
$backend = $this->createMock(BackendInterface::class);
$backend->expects($this->once())->method('getStatus')->will($this->returnValue($result));

$health = new BackendHealthCheck($backend);
Expand Down
6 changes: 4 additions & 2 deletions tests/Backend/MessageManagerBackendDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Sonata\NotificationBundle\Tests\Backend;

use PHPUnit\Framework\TestCase;
use Sonata\NotificationBundle\Backend\MessageManagerBackend;
use Sonata\NotificationBundle\Backend\MessageManagerBackendDispatcher;
use Sonata\NotificationBundle\Model\Message;
use Sonata\NotificationBundle\Model\MessageManagerInterface;

/**
* @author Hugo Briand <briand@ekino.com>
Expand All @@ -24,7 +26,7 @@ class MessageManagerBackendDispatcherTest extends TestCase
{
public function testCreate(): void
{
$testBackend = $this->createMock('Sonata\NotificationBundle\Backend\MessageManagerBackend');
$testBackend = $this->createMock(MessageManagerBackend::class);

$testBackend->expects($this->once())
->method('setDispatcher')
Expand All @@ -39,7 +41,7 @@ public function testCreate(): void
->will($this->returnValue($message))
;

$mMgr = $this->createMock('Sonata\NotificationBundle\Model\MessageManagerInterface');
$mMgr = $this->createMock(MessageManagerInterface::class);

$mMgrBackend = new MessageManagerBackendDispatcher($mMgr, [], '', [['types' => ['test'], 'backend' => $testBackend]]);

Expand Down
22 changes: 12 additions & 10 deletions tests/Backend/MessageManagerBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Sonata\NotificationBundle\Backend\MessageManagerBackend;
use Sonata\NotificationBundle\Exception\HandlingException;
use Sonata\NotificationBundle\Model\MessageInterface;
use Sonata\NotificationBundle\Model\MessageManagerInterface;
use Sonata\NotificationBundle\Tests\Entity\Message;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use ZendDiagnostics\Result\Failure;
use ZendDiagnostics\Result\Success;
use ZendDiagnostics\Result\Warning;
Expand All @@ -27,14 +29,14 @@ class MessageManagerBackendTest extends TestCase
public function testCreateAndPublish(): void
{
$message = new Message();
$modelManager = $this->createMock('Sonata\NotificationBundle\Model\MessageManagerInterface');
$modelManager = $this->createMock(MessageManagerInterface::class);
$modelManager->expects($this->once())->method('save')->will($this->returnValue($message));
$modelManager->expects($this->once())->method('create')->will($this->returnValue($message));

$backend = new MessageManagerBackend($modelManager, []);
$message = $backend->createAndPublish('foo', ['message' => 'salut']);

$this->assertInstanceOf('Sonata\\NotificationBundle\\Model\\MessageInterface', $message);
$this->assertInstanceOf(MessageInterface::class, $message);
$this->assertEquals(MessageInterface::STATE_OPEN, $message->getState());
$this->assertNotNull($message->getCreatedAt());
$this->assertEquals('foo', $message->getType());
Expand All @@ -44,10 +46,10 @@ public function testCreateAndPublish(): void
public function testHandleSuccess(): void
{
$message = new Message();
$modelManager = $this->createMock('Sonata\NotificationBundle\Model\MessageManagerInterface');
$modelManager = $this->createMock(MessageManagerInterface::class);
$modelManager->expects($this->exactly(2))->method('save')->will($this->returnValue($message));

$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects($this->once())->method('dispatch');

$backend = new MessageManagerBackend($modelManager, []);
Expand All @@ -62,10 +64,10 @@ public function testHandleSuccess(): void
public function testHandleError(): void
{
$message = new Message();
$modelManager = $this->createMock('Sonata\NotificationBundle\Model\MessageManagerInterface');
$modelManager = $this->createMock(MessageManagerInterface::class);
$modelManager->expects($this->exactly(2))->method('save')->will($this->returnValue($message));

$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects($this->once())->method('dispatch')->will($this->throwException(new \RuntimeException()));
$backend = new MessageManagerBackend($modelManager, []);

Expand All @@ -76,7 +78,7 @@ public function testHandleError(): void
} catch (HandlingException $e) {
}

$this->assertInstanceOf('Sonata\NotificationBundle\Exception\HandlingException', $e);
$this->assertInstanceOf(HandlingException::class, $e);

$this->assertEquals(MessageInterface::STATE_ERROR, $message->getState());
$this->assertNotNull($message->getCreatedAt());
Expand All @@ -88,11 +90,11 @@ public function testHandleError(): void
*/
public function testStatus($counts, $expectedStatus, $message): void
{
if (!class_exists('ZendDiagnostics\Result\Success')) {
if (!class_exists(Success::class)) {
$this->markTestSkipped('The class ZendDiagnostics\Result\Success does not exist');
}

$modelManager = $this->createMock('Sonata\NotificationBundle\Model\MessageManagerInterface');
$modelManager = $this->createMock(MessageManagerInterface::class);
$modelManager->expects($this->exactly(1))->method('countStates')->will($this->returnValue($counts));

$backend = new MessageManagerBackend($modelManager, [
Expand All @@ -110,7 +112,7 @@ public function testStatus($counts, $expectedStatus, $message): void

public static function statusProvider()
{
if (!class_exists('ZendDiagnostics\Result\Success')) {
if (!class_exists(Success::class)) {
return [[1, 1, 1]];
}

Expand Down
18 changes: 10 additions & 8 deletions tests/Backend/PostponeRuntimeBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Sonata\NotificationBundle\Consumer\ConsumerEventInterface;
use Sonata\NotificationBundle\Model\MessageInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use ZendDiagnostics\Result\Success;

/**
* @covers \Sonata\NotificationBundle\Backend\PostponeRuntimeBackend
Expand All @@ -27,7 +29,7 @@ class PostponeRuntimeBackendTest extends TestCase
public function testIteratorContainsPublishedMessages(): void
{
$backend = new PostponeRuntimeBackend(
$this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'),
$this->createMock(EventDispatcherInterface::class),
true
);

Expand Down Expand Up @@ -55,9 +57,9 @@ public function testIteratorContainsPublishedMessages(): void

public function testNoMessagesOnEvent(): void
{
$backend = $this->getMockBuilder('Sonata\NotificationBundle\Backend\PostponeRuntimeBackend')
$backend = $this->getMockBuilder(PostponeRuntimeBackend::class)
->setMethods(['handle'])
->setConstructorArgs([$this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')])
->setConstructorArgs([$this->createMock(EventDispatcherInterface::class)])
->getMock();

$backend
Expand Down Expand Up @@ -134,24 +136,24 @@ public function testRecursiveMessage(): void

public function testStatusIsOk(): void
{
if (!class_exists('ZendDiagnostics\Result\Success')) {
if (!class_exists(Success::class)) {
$this->markTestSkipped('The class ZendDiagnostics\Result\Success does not exist');
}

$backend = new PostponeRuntimeBackend(
$this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'),
$this->createMock(EventDispatcherInterface::class),
true
);

$status = $backend->getStatus();
$this->assertInstanceOf('ZendDiagnostics\Result\Success', $status);
$this->assertInstanceOf(Success::class, $status);
}

public function testOnCliPublishHandlesDirectly(): void
{
$backend = $this->getMockBuilder('Sonata\NotificationBundle\Backend\PostponeRuntimeBackend')
$backend = $this->getMockBuilder(PostponeRuntimeBackend::class)
->setMethods(['handle'])
->setConstructorArgs([$this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')])
->setConstructorArgs([$this->createMock(EventDispatcherInterface::class)])
->getMock();

$backend
Expand Down
13 changes: 7 additions & 6 deletions tests/Backend/RuntimeBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
use Sonata\NotificationBundle\Exception\HandlingException;
use Sonata\NotificationBundle\Model\MessageInterface;
use Sonata\NotificationBundle\Tests\Entity\Message;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class RuntimeBackendTest extends TestCase
{
public function testCreateAndPublish(): void
{
$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$backend = new RuntimeBackend($dispatcher);
$message = $backend->createAndPublish('foo', ['message' => 'salut']);

$this->assertInstanceOf('Sonata\\NotificationBundle\\Model\\MessageInterface', $message);
$this->assertInstanceOf(MessageInterface::class, $message);

$this->assertEquals(MessageInterface::STATE_DONE, $message->getState());
$this->assertNotNull($message->getCreatedAt());
Expand All @@ -37,7 +38,7 @@ public function testCreateAndPublish(): void

public function testIterator(): void
{
$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$backend = new RuntimeBackend($dispatcher);

$this->assertInstanceOf('Iterator', $backend->getIterator());
Expand All @@ -47,7 +48,7 @@ public function testHandleSuccess(): void
{
$message = new Message();

$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects($this->once())->method('dispatch');

$backend = new RuntimeBackend($dispatcher);
Expand All @@ -62,7 +63,7 @@ public function testHandleError(): void
{
$message = new Message();

$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects($this->once())->method('dispatch')->will($this->throwException(new \RuntimeException()));

$backend = new RuntimeBackend($dispatcher);
Expand All @@ -74,7 +75,7 @@ public function testHandleError(): void
} catch (HandlingException $e) {
}

$this->assertInstanceOf('Sonata\NotificationBundle\Exception\HandlingException', $e);
$this->assertInstanceOf(HandlingException::class, $e);

$this->assertEquals(MessageInterface::STATE_ERROR, $message->getState());
$this->assertNotNull($message->getCreatedAt());
Expand Down
8 changes: 5 additions & 3 deletions tests/Consumer/LoggerConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Sonata\NotificationBundle\Tests\Consumer;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Sonata\NotificationBundle\Consumer\ConsumerEvent;
use Sonata\NotificationBundle\Consumer\LoggerConsumer;
use Sonata\NotificationBundle\Exception\InvalidParameterException;
use Sonata\NotificationBundle\Tests\Entity\Message;

class LoggerConsumerTest extends TestCase
Expand All @@ -28,7 +30,7 @@ class LoggerConsumerTest extends TestCase
*/
public function testProcess($type, $calledType): void
{
$logger = $this->createMock('Psr\Log\LoggerInterface');
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())->method($calledType);

$message = new Message();
Expand Down Expand Up @@ -62,9 +64,9 @@ public function calledTypeProvider()

public function testInvalidType(): void
{
$this->expectException(\Sonata\NotificationBundle\Exception\InvalidParameterException::class);
$this->expectException(InvalidParameterException::class);

$logger = $this->createMock('Psr\Log\LoggerInterface');
$logger = $this->createMock(LoggerInterface::class);

$message = new Message();
$message->setBody([
Expand Down

0 comments on commit 97d58e1

Please sign in to comment.