/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php
120 строк
4 KB
Christian Flothmann
Merge branch '8.0' into 8.1
21 дек 2025, 14:11
21 дек 2025, 14:11
9fd3b36
Код
Авторство
О чём код?
<?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\Security\Http\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcherInterface; use Symfony\Component\Security\Http\Firewall\ExceptionListener; use Symfony\Component\Security\Http\FirewallMap; class FirewallMapTest extends TestCase { public function testGetListeners() { $map = new FirewallMap(); $request = new Request(); $notMatchingMatcher = $this->createMock(RequestMatcherInterface::class); $notMatchingMatcher ->expects($this->once()) ->method('matches') ->with($this->equalTo($request)) ->willReturn(false) ; $map->add($notMatchingMatcher, [static function () {}]); $matchingMatcher = $this->createMock(RequestMatcherInterface::class); $matchingMatcher ->expects($this->once()) ->method('matches') ->with($this->equalTo($request)) ->willReturn(true) ; $theListener = static function () {}; $theException = $this->createStub(ExceptionListener::class); $map->add($matchingMatcher, [$theListener], $theException); $tooLateMatcher = $this->createMock(RequestMatcherInterface::class); $tooLateMatcher ->expects($this->never()) ->method('matches') ; $map->add($tooLateMatcher, [static function () {}]); [$listeners, $exception] = $map->getListeners($request); $this->assertEquals([$theListener], $listeners); $this->assertEquals($theException, $exception); } public function testGetListenersWithAnEntryHavingNoRequestMatcher() { $map = new FirewallMap(); $request = new Request(); $notMatchingMatcher = $this->createMock(RequestMatcherInterface::class); $notMatchingMatcher ->expects($this->once()) ->method('matches') ->with($this->equalTo($request)) ->willReturn(false) ; $map->add($notMatchingMatcher, [static function () {}]); $theListener = static function () {}; $theException = $this->createStub(ExceptionListener::class); $map->add(null, [$theListener], $theException); $tooLateMatcher = $this->createMock(RequestMatcherInterface::class); $tooLateMatcher ->expects($this->never()) ->method('matches') ; $map->add($tooLateMatcher, [static function () {}]); [$listeners, $exception] = $map->getListeners($request); $this->assertEquals([$theListener], $listeners); $this->assertEquals($theException, $exception); } public function testGetListenersWithNoMatchingEntry() { $map = new FirewallMap(); $request = new Request(); $notMatchingMatcher = $this->createMock(RequestMatcherInterface::class); $notMatchingMatcher ->expects($this->once()) ->method('matches') ->with($this->equalTo($request)) ->willReturn(false) ; $map->add($notMatchingMatcher, [static function () {}]); [$listeners, $exception] = $map->getListeners($request); $this->assertEquals([], $listeners); $this->assertNull($exception); } }