From f75654ca581fabb3e3b719f03ace7d3f59a84bc4 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 13:09:22 +0100 Subject: [PATCH] Use createMock() and use import instead of FQCN --- Tests/CacheClearer/ChainCacheClearerTest.php | 3 +- Tests/CacheClearer/Psr6CacheClearerTest.php | 4 +- .../CacheWarmer/CacheWarmerAggregateTest.php | 16 ++------ Tests/Config/FileLocatorTest.php | 5 ++- .../NotTaggedControllerValueResolverTest.php | 9 +++-- .../ServiceValueResolverTest.php | 3 +- Tests/Controller/ArgumentResolverTest.php | 6 +-- .../ContainerControllerResolverTest.php | 6 +-- Tests/Controller/ControllerResolverTest.php | 2 +- Tests/Controller/ErrorControllerTest.php | 4 +- Tests/DataCollector/DumpDataCollectorTest.php | 2 +- .../RequestDataCollectorTest.php | 7 ++-- Tests/DataCollector/TimeDataCollectorTest.php | 3 +- Tests/Debug/TraceableEventDispatcherTest.php | 6 ++- .../LazyLoadingFragmentHandlerTest.php | 9 +++-- ...sterControllerArgumentLocatorsPassTest.php | 17 ++++---- .../ResettableServicePassTest.php | 3 +- .../AddRequestFormatsListenerTest.php | 11 ++---- .../DebugHandlersListenerTest.php | 7 ++-- Tests/EventListener/ErrorListenerTest.php | 8 ++-- Tests/EventListener/ExceptionListenerTest.php | 9 +++-- Tests/EventListener/FragmentListenerTest.php | 7 ++-- .../EventListener/LocaleAwareListenerTest.php | 4 +- Tests/EventListener/LocaleListenerTest.php | 15 ++++--- Tests/EventListener/ProfilerListenerTest.php | 26 +++++-------- Tests/EventListener/ResponseListenerTest.php | 2 +- Tests/EventListener/RouterListenerTest.php | 39 ++++++++++--------- .../EventListener/SaveSessionListenerTest.php | 6 +-- Tests/EventListener/SessionListenerTest.php | 30 +++++++------- Tests/EventListener/SurrogateListenerTest.php | 6 +-- .../EventListener/TestSessionListenerTest.php | 18 ++++----- .../EventListener/TranslatorListenerTest.php | 7 ++-- .../ValidateRequestListenerTest.php | 5 ++- Tests/Fragment/EsiFragmentRendererTest.php | 3 +- Tests/Fragment/FragmentHandlerTest.php | 9 ++--- .../Fragment/HIncludeFragmentRendererTest.php | 3 +- Tests/Fragment/InlineFragmentRendererTest.php | 15 ++++--- .../Fragment/RoutableFragmentRendererTest.php | 3 +- Tests/Fragment/SsiFragmentRendererTest.php | 3 +- Tests/HttpCache/EsiTest.php | 3 +- Tests/HttpCache/HttpCacheTest.php | 10 +++-- Tests/HttpCache/SsiTest.php | 3 +- Tests/HttpClientKernelTest.php | 4 +- Tests/HttpKernelBrowserTest.php | 3 +- Tests/HttpKernelTest.php | 10 +++-- Tests/KernelTest.php | 14 ++++--- 46 files changed, 203 insertions(+), 185 deletions(-) diff --git a/Tests/CacheClearer/ChainCacheClearerTest.php b/Tests/CacheClearer/ChainCacheClearerTest.php index a0b4bd8c41..80c1b576be 100644 --- a/Tests/CacheClearer/ChainCacheClearerTest.php +++ b/Tests/CacheClearer/ChainCacheClearerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\CacheClearer; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer; class ChainCacheClearerTest extends TestCase @@ -41,6 +42,6 @@ public function testInjectClearersInConstructor() protected function getMockClearer() { - return $this->getMockBuilder(\Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface::class)->getMock(); + return $this->createMock(CacheClearerInterface::class); } } diff --git a/Tests/CacheClearer/Psr6CacheClearerTest.php b/Tests/CacheClearer/Psr6CacheClearerTest.php index c7c683428e..0c6f1543ac 100644 --- a/Tests/CacheClearer/Psr6CacheClearerTest.php +++ b/Tests/CacheClearer/Psr6CacheClearerTest.php @@ -19,7 +19,7 @@ class Psr6CacheClearerTest extends TestCase { public function testClearPoolsInjectedInConstructor() { - $pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock(); + $pool = $this->createMock(CacheItemPoolInterface::class); $pool ->expects($this->once()) ->method('clear'); @@ -29,7 +29,7 @@ public function testClearPoolsInjectedInConstructor() public function testClearPool() { - $pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock(); + $pool = $this->createMock(CacheItemPoolInterface::class); $pool ->expects($this->once()) ->method('clear'); diff --git a/Tests/CacheWarmer/CacheWarmerAggregateTest.php b/Tests/CacheWarmer/CacheWarmerAggregateTest.php index cf9493a295..c34cc9c400 100644 --- a/Tests/CacheWarmer/CacheWarmerAggregateTest.php +++ b/Tests/CacheWarmer/CacheWarmerAggregateTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate; +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; class CacheWarmerAggregateTest extends TestCase { @@ -30,7 +31,7 @@ public static function tearDownAfterClass(): void public function testInjectWarmersUsingConstructor() { - $warmer = $this->getCacheWarmerMock(); + $warmer = $this->createMock(CacheWarmerInterface::class); $warmer ->expects($this->once()) ->method('warmUp'); @@ -40,7 +41,7 @@ public function testInjectWarmersUsingConstructor() public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled() { - $warmer = $this->getCacheWarmerMock(); + $warmer = $this->createMock(CacheWarmerInterface::class); $warmer ->expects($this->never()) ->method('isOptional'); @@ -55,7 +56,7 @@ public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarme public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled() { - $warmer = $this->getCacheWarmerMock(); + $warmer = $this->createMock(CacheWarmerInterface::class); $warmer ->expects($this->once()) ->method('isOptional') @@ -67,13 +68,4 @@ public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWa $aggregate = new CacheWarmerAggregate([$warmer]); $aggregate->warmUp(self::$cacheDir); } - - protected function getCacheWarmerMock() - { - $warmer = $this->getMockBuilder(\Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - return $warmer; - } } diff --git a/Tests/Config/FileLocatorTest.php b/Tests/Config/FileLocatorTest.php index d992286752..e70e49e83c 100644 --- a/Tests/Config/FileLocatorTest.php +++ b/Tests/Config/FileLocatorTest.php @@ -13,12 +13,13 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\HttpKernel\KernelInterface; class FileLocatorTest extends TestCase { public function testLocate() { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $kernel = $this->createMock(KernelInterface::class); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') @@ -39,7 +40,7 @@ public function testLocate() */ public function testLocateWithGlobalResourcePath() { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $kernel = $this->createMock(KernelInterface::class); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') diff --git a/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php b/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php index efb7322efa..3cf2f0f185 100644 --- a/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php +++ b/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver; use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentResolver\NotTaggedControllerValueResolver; @@ -55,7 +56,7 @@ public function testDoNotSupportEmptyController() public function testController() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -66,7 +67,7 @@ public function testController() public function testControllerWithATrailingBackSlash() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -77,7 +78,7 @@ public function testControllerWithATrailingBackSlash() public function testControllerWithMethodNameStartUppercase() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -88,7 +89,7 @@ public function testControllerWithMethodNameStartUppercase() public function testControllerNameIsAnArray() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); diff --git a/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php b/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php index 743eefa3e5..69b9511c05 100644 --- a/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php +++ b/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver; @@ -107,7 +108,7 @@ public function testControllerNameIsAnArray() public function testErrorIsTruncated() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Cannot autowire argument $dummy of "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyController::index()": it references class "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyService" but no such service exists.'); $container = new ContainerBuilder(); $container->addCompilerPass(new RegisterControllerArgumentLocatorsPass()); diff --git a/Tests/Controller/ArgumentResolverTest.php b/Tests/Controller/ArgumentResolverTest.php index da521ff204..40638b4fe6 100644 --- a/Tests/Controller/ArgumentResolverTest.php +++ b/Tests/Controller/ArgumentResolverTest.php @@ -177,7 +177,7 @@ public function testGetArgumentWithoutArray() { $this->expectException(\InvalidArgumentException::class); $factory = new ArgumentMetadataFactory(); - $valueResolver = $this->getMockBuilder(ArgumentValueResolverInterface::class)->getMock(); + $valueResolver = $this->createMock(ArgumentValueResolverInterface::class); $resolver = new ArgumentResolver($factory, [$valueResolver]); $valueResolver->expects($this->any())->method('supports')->willReturn(true); @@ -241,7 +241,7 @@ public function testGetSessionArgumentsWithExtendedSession() public function testGetSessionArgumentsWithInterface() { - $session = $this->getMockBuilder(SessionInterface::class)->getMock(); + $session = $this->createMock(SessionInterface::class); $request = Request::create('/'); $request->setSession($session); $controller = [$this, 'controllerWithSessionInterface']; @@ -252,7 +252,7 @@ public function testGetSessionArgumentsWithInterface() public function testGetSessionMissMatchWithInterface() { $this->expectException(\RuntimeException::class); - $session = $this->getMockBuilder(SessionInterface::class)->getMock(); + $session = $this->createMock(SessionInterface::class); $request = Request::create('/'); $request->setSession($session); $controller = [$this, 'controllerWithExtendingSession']; diff --git a/Tests/Controller/ContainerControllerResolverTest.php b/Tests/Controller/ContainerControllerResolverTest.php index 7f4564688c..1c239fc4c0 100644 --- a/Tests/Controller/ContainerControllerResolverTest.php +++ b/Tests/Controller/ContainerControllerResolverTest.php @@ -153,7 +153,7 @@ public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsNam { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); - $container = $this->getMockBuilder(Container::class)->getMock(); + $container = $this->createMock(Container::class); $container->expects($this->once()) ->method('has') ->with(ControllerTestService::class) @@ -177,7 +177,7 @@ public function testExceptionWhenUsingRemovedControllerService() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); - $container = $this->getMockBuilder(Container::class)->getMock(); + $container = $this->createMock(Container::class); $container->expects($this->once()) ->method('has') ->with('app.my_controller') @@ -232,7 +232,7 @@ protected function createControllerResolver(LoggerInterface $logger = null, Cont protected function createMockContainer() { - return $this->getMockBuilder(ContainerInterface::class)->getMock(); + return $this->createMock(ContainerInterface::class); } } diff --git a/Tests/Controller/ControllerResolverTest.php b/Tests/Controller/ControllerResolverTest.php index 834f925c43..2afcfe4b4e 100644 --- a/Tests/Controller/ControllerResolverTest.php +++ b/Tests/Controller/ControllerResolverTest.php @@ -20,7 +20,7 @@ class ControllerResolverTest extends TestCase { public function testGetControllerWithoutControllerParameter() { - $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $logger->expects($this->once())->method('warning')->with('Unable to look for the controller as the "_controller" parameter is missing.'); $resolver = $this->createControllerResolver($logger); diff --git a/Tests/Controller/ErrorControllerTest.php b/Tests/Controller/ErrorControllerTest.php index fadd820ea6..1b3a833578 100644 --- a/Tests/Controller/ErrorControllerTest.php +++ b/Tests/Controller/ErrorControllerTest.php @@ -27,7 +27,7 @@ class ErrorControllerTest extends TestCase */ public function testInvokeController(Request $request, \Exception $exception, int $statusCode, string $content) { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $errorRenderer = new HtmlErrorRenderer(); $controller = new ErrorController($kernel, null, $errorRenderer); $response = $controller($exception); @@ -67,7 +67,7 @@ public function testPreviewController() $_controller = 'error_controller'; $code = 404; - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel ->expects($this->once()) ->method('handle') diff --git a/Tests/DataCollector/DumpDataCollectorTest.php b/Tests/DataCollector/DumpDataCollectorTest.php index a40a482278..c69166bf09 100644 --- a/Tests/DataCollector/DumpDataCollectorTest.php +++ b/Tests/DataCollector/DumpDataCollectorTest.php @@ -62,7 +62,7 @@ public function testDumpWithServerConnection() $data = new Data([[123]]); // Server is up, server dumper is used - $serverDumper = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + $serverDumper = $this->createMock(Connection::class); $serverDumper->expects($this->once())->method('write')->willReturn(true); $collector = new DumpDataCollector(null, null, null, null, $serverDumper); diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index bb29b4ba52..e81a6e5b57 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -21,6 +21,7 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; @@ -203,7 +204,7 @@ public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie( 'sf_redirect' => '{}', ]); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $c = new RequestDataCollector(); $c->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse())); @@ -288,8 +289,8 @@ protected function createResponse() */ protected function injectController($collector, $controller, $request) { - $resolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); - $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock()); + $resolver = $this->createMock(ControllerResolverInterface::class); + $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->createMock(ArgumentResolverInterface::class)); $event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); $collector->onKernelController($event); } diff --git a/Tests/DataCollector/TimeDataCollectorTest.php b/Tests/DataCollector/TimeDataCollectorTest.php index ab231ac4c5..0496f1a3d1 100644 --- a/Tests/DataCollector/TimeDataCollectorTest.php +++ b/Tests/DataCollector/TimeDataCollectorTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Stopwatch\Stopwatch; /** @@ -43,7 +44,7 @@ public function testCollect() $c->collect($request, new Response()); $this->assertEquals(0, $c->getStartTime()); - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $kernel = $this->createMock(KernelInterface::class); $kernel->expects($this->once())->method('getStartTime')->willReturn(123456.0); $c = new TimeDataCollector($kernel); diff --git a/Tests/Debug/TraceableEventDispatcherTest.php b/Tests/Debug/TraceableEventDispatcherTest.php index c4d42ec648..2fb050dafd 100644 --- a/Tests/Debug/TraceableEventDispatcherTest.php +++ b/Tests/Debug/TraceableEventDispatcherTest.php @@ -17,6 +17,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\Stopwatch\Stopwatch; @@ -110,9 +112,9 @@ public function testListenerCanRemoveItselfWhenExecuted() protected function getHttpKernel($dispatcher, $controller) { - $controllerResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); + $controllerResolver = $this->createMock(ControllerResolverInterface::class); $controllerResolver->expects($this->once())->method('getController')->willReturn($controller); - $argumentResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface::class)->getMock(); + $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver->expects($this->once())->method('getArguments')->willReturn([]); return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver); diff --git a/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php b/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php index 493178d470..c8db5e55e9 100644 --- a/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php +++ b/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php @@ -12,22 +12,25 @@ namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler; +use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; class LazyLoadingFragmentHandlerTest extends TestCase { public function testRender() { - $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); + $renderer = $this->createMock(FragmentRendererInterface::class); $renderer->expects($this->once())->method('getName')->willReturn('foo'); $renderer->expects($this->any())->method('render')->willReturn(new Response()); - $requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock(); + $requestStack = $this->createMock(RequestStack::class); $requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/')); - $container = $this->getMockBuilder(\Psr\Container\ContainerInterface::class)->getMock(); + $container = $this->createMock(ContainerInterface::class); $container->expects($this->once())->method('has')->with('foo')->willReturn(true); $container->expects($this->once())->method('get')->willReturn($renderer); diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index 8a65b4ff38..c00e1849fc 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\TypedReference; @@ -27,7 +28,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase { public function testInvalidClass() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -42,7 +43,7 @@ public function testInvalidClass() public function testNoAction() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -57,7 +58,7 @@ public function testNoAction() public function testNoArgument() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "argument" attribute on tag "controller.service_arguments" {"action":"fooAction"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -72,7 +73,7 @@ public function testNoArgument() public function testNoService() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "id" attribute on tag "controller.service_arguments" {"action":"fooAction","argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -87,7 +88,7 @@ public function testNoService() public function testInvalidMethod() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "action" attribute on tag "controller.service_arguments" for service "foo": no public "barAction()" method found on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -102,7 +103,7 @@ public function testInvalidMethod() public function testInvalidArgument() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "controller.service_arguments" tag for service "foo": method "fooAction()" has no "baz" argument on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -197,7 +198,7 @@ public function testSkipSetContainer() public function testExceptionOnNonExistentTypeHint() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClass". Did you forget to add a use statement?'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -211,7 +212,7 @@ public function testExceptionOnNonExistentTypeHint() public function testExceptionOnNonExistentTypeHintDifferentNamespace() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassDifferentNamespaceController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Acme\NonExistentClass".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); diff --git a/Tests/DependencyInjection/ResettableServicePassTest.php b/Tests/DependencyInjection/ResettableServicePassTest.php index b28f90d362..4c110e3a26 100644 --- a/Tests/DependencyInjection/ResettableServicePassTest.php +++ b/Tests/DependencyInjection/ResettableServicePassTest.php @@ -6,6 +6,7 @@ use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; @@ -57,7 +58,7 @@ public function testCompilerPass() public function testMissingMethod() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Tag "kernel.reset" requires the "method" attribute to be set.'); $container = new ContainerBuilder(); $container->register(ResettableService::class) diff --git a/Tests/EventListener/AddRequestFormatsListenerTest.php b/Tests/EventListener/AddRequestFormatsListenerTest.php index 6c4459fc2a..def3831851 100644 --- a/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener; @@ -41,7 +42,7 @@ protected function tearDown(): void public function testIsAnEventSubscriber() { - $this->assertInstanceOf(\Symfony\Component\EventDispatcher\EventSubscriberInterface::class, $this->listener); + $this->assertInstanceOf(EventSubscriberInterface::class, $this->listener); } public function testRegisteredEvent() @@ -66,16 +67,12 @@ public function testSetAdditionalFormats() protected function getRequestMock() { - return $this->getMockBuilder(Request::class)->getMock(); + return $this->createMock(Request::class); } protected function getRequestEventMock(Request $request) { - $event = $this - ->getMockBuilder(RequestEvent::class) - ->disableOriginalConstructor() - ->getMock(); - + $event = $this->createMock(RequestEvent::class); $event->expects($this->any()) ->method('getRequest') ->willReturn($request); diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index fb18d63fbe..8d74b2c0dd 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -35,7 +36,7 @@ class DebugHandlersListenerTest extends TestCase { public function testConfigure() { - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $userHandler = function () {}; $listener = new DebugHandlersListener($userHandler, $logger); $eHandler = new ErrorHandler(); @@ -67,7 +68,7 @@ public function testConfigureForHttpKernelWithNoTerminateWithException() $listener = new DebugHandlersListener(null); $eHandler = new ErrorHandler(); $event = new KernelEvent( - $this->getMockBuilder(HttpKernelInterface::class)->getMock(), + $this->createMock(HttpKernelInterface::class), Request::create('/'), HttpKernelInterface::MASTER_REQUEST ); @@ -91,7 +92,7 @@ public function testConsoleEvent() { $dispatcher = new EventDispatcher(); $listener = new DebugHandlersListener(null); - $app = $this->getMockBuilder(Application::class)->getMock(); + $app = $this->createMock(Application::class); $app->expects($this->once())->method('getHelperSet')->willReturn(new HelperSet()); $command = new Command(__FUNCTION__); $command->setApplication($app); diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index 4428e3d1a6..2cd1091a7f 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -115,9 +115,9 @@ public function provider() public function testSubRequestFormat() { - $listener = new ErrorListener('foo', $this->getMockBuilder(LoggerInterface::class)->getMock()); + $listener = new ErrorListener('foo', $this->createMock(LoggerInterface::class)); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); @@ -135,12 +135,12 @@ public function testSubRequestFormat() public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); - $listener = new ErrorListener('foo', $this->getMockBuilder(LoggerInterface::class)->getMock(), true); + $listener = new ErrorListener('foo', $this->createMock(LoggerInterface::class), true); $dispatcher->addSubscriber($listener); diff --git a/Tests/EventListener/ExceptionListenerTest.php b/Tests/EventListener/ExceptionListenerTest.php index 91ff62d906..6163f5b56e 100644 --- a/Tests/EventListener/ExceptionListenerTest.php +++ b/Tests/EventListener/ExceptionListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -112,9 +113,9 @@ public function provider() public function testSubRequestFormat() { - $listener = new ExceptionListener('foo', $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock()); + $listener = new ExceptionListener('foo', $this->createMock(LoggerInterface::class)); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); @@ -132,12 +133,12 @@ public function testSubRequestFormat() public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); - $listener = new ExceptionListener('foo', $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(), true); + $listener = new ExceptionListener('foo', $this->createMock(LoggerInterface::class), true); $dispatcher->addSubscriber($listener); diff --git a/Tests/EventListener/FragmentListenerTest.php b/Tests/EventListener/FragmentListenerTest.php index e0b857debd..5720420dbf 100644 --- a/Tests/EventListener/FragmentListenerTest.php +++ b/Tests/EventListener/FragmentListenerTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\FragmentListener; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\UriSigner; @@ -52,7 +53,7 @@ public function testOnlyTriggeredIfControllerWasNotDefinedYet() public function testAccessDeniedWithNonSafeMethods() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $request = Request::create('http://example.com/_fragment', 'POST'); $listener = new FragmentListener(new UriSigner('foo')); @@ -63,7 +64,7 @@ public function testAccessDeniedWithNonSafeMethods() public function testAccessDeniedWithWrongSignature() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']); $listener = new FragmentListener(new UriSigner('foo')); @@ -113,6 +114,6 @@ public function testRemovesPathWithControllerNotDefined() private function createRequestEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST) { - return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, $requestType); + return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, $requestType); } } diff --git a/Tests/EventListener/LocaleAwareListenerTest.php b/Tests/EventListener/LocaleAwareListenerTest.php index 0d14e5a987..20c9f9d8c9 100644 --- a/Tests/EventListener/LocaleAwareListenerTest.php +++ b/Tests/EventListener/LocaleAwareListenerTest.php @@ -28,7 +28,7 @@ class LocaleAwareListenerTest extends TestCase protected function setUp(): void { - $this->localeAwareService = $this->getMockBuilder(LocaleAwareInterface::class)->getMock(); + $this->localeAwareService = $this->createMock(LocaleAwareInterface::class); $this->requestStack = new RequestStack(); $this->listener = new LocaleAwareListener(new \ArrayIterator([$this->localeAwareService]), $this->requestStack); } @@ -110,7 +110,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() private function createHttpKernel() { - return $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + return $this->createMock(HttpKernelInterface::class); } private function createRequest($locale) diff --git a/Tests/EventListener/LocaleListenerTest.php b/Tests/EventListener/LocaleListenerTest.php index 705600d70e..186ce43b1d 100644 --- a/Tests/EventListener/LocaleListenerTest.php +++ b/Tests/EventListener/LocaleListenerTest.php @@ -14,11 +14,14 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\LocaleListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\Router; class LocaleListenerTest extends TestCase { @@ -26,7 +29,7 @@ class LocaleListenerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->disableOriginalConstructor()->getMock(); + $this->requestStack = $this->createMock(RequestStack::class); } public function testIsAnEventSubscriber() @@ -70,10 +73,10 @@ public function testLocaleFromRequestAttribute() public function testLocaleSetForRoutingContext() { // the request context is updated - $context = $this->getMockBuilder(\Symfony\Component\Routing\RequestContext::class)->getMock(); + $context = $this->createMock(RequestContext::class); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder(\Symfony\Component\Routing\Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $request = Request::create('/'); @@ -86,10 +89,10 @@ public function testLocaleSetForRoutingContext() public function testRouterResetWithParentRequestOnKernelFinishRequest() { // the request context is updated - $context = $this->getMockBuilder(\Symfony\Component\Routing\RequestContext::class)->getMock(); + $context = $this->createMock(RequestContext::class); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder(\Symfony\Component\Routing\Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $parentRequest = Request::create('/'); @@ -116,6 +119,6 @@ public function testRequestLocaleIsNotOverridden() private function getEvent(Request $request): RequestEvent { - return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST); } } diff --git a/Tests/EventListener/ProfilerListenerTest.php b/Tests/EventListener/ProfilerListenerTest.php index 4b076ef17d..8f7aca2a00 100644 --- a/Tests/EventListener/ProfilerListenerTest.php +++ b/Tests/EventListener/ProfilerListenerTest.php @@ -12,14 +12,18 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\EventListener\ProfilerListener; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Profiler\Profile; +use Symfony\Component\HttpKernel\Profiler\Profiler; class ProfilerListenerTest extends TestCase { @@ -30,27 +34,15 @@ public function testKernelTerminate() { $profile = new Profile('token'); - $profiler = $this->getMockBuilder(\Symfony\Component\HttpKernel\Profiler\Profiler::class) - ->disableOriginalConstructor() - ->getMock(); - + $profiler = $this->createMock(Profiler::class); $profiler->expects($this->once()) ->method('collect') ->willReturn($profile); - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); - - $masterRequest = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class) - ->disableOriginalConstructor() - ->getMock(); - - $subRequest = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class) - ->disableOriginalConstructor() - ->getMock(); - - $response = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Response::class) - ->disableOriginalConstructor() - ->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); + $masterRequest = $this->createMock(Request::class); + $subRequest = $this->createMock(Request::class); + $response = $this->createMock(Response::class); $requestStack = new RequestStack(); $requestStack->push($masterRequest); diff --git a/Tests/EventListener/ResponseListenerTest.php b/Tests/EventListener/ResponseListenerTest.php index 31cfa38477..6c5af2a6dd 100644 --- a/Tests/EventListener/ResponseListenerTest.php +++ b/Tests/EventListener/ResponseListenerTest.php @@ -32,7 +32,7 @@ protected function setUp(): void $listener = new ResponseListener('UTF-8'); $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $this->kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $this->kernel = $this->createMock(HttpKernelInterface::class); } protected function tearDown(): void diff --git a/Tests/EventListener/RouterListenerTest.php b/Tests/EventListener/RouterListenerTest.php index 59e63deea8..cc46fd8db5 100644 --- a/Tests/EventListener/RouterListenerTest.php +++ b/Tests/EventListener/RouterListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -22,9 +23,12 @@ use Symfony\Component\HttpKernel\EventListener\ErrorListener; use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Routing\Exception\NoConfigurationException; +use Symfony\Component\Routing\Matcher\RequestMatcherInterface; +use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\RequestContext; class RouterListenerTest extends TestCase @@ -33,7 +37,7 @@ class RouterListenerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder(RequestStack::class)->disableOriginalConstructor()->getMock(); + $this->requestStack = $this->createMock(RequestStack::class); } /** @@ -41,9 +45,8 @@ protected function setUp(): void */ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort) { - $urlMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\UrlMatcherInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $urlMatcher = $this->createMock(UrlMatcherInterface::class); + $context = new RequestContext(); $context->setHttpPort($defaultHttpPort); $context->setHttpsPort($defaultHttpsPort); @@ -72,7 +75,7 @@ public function getPortData() private function createRequestEventForUri(string $uri): RequestEvent { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create($uri); $request->attributes->set('_controller', null); // Prevents going in to routing process @@ -87,11 +90,11 @@ public function testInvalidMatcher() public function testRequestMatcher() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->once()) ->method('matchRequest') ->with($this->isInstanceOf(Request::class)) @@ -103,11 +106,11 @@ public function testRequestMatcher() public function testSubRequestWithDifferentMethod() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/', 'post'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->any()) ->method('matchRequest') ->with($this->isInstanceOf(Request::class)) @@ -119,7 +122,7 @@ public function testSubRequestWithDifferentMethod() $listener->onKernelRequest($event); // sub-request with another HTTP method - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/', 'get'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); @@ -133,17 +136,17 @@ public function testSubRequestWithDifferentMethod() */ public function testLoggingParameter($parameter, $log, $parameters) { - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->once()) ->method('matchRequest') ->willReturn($parameter); - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $logger->expects($this->once()) ->method('info') ->with($this->equalTo($log), $this->equalTo($parameters)); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/'); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger); @@ -162,7 +165,7 @@ public function testWithBadRequest() { $requestStack = new RequestStack(); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->never())->method('matchRequest'); $dispatcher = new EventDispatcher(); @@ -184,7 +187,7 @@ public function testNoRoutingConfigurationResponse() { $requestStack = new RequestStack(); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher ->expects($this->once()) ->method('matchRequest') @@ -204,12 +207,12 @@ public function testNoRoutingConfigurationResponse() public function testRequestWithBadHost() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $this->expectException(BadRequestHttpException::class); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://bad host %22/'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext()); $listener->onKernelRequest($event); diff --git a/Tests/EventListener/SaveSessionListenerTest.php b/Tests/EventListener/SaveSessionListenerTest.php index 6cdd7476c9..f79b73c5fe 100644 --- a/Tests/EventListener/SaveSessionListenerTest.php +++ b/Tests/EventListener/SaveSessionListenerTest.php @@ -27,7 +27,7 @@ class SaveSessionListenerTest extends TestCase public function testOnlyTriggeredOnMasterRequest() { $listener = new SaveSessionListener(); - $event = $this->getMockBuilder(ResponseEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->createMock(ResponseEvent::class); $event->expects($this->once())->method('isMasterRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); @@ -38,9 +38,9 @@ public function testOnlyTriggeredOnMasterRequest() public function testSessionSaved() { $listener = new SaveSessionListener(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); - $session = $this->getMockBuilder(SessionInterface::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(SessionInterface::class); $session->expects($this->once())->method('isStarted')->willReturn(true); $session->expects($this->once())->method('save'); diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 8131ff2ea1..de1069606b 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -32,7 +32,7 @@ class SessionListenerTest extends TestCase public function testOnlyTriggeredOnMasterRequest() { $listener = $this->getMockForAbstractClass(AbstractSessionListener::class); - $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->createMock(RequestEvent::class); $event->expects($this->once())->method('isMasterRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); @@ -42,12 +42,12 @@ public function testOnlyTriggeredOnMasterRequest() public function testSessionIsSet() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); - $requestStack = $this->getMockBuilder(RequestStack::class)->getMock(); + $requestStack = $this->createMock(RequestStack::class); $requestStack->expects($this->once())->method('getMasterRequest')->willReturn(null); - $sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock(); + $sessionStorage = $this->createMock(NativeSessionStorage::class); $sessionStorage->expects($this->never())->method('setOptions')->with(['cookie_secure' => true]); $container = new Container(); @@ -58,7 +58,7 @@ public function testSessionIsSet() $request = new Request(); $listener = new SessionListener($container); - $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->createMock(RequestEvent::class); $event->expects($this->once())->method('isMasterRequest')->willReturn(true); $event->expects($this->once())->method('getRequest')->willReturn($request); @@ -70,14 +70,14 @@ public function testSessionIsSet() public function testResponseIsPrivateIfSessionStarted() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); $container = new Container(); $container->set('initialized_session', $session); $listener = new SessionListener($container); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); @@ -95,14 +95,14 @@ public function testResponseIsPrivateIfSessionStarted() public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); $container = new Container(); $container->set('initialized_session', $session); $listener = new SessionListener($container); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); @@ -122,7 +122,7 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent() public function testUninitializedSession() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response(); $response->setSharedMaxAge(60); $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); @@ -143,7 +143,7 @@ public function testUninitializedSession() public function testSurrogateMasterRequestIsPublic() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1)); $container = new Container(); @@ -151,7 +151,7 @@ public function testSurrogateMasterRequestIsPublic() $container->set('session', $session); $listener = new SessionListener($container); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $response = new Response(); @@ -182,9 +182,9 @@ public function testSurrogateMasterRequestIsPublic() public function testGetSessionIsCalledOnce() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); - $sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock(); - $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); + $session = $this->createMock(Session::class); + $sessionStorage = $this->createMock(NativeSessionStorage::class); + $kernel = $this->createMock(KernelInterface::class); $sessionStorage->expects($this->once()) ->method('setOptions') diff --git a/Tests/EventListener/SurrogateListenerTest.php b/Tests/EventListener/SurrogateListenerTest.php index e4b8b2d558..fc7e4d83ac 100644 --- a/Tests/EventListener/SurrogateListenerTest.php +++ b/Tests/EventListener/SurrogateListenerTest.php @@ -26,7 +26,7 @@ class SurrogateListenerTest extends TestCase public function testFilterDoesNothingForSubRequests() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); @@ -40,7 +40,7 @@ public function testFilterDoesNothingForSubRequests() public function testFilterWhenThereIsSomeEsiIncludes() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); @@ -54,7 +54,7 @@ public function testFilterWhenThereIsSomeEsiIncludes() public function testFilterWhenThereIsNoEsiIncludes() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response('foo'); $listener = new SurrogateListener(new Esi()); diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index e0a5cc69da..2ec6581694 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -14,9 +14,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener; use Symfony\Component\HttpKernel\EventListener\SessionListener; use Symfony\Component\HttpKernel\EventListener\TestSessionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -42,7 +44,7 @@ class TestSessionListenerTest extends TestCase protected function setUp(): void { - $this->listener = $this->getMockForAbstractClass(\Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener::class); + $this->listener = $this->getMockForAbstractClass(AbstractTestSessionListener::class); $this->session = $this->getSession(); $this->listener->expects($this->any()) ->method('getSession') @@ -95,7 +97,7 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie() $this->sessionIsEmpty(); $this->fixSessionId('456'); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); @@ -114,7 +116,7 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie( $this->sessionIsEmpty(); $this->fixSessionId('456'); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); @@ -145,7 +147,7 @@ public function testUnstartedSessionIsNotSave() public function testDoesNotThrowIfRequestDoesNotHaveASession() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); $this->listener->onKernelResponse($event); @@ -157,7 +159,7 @@ private function filterResponse(Request $request, $type = HttpKernelInterface::M { $request->setSession($this->session); $response = $response ?: new Response(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $event = new ResponseEvent($kernel, $request, $type, $response); $this->listener->onKernelResponse($event); @@ -209,11 +211,7 @@ private function fixSessionId($sessionId) private function getSession() { - $mock = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class) - ->disableOriginalConstructor() - ->getMock(); - - // set return value for getName() + $mock = $this->createMock(Session::class); $mock->expects($this->any())->method('getName')->willReturn('MOCKSESSID'); return $mock; diff --git a/Tests/EventListener/TranslatorListenerTest.php b/Tests/EventListener/TranslatorListenerTest.php index 1fe4d1f2fa..26097696dd 100644 --- a/Tests/EventListener/TranslatorListenerTest.php +++ b/Tests/EventListener/TranslatorListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\TranslatorListener; @@ -30,8 +31,8 @@ class TranslatorListenerTest extends TestCase protected function setUp(): void { - $this->translator = $this->getMockBuilder(LocaleAwareInterface::class)->getMock(); - $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock(); + $this->translator = $this->createMock(LocaleAwareInterface::class); + $this->requestStack = $this->createMock(RequestStack::class); $this->listener = new TranslatorListener($this->translator, $this->requestStack); } @@ -105,7 +106,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() private function createHttpKernel() { - return $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + return $this->createMock(HttpKernelInterface::class); } private function createRequest($locale) diff --git a/Tests/EventListener/ValidateRequestListenerTest.php b/Tests/EventListener/ValidateRequestListenerTest.php index 96b686d91b..d23832d80a 100644 --- a/Tests/EventListener/ValidateRequestListenerTest.php +++ b/Tests/EventListener/ValidateRequestListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; @@ -28,9 +29,9 @@ protected function tearDown(): void public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() { - $this->expectException(\Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException::class); + $this->expectException(ConflictingHeadersException::class); $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED); diff --git a/Tests/Fragment/EsiFragmentRendererTest.php b/Tests/Fragment/EsiFragmentRendererTest.php index c9af77149c..3817f4897e 100644 --- a/Tests/Fragment/EsiFragmentRendererTest.php +++ b/Tests/Fragment/EsiFragmentRendererTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer; +use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\UriSigner; @@ -91,7 +92,7 @@ public function testRenderAltControllerReferenceWithoutSignerThrowsException() private function getInlineStrategy($called = false) { - $inline = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer::class)->disableOriginalConstructor()->getMock(); + $inline = $this->createMock(InlineFragmentRenderer::class); if ($called) { $inline->expects($this->once())->method('render'); diff --git a/Tests/Fragment/FragmentHandlerTest.php b/Tests/Fragment/FragmentHandlerTest.php index fa011c8f29..7ad4f3e704 100644 --- a/Tests/Fragment/FragmentHandlerTest.php +++ b/Tests/Fragment/FragmentHandlerTest.php @@ -13,8 +13,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; +use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; /** * @group time-sensitive @@ -25,10 +27,7 @@ class FragmentHandlerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class) - ->disableOriginalConstructor() - ->getMock() - ; + $this->requestStack = $this->createMock(RequestStack::class); $this->requestStack ->expects($this->any()) ->method('getCurrentRequest') @@ -69,7 +68,7 @@ public function testRender() protected function getHandler($returnValue, $arguments = []) { - $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); + $renderer = $this->createMock(FragmentRendererInterface::class); $renderer ->expects($this->any()) ->method('getName') diff --git a/Tests/Fragment/HIncludeFragmentRendererTest.php b/Tests/Fragment/HIncludeFragmentRendererTest.php index ae1cb15516..665c1d458a 100644 --- a/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer; use Symfony\Component\HttpKernel\UriSigner; +use Symfony\Component\Templating\EngineInterface; use Twig\Environment; use Twig\Loader\ArrayLoader; @@ -86,7 +87,7 @@ public function testRenderWithTwigAndDefaultText() */ public function testRenderWithDefaultTextLegacy() { - $engine = $this->getMockBuilder(\Symfony\Component\Templating\EngineInterface::class)->getMock(); + $engine = $this->createMock(EngineInterface::class); $engine->expects($this->once()) ->method('exists') ->with('default') diff --git a/Tests/Fragment/InlineFragmentRendererTest.php b/Tests/Fragment/InlineFragmentRendererTest.php index c25297dbe4..c70a1ae6f0 100644 --- a/Tests/Fragment/InlineFragmentRendererTest.php +++ b/Tests/Fragment/InlineFragmentRendererTest.php @@ -16,10 +16,13 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\HttpKernel; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -72,7 +75,7 @@ public function testRenderWithTrustedHeaderDisabled() public function testRenderExceptionNoIgnoreErrors() { $this->expectException(\RuntimeException::class); - $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); + $dispatcher = $this->createMock(EventDispatcherInterface::class); $dispatcher->expects($this->never())->method('dispatch'); $strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher); @@ -86,7 +89,7 @@ public function testRenderExceptionIgnoreErrors() $kernel = $this->getKernel($this->throwException($exception)); $request = Request::create('/'); $expectedEvent = new ExceptionEvent($kernel, $request, $kernel::SUB_REQUEST, $exception); - $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); + $dispatcher = $this->createMock(EventDispatcherInterface::class); $dispatcher->expects($this->once())->method('dispatch')->with($expectedEvent, KernelEvents::EXCEPTION); $strategy = new InlineFragmentRenderer($kernel, $dispatcher); @@ -106,7 +109,7 @@ public function testRenderExceptionIgnoreErrorsWithAlt() private function getKernel($returnValue) { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel ->expects($this->any()) ->method('handle') @@ -118,7 +121,7 @@ private function getKernel($returnValue) public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() { - $controllerResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); + $controllerResolver = $this->createMock(ControllerResolverInterface::class); $controllerResolver ->expects($this->once()) ->method('getController') @@ -129,7 +132,7 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() }) ; - $argumentResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface::class)->getMock(); + $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver ->expects($this->once()) ->method('getArguments') @@ -258,7 +261,7 @@ public function testIpAddressOfRangedTrustedProxyIsSetAsRemote() */ private function getKernelExpectingRequest(Request $request, $strict = false) { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel ->expects($this->once()) ->method('handle') diff --git a/Tests/Fragment/RoutableFragmentRendererTest.php b/Tests/Fragment/RoutableFragmentRendererTest.php index 5980284afe..d17643c186 100644 --- a/Tests/Fragment/RoutableFragmentRendererTest.php +++ b/Tests/Fragment/RoutableFragmentRendererTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer; class RoutableFragmentRendererTest extends TestCase { @@ -74,7 +75,7 @@ public function getGenerateFragmentUriDataWithNonScalar() private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false) { - $renderer = $this->getMockForAbstractClass(\Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer::class); + $renderer = $this->getMockForAbstractClass(RoutableFragmentRenderer::class); $r = new \ReflectionObject($renderer); $m = $r->getMethod('generateFragmentUri'); $m->setAccessible(true); diff --git a/Tests/Fragment/SsiFragmentRendererTest.php b/Tests/Fragment/SsiFragmentRendererTest.php index db203f91de..63a92028f4 100644 --- a/Tests/Fragment/SsiFragmentRendererTest.php +++ b/Tests/Fragment/SsiFragmentRendererTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\Fragment\SsiFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Ssi; use Symfony\Component\HttpKernel\UriSigner; @@ -82,7 +83,7 @@ public function testRenderAltControllerReferenceWithoutSignerThrowsException() private function getInlineStrategy($called = false) { - $inline = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer::class)->disableOriginalConstructor()->getMock(); + $inline = $this->createMock(InlineFragmentRenderer::class); if ($called) { $inline->expects($this->once())->method('render'); diff --git a/Tests/HttpCache/EsiTest.php b/Tests/HttpCache/EsiTest.php index 5246721a64..e708c2ae5f 100644 --- a/Tests/HttpCache/EsiTest.php +++ b/Tests/HttpCache/EsiTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpCache\Esi; +use Symfony\Component\HttpKernel\HttpCache\HttpCache; class EsiTest extends TestCase { @@ -222,7 +223,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index 932f46c6ef..d9dd572bf1 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -16,7 +16,9 @@ use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\HttpCache\HttpCache; use Symfony\Component\HttpKernel\HttpCache\Store; +use Symfony\Component\HttpKernel\HttpCache\StoreInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\Kernel; /** * @group time-sensitive @@ -25,7 +27,7 @@ class HttpCacheTest extends HttpCacheTestCase { public function testTerminateDelegatesTerminationOnlyForTerminableInterface() { - $storeMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\StoreInterface::class) + $storeMock = $this->getMockBuilder(StoreInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -37,7 +39,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() $this->assertFalse($kernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface'); // implements TerminableInterface - $kernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class) + $kernelMock = $this->getMockBuilder(Kernel::class) ->disableOriginalConstructor() ->setMethods(['terminate', 'registerBundles', 'registerContainerConfiguration']) ->getMock(); @@ -1488,8 +1490,8 @@ public function testDoesNotCacheOptionsRequest() public function testUsesOriginalRequestForSurrogate() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $store = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\StoreInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); + $store = $this->createMock(StoreInterface::class); $kernel ->expects($this->exactly(2)) diff --git a/Tests/HttpCache/SsiTest.php b/Tests/HttpCache/SsiTest.php index 23c7410a28..157c4d7455 100644 --- a/Tests/HttpCache/SsiTest.php +++ b/Tests/HttpCache/SsiTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpCache\HttpCache; use Symfony\Component\HttpKernel\HttpCache\Ssi; class SsiTest extends TestCase @@ -189,7 +190,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpClientKernelTest.php b/Tests/HttpClientKernelTest.php index 2b904bf9a2..27b3a82e03 100644 --- a/Tests/HttpClientKernelTest.php +++ b/Tests/HttpClientKernelTest.php @@ -24,10 +24,10 @@ public function testHandlePassesMaxRedirectsHttpClientOption() $request = new Request(); $request->attributes->set('http_client_options', ['max_redirects' => 50]); - $response = $this->getMockBuilder(ResponseInterface::class)->getMock(); + $response = $this->createMock(ResponseInterface::class); $response->expects($this->once())->method('getStatusCode')->willReturn(200); - $client = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $client = $this->createMock(HttpClientInterface::class); $client ->expects($this->once()) ->method('request') diff --git a/Tests/HttpKernelBrowserTest.php b/Tests/HttpKernelBrowserTest.php index eab6c5221c..7cd4d52d39 100644 --- a/Tests/HttpKernelBrowserTest.php +++ b/Tests/HttpKernelBrowserTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\HttpKernelBrowser; @@ -31,7 +32,7 @@ public function testDoRequest() $client->request('GET', '/'); $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request'); $this->assertInstanceOf(\Symfony\Component\BrowserKit\Request::class, $client->getInternalRequest()); - $this->assertInstanceOf(\Symfony\Component\HttpFoundation\Request::class, $client->getRequest()); + $this->assertInstanceOf(Request::class, $client->getRequest()); $this->assertInstanceOf(\Symfony\Component\BrowserKit\Response::class, $client->getInternalResponse()); $this->assertInstanceOf(Response::class, $client->getResponse()); diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index 5c954261b6..014dc752c3 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -21,8 +21,10 @@ use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -156,7 +158,7 @@ public function testHandleWhenAListenerReturnsAResponse() public function testHandleWhenNoControllerIsFound() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class); + $this->expectException(NotFoundHttpException::class); $dispatcher = new EventDispatcher(); $kernel = $this->getHttpKernel($dispatcher, false); @@ -315,7 +317,7 @@ public function testVerifyRequestStackPushPopDuringHandle() public function testInconsistentClientIpsOnMasterRequests() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); $request = new Request(); $request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED); $request->server->set('REMOTE_ADDR', '1.1.1.1'); @@ -339,13 +341,13 @@ private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $contr $controller = function () { return new Response('Hello'); }; } - $controllerResolver = $this->getMockBuilder(ControllerResolverInterface::class)->getMock(); + $controllerResolver = $this->createMock(ControllerResolverInterface::class); $controllerResolver ->expects($this->any()) ->method('getController') ->willReturn($controller); - $argumentResolver = $this->getMockBuilder(ArgumentResolverInterface::class)->getMock(); + $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver ->expects($this->any()) ->method('getArguments') diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 570e6f0298..9e48e4274e 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -19,9 +19,11 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; +use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName; @@ -125,7 +127,7 @@ public function testBootInitializesBundlesAndContainer() public function testBootSetsTheContainerToTheBundles() { - $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once()) ->method('setContainer'); @@ -167,7 +169,7 @@ public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce() public function testShutdownCallsShutdownOnAllBundles() { - $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once()) ->method('shutdown'); @@ -179,7 +181,7 @@ public function testShutdownCallsShutdownOnAllBundles() public function testShutdownGivesNullContainerToAllBundles() { - $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->exactly(2)) ->method('setContainer') ->withConsecutive( @@ -202,7 +204,7 @@ public function testHandleCallsHandleOnHttpKernel() $catch = true; $request = new Request(); - $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) + $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() ->getMock(); $httpKernelMock @@ -224,7 +226,7 @@ public function testHandleBootsTheKernel() $catch = true; $request = new Request(); - $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) + $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() ->getMock(); @@ -547,7 +549,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() $this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface'); // implements TerminableInterface - $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) + $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() ->setMethods(['terminate']) ->getMock();