clean up remaining event mocks
This commit is contained in:
parent
120f3d6a73
commit
f09bd17ba1
@ -16,7 +16,6 @@ use Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||
use Symfony\Component\Templating\Loader\Loader;
|
||||
use Symfony\Component\Templating\Storage\StringStorage;
|
||||
use Symfony\Component\Templating\TemplateNameParserInterface;
|
||||
@ -34,18 +33,15 @@ class TimedPhpEngineTest extends TestCase
|
||||
$globalVariables = $this->getGlobalVariables();
|
||||
$loader = $this->getLoader($this->getStorage());
|
||||
|
||||
$stopwatch = $this->getStopwatch();
|
||||
$stopwatchEvent = $this->getStopwatchEvent();
|
||||
|
||||
$stopwatch->expects($this->once())
|
||||
->method('start')
|
||||
->with('template.php (index.php)', 'template')
|
||||
->willReturn($stopwatchEvent);
|
||||
|
||||
$stopwatchEvent->expects($this->once())->method('stop');
|
||||
$stopwatch = new Stopwatch();
|
||||
|
||||
$engine = new TimedPhpEngine($templateNameParser, $container, $loader, $stopwatch, $globalVariables);
|
||||
$engine->render('index.php');
|
||||
|
||||
$sections = $stopwatch->getSections();
|
||||
|
||||
$this->assertCount(1, $sections);
|
||||
$this->assertCount(1, reset($sections)->getEvents());
|
||||
}
|
||||
|
||||
private function getTemplateNameParser(): TemplateNameParserInterface
|
||||
@ -83,14 +79,4 @@ class TimedPhpEngineTest extends TestCase
|
||||
|
||||
return $loader;
|
||||
}
|
||||
|
||||
private function getStopwatchEvent(): StopwatchEvent
|
||||
{
|
||||
return $this->createMock(StopwatchEvent::class);
|
||||
}
|
||||
|
||||
private function getStopwatch(): Stopwatch
|
||||
{
|
||||
return $this->createMock(Stopwatch::class);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
@ -322,14 +323,7 @@ class GuardAuthenticationListenerTest extends TestCase
|
||||
$this->guardAuthenticatorHandler = $this->createMock(GuardAuthenticatorHandler::class);
|
||||
$this->request = new Request([], [], [], [], [], []);
|
||||
|
||||
$this->event = $this->getMockBuilder(RequestEvent::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getRequest'])
|
||||
->getMock();
|
||||
$this->event
|
||||
->expects($this->any())
|
||||
->method('getRequest')
|
||||
->willReturn($this->request);
|
||||
$this->event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->rememberMeServices = $this->createMock(RememberMeServicesInterface::class);
|
||||
|
@ -45,7 +45,7 @@ class RememberMeListenerTest extends TestCase
|
||||
->method('setToken')
|
||||
;
|
||||
|
||||
$this->assertNull($listener($this->getGetResponseEvent()));
|
||||
$this->assertNull($listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST)));
|
||||
}
|
||||
|
||||
public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet()
|
||||
@ -64,9 +64,7 @@ class RememberMeListenerTest extends TestCase
|
||||
->willReturn(null)
|
||||
;
|
||||
|
||||
$event = $this->getGetResponseEvent();
|
||||
|
||||
$this->assertNull($listener($event));
|
||||
$this->assertNull($listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST)));
|
||||
}
|
||||
|
||||
public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation()
|
||||
@ -99,9 +97,7 @@ class RememberMeListenerTest extends TestCase
|
||||
->willThrowException($exception)
|
||||
;
|
||||
|
||||
$event = $this->getGetResponseEvent($request);
|
||||
|
||||
$listener($event);
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation()
|
||||
@ -134,9 +130,7 @@ class RememberMeListenerTest extends TestCase
|
||||
->willThrowException($exception)
|
||||
;
|
||||
|
||||
$event = $this->getGetResponseEvent();
|
||||
|
||||
$listener($event);
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggersLoginFail()
|
||||
@ -166,9 +160,7 @@ class RememberMeListenerTest extends TestCase
|
||||
->method('authenticate')
|
||||
;
|
||||
|
||||
$event = $this->getGetResponseEvent();
|
||||
|
||||
$listener($event);
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function testOnCoreSecurity()
|
||||
@ -200,9 +192,7 @@ class RememberMeListenerTest extends TestCase
|
||||
->willReturn($token)
|
||||
;
|
||||
|
||||
$event = $this->getGetResponseEvent();
|
||||
|
||||
$listener($event);
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function testSessionStrategy()
|
||||
@ -244,15 +234,13 @@ class RememberMeListenerTest extends TestCase
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
$event = $this->getGetResponseEvent($request);
|
||||
|
||||
$sessionStrategy
|
||||
->expects($this->once())
|
||||
->method('onAuthentication')
|
||||
->willReturn(null)
|
||||
;
|
||||
|
||||
$listener($event);
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function testSessionIsMigratedByDefault()
|
||||
@ -298,9 +286,7 @@ class RememberMeListenerTest extends TestCase
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
$event = $this->getGetResponseEvent($request);
|
||||
|
||||
$listener($event);
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent()
|
||||
@ -332,8 +318,6 @@ class RememberMeListenerTest extends TestCase
|
||||
->willReturn($token)
|
||||
;
|
||||
|
||||
$event = $this->getGetResponseEvent();
|
||||
|
||||
$dispatcher
|
||||
->expects($this->once())
|
||||
->method('dispatch')
|
||||
@ -343,23 +327,7 @@ class RememberMeListenerTest extends TestCase
|
||||
)
|
||||
;
|
||||
|
||||
$listener($event);
|
||||
}
|
||||
|
||||
protected function getGetResponseEvent(Request $request = null): RequestEvent
|
||||
{
|
||||
$request = $request ?? new Request();
|
||||
|
||||
$event = $this->getMockBuilder(RequestEvent::class)
|
||||
->setConstructorArgs([$this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST])
|
||||
->getMock();
|
||||
$event
|
||||
->expects($this->any())
|
||||
->method('getRequest')
|
||||
->willReturn($request)
|
||||
;
|
||||
|
||||
return $event;
|
||||
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST));
|
||||
}
|
||||
|
||||
protected function getListener($withDispatcher = false, $catchExceptions = true, $withSessionStrategy = false)
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Http\Tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\Security\Http\Firewall;
|
||||
@ -68,20 +69,8 @@ class FirewallTest extends TestCase
|
||||
->willReturn([[$first, $second], null, null])
|
||||
;
|
||||
|
||||
$event = $this->getMockBuilder(RequestEvent::class)
|
||||
->setMethods(['hasResponse'])
|
||||
->setConstructorArgs([
|
||||
$this->createMock(HttpKernelInterface::class),
|
||||
$this->createMock(Request::class),
|
||||
HttpKernelInterface::MASTER_REQUEST,
|
||||
])
|
||||
->getMock()
|
||||
;
|
||||
$event
|
||||
->expects($this->once())
|
||||
->method('hasResponse')
|
||||
->willReturn(true)
|
||||
;
|
||||
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST);
|
||||
$event->setResponse(new Response());
|
||||
|
||||
$firewall = new Firewall($map, $this->createMock(EventDispatcherInterface::class));
|
||||
$firewall->onKernelRequest($event);
|
||||
|
@ -71,12 +71,7 @@ class StopwatchTest extends TestCase
|
||||
$events = new \ReflectionProperty(Section::class, 'events');
|
||||
$events->setAccessible(true);
|
||||
|
||||
$stopwatchMockEvent = $this->getMockBuilder(StopwatchEvent::class)
|
||||
->setConstructorArgs([microtime(true) * 1000])
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$events->setValue(end($section), ['foo' => $stopwatchMockEvent]);
|
||||
$events->setValue(end($section), ['foo' => new StopwatchEvent(microtime(true) * 1000)]);
|
||||
|
||||
$this->assertFalse($stopwatch->isStarted('foo'));
|
||||
}
|
||||
|
Reference in New Issue
Block a user