Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Notifier] Add notify helper in AbstractController #42418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add tests
  • Loading branch information
ismail1432 committed Aug 7, 2021
commit 2b81864d15e24d6ff933aaf59170d9ca7db7e42a
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ protected function addLink(Request $request, LinkInterface $link): void
/**
* Send a notification via the Notifier.
*
* @param Notification $notification The $notification.
* @param Notification $notification the $notification
*/
protected function notify(Notification $notification): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Notifier;
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
Expand Down Expand Up @@ -78,6 +81,7 @@ public function testSubscribedServices()
'messenger.default_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface',
'security.token_storage' => '?Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface',
'security.csrf.token_manager' => '?Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface',
'notifier' => '?Symfony\\Component\\Notifier\\NotifierInterface',
];

$this->assertEquals($expectedServices, $subscribed, 'Subscribed core services in AbstractController have changed');
Expand Down Expand Up @@ -628,4 +632,30 @@ public function testAddLink()
$this->assertContains($link1, $links);
$this->assertContains($link2, $links);
}

public function testNotify()
{
$notifier = $this->createMock(NotifierInterface::class);
$notifier->expects($this->once())->method('send');

$container = new Container();
$container->set('notifier', $notifier);

$controller = $this->createController();
$controller->setContainer($container);

$controller->notify(new Notification());
}

public function testNotifyThrowErrorIfNotifierIsNotInstalled()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The Notifier is not registered in your application. Try running "composer require symfony/notifier".');

$container = new Container();
$controller = $this->createController();
$controller->setContainer($container);

$controller->notify(new Notification());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.