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