/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Notifier/Tests/Channel/BrowserChannelTest.php
87 строк
4 KB
Christian Flothmann
Merge branch '7.3' into 7.4
05 янв 2026, 11:47
05 янв 2026, 11:47
40b06f5
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Notifier\Tests\Channel; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\Notifier\Channel\BrowserChannel; use Symfony\Component\Notifier\Exception\FlashMessageImportanceMapperException; use Symfony\Component\Notifier\FlashMessage\BootstrapFlashMessageImportanceMapper; use Symfony\Component\Notifier\FlashMessage\DefaultFlashMessageImportanceMapper; use Symfony\Component\Notifier\FlashMessage\FlashMessageImportanceMapperInterface; use Symfony\Component\Notifier\Notification\Notification; use Symfony\Component\Notifier\Recipient\Recipient; /** * @author Ben Roberts <ben@headsnet.com> */ class BrowserChannelTest extends TestCase { #[DataProvider('defaultFlashMessageImportanceDataProvider')] public function testImportanceLevelIsReflectedInFlashMessageType( FlashMessageImportanceMapperInterface $mapper, string $importance, string $expectedFlashMessageType, ) { $session = new Session(new MockArraySessionStorage(), null, new FlashBag()); $browserChannel = $this->buildBrowserChannel($session, $mapper); $notification = new Notification(); $notification->importance($importance); $recipient = new Recipient('hello@example.com'); $browserChannel->notify($notification, $recipient); $this->assertEquals($expectedFlashMessageType, array_key_first($session->getFlashBag()->all())); } public function testUnknownImportanceMappingIsReported() { $session = new Session(new MockArraySessionStorage(), null, new FlashBag()); $browserChannel = $this->buildBrowserChannel($session, new DefaultFlashMessageImportanceMapper()); $notification = new Notification(); $notification->importance('unknown-importance-string'); $recipient = new Recipient('hello@example.com'); $this->expectException(FlashMessageImportanceMapperException::class); $browserChannel->notify($notification, $recipient); } public static function defaultFlashMessageImportanceDataProvider(): array { return [ [new DefaultFlashMessageImportanceMapper(), Notification::IMPORTANCE_URGENT, 'notification'], [new DefaultFlashMessageImportanceMapper(), Notification::IMPORTANCE_HIGH, 'notification'], [new DefaultFlashMessageImportanceMapper(), Notification::IMPORTANCE_MEDIUM, 'notification'], [new DefaultFlashMessageImportanceMapper(), Notification::IMPORTANCE_LOW, 'notification'], [new BootstrapFlashMessageImportanceMapper(), Notification::IMPORTANCE_URGENT, 'danger'], [new BootstrapFlashMessageImportanceMapper(), Notification::IMPORTANCE_HIGH, 'warning'], [new BootstrapFlashMessageImportanceMapper(), Notification::IMPORTANCE_MEDIUM, 'info'], [new BootstrapFlashMessageImportanceMapper(), Notification::IMPORTANCE_LOW, 'success'], ]; } private function buildBrowserChannel(Session $session, FlashMessageImportanceMapperInterface $mapper): BrowserChannel { $request = new Request(); $request->setSession($session); $requestStack = new RequestStack(); $requestStack->push($request); return new BrowserChannel($requestStack, $mapper); } }