diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php
index 86c6d3940c713..72e3fb0f78920 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php
@@ -29,7 +29,7 @@ class TimedPhpEngineTest extends TestCase
{
public function testThatRenderLogsTime()
{
- $container = $this->getContainer();
+ $container = $this->createMock(Container::class);
$templateNameParser = $this->getTemplateNameParser();
$globalVariables = $this->getGlobalVariables();
$loader = $this->getLoader($this->getStorage());
@@ -48,11 +48,6 @@ public function testThatRenderLogsTime()
$engine->render('index.php');
}
- private function getContainer(): Container
- {
- return $this->createMock(Container::class);
- }
-
private function getTemplateNameParser(): TemplateNameParserInterface
{
$templateReference = $this->createMock(TemplateReferenceInterface::class);
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
index 30b3edf164637..01d586346ad30 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
@@ -65,7 +65,7 @@ public function testHtmlRedirectionIsIntercepted($statusCode, $hasSession)
{
$response = new Response('Some content', $statusCode);
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
$listener->onKernelResponse($event);
@@ -78,7 +78,7 @@ public function testNonHtmlRedirectionIsNotIntercepted()
{
$response = new Response('Some content', '301');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
$listener->onKernelResponse($event);
@@ -92,7 +92,7 @@ public function testToolbarIsInjected()
$response = new Response('
');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -108,7 +108,7 @@ public function testToolbarIsNotInjectedOnNonHtmlContentType()
$response = new Response('');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
$response->headers->set('Content-Type', 'text/xml');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -124,7 +124,7 @@ public function testToolbarIsNotInjectedOnContentDispositionAttachment()
$response = new Response('');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
$response->headers->set('Content-Disposition', 'attachment; filename=test.html');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -140,7 +140,7 @@ public function testToolbarIsNotInjectedOnRedirection($statusCode, $hasSession)
{
$response = new Response('', $statusCode);
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -165,7 +165,7 @@ public function testToolbarIsNotInjectedWhenThereIsNoNoXDebugTokenResponseHeader
{
$response = new Response('');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -181,7 +181,7 @@ public function testToolbarIsNotInjectedWhenOnSubRequest()
$response = new Response('');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -197,7 +197,7 @@ public function testToolbarIsNotInjectedOnIncompleteHtmlResponses()
$response = new Response('Some content
');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -213,7 +213,7 @@ public function testToolbarIsNotInjectedOnXmlHttpRequests()
$response = new Response('');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(true), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(true), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -229,7 +229,7 @@ public function testToolbarIsNotInjectedOnNonHtmlRequests()
$response = new Response('');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json'), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'json'), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);
@@ -242,7 +242,7 @@ public function testXDebugUrlHeader()
$response = new Response();
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $urlGenerator = $this->getUrlGeneratorMock();
+ $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$urlGenerator
->expects($this->once())
->method('generate')
@@ -250,7 +250,7 @@ public function testXDebugUrlHeader()
->willReturn('http://mydomain.com/_profiler/xxxxxxxx')
;
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
$listener->onKernelResponse($event);
@@ -263,7 +263,7 @@ public function testThrowingUrlGenerator()
$response = new Response();
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $urlGenerator = $this->getUrlGeneratorMock();
+ $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$urlGenerator
->expects($this->once())
->method('generate')
@@ -271,7 +271,7 @@ public function testThrowingUrlGenerator()
->willThrowException(new \Exception('foo'))
;
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
$listener->onKernelResponse($event);
@@ -284,7 +284,7 @@ public function testThrowingErrorCleanup()
$response = new Response();
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
- $urlGenerator = $this->getUrlGeneratorMock();
+ $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$urlGenerator
->expects($this->once())
->method('generate')
@@ -292,7 +292,7 @@ public function testThrowingErrorCleanup()
->willThrowException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline"))
;
- $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
+ $event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
$listener->onKernelResponse($event);
@@ -331,14 +331,4 @@ protected function getTwigMock($render = 'WDT')
return $templating;
}
-
- protected function getUrlGeneratorMock()
- {
- return $this->createMock(UrlGeneratorInterface::class);
- }
-
- protected function getKernelMock()
- {
- return $this->createMock(Kernel::class);
- }
}
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php
index 9b43ab5350732..5e746c63bffe3 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php
@@ -21,8 +21,6 @@
use Twig\Loader\SourceContextLoaderInterface;
/**
- * Test for TemplateManager class.
- *
* @author Artur Wielogórski
*/
class TemplateManagerTest extends TestCase
@@ -38,7 +36,7 @@ class TemplateManagerTest extends TestCase
protected $profiler;
/**
- * @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
+ * @var TemplateManager
*/
protected $templateManager;
@@ -46,7 +44,7 @@ protected function setUp(): void
{
parent::setUp();
- $profiler = $this->mockProfiler();
+ $this->profiler = $this->createMock(Profiler::class);
$twigEnvironment = $this->mockTwigEnvironment();
$templates = [
'data_collector.foo' => ['foo', 'FooBundle:Collector:foo'],
@@ -54,7 +52,7 @@ protected function setUp(): void
'data_collector.baz' => ['baz', 'FooBundle:Collector:baz'],
];
- $this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
+ $this->templateManager = new TemplateManager($this->profiler, $twigEnvironment, $templates);
}
public function testGetNameOfInvalidTemplate()
@@ -98,11 +96,6 @@ public function profileHasCollectorCallback($panel)
}
}
- protected function mockProfile()
- {
- return $this->createMock(Profile::class);
- }
-
protected function mockTwigEnvironment()
{
$this->twigEnvironment = $this->createMock(Environment::class);
@@ -121,13 +114,6 @@ protected function mockTwigEnvironment()
return $this->twigEnvironment;
}
-
- protected function mockProfiler()
- {
- $this->profiler = $this->createMock(Profiler::class);
-
- return $this->profiler;
- }
}
class ProfileDummy extends Profile
diff --git a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php
index ce3df1a0ec7bd..280395803c1c2 100644
--- a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php
+++ b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php
@@ -30,7 +30,7 @@ public function testOnConsoleError()
{
$error = new \TypeError('An error occurred');
- $logger = $this->getLogger();
+ $logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('error')
@@ -38,14 +38,14 @@ public function testOnConsoleError()
;
$listener = new ErrorListener($logger);
- $listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $this->getOutput(), $error, new Command('test:run')));
+ $listener->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $this->createMock(OutputInterface::class), $error, new Command('test:run')));
}
public function testOnConsoleErrorWithNoCommandAndNoInputString()
{
$error = new \RuntimeException('An error occurred');
- $logger = $this->getLogger();
+ $logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('error')
@@ -53,12 +53,12 @@ public function testOnConsoleErrorWithNoCommandAndNoInputString()
;
$listener = new ErrorListener($logger);
- $listener->onConsoleError(new ConsoleErrorEvent(new NonStringInput(), $this->getOutput(), $error));
+ $listener->onConsoleError(new ConsoleErrorEvent(new NonStringInput(), $this->createMock(OutputInterface::class), $error));
}
public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog()
{
- $logger = $this->getLogger();
+ $logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('debug')
@@ -71,7 +71,7 @@ public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog()
public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
{
- $logger = $this->getLogger();
+ $logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->never())
->method('debug')
@@ -83,7 +83,7 @@ public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
public function testGetSubscribedEvents()
{
- $this->assertEquals(
+ $this->assertSame(
[
'console.error' => ['onConsoleError', -128],
'console.terminate' => ['onConsoleTerminate', -128],
@@ -94,7 +94,7 @@ public function testGetSubscribedEvents()
public function testAllKindsOfInputCanBeLogged()
{
- $logger = $this->getLogger();
+ $logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->exactly(3))
->method('debug')
@@ -109,7 +109,7 @@ public function testAllKindsOfInputCanBeLogged()
public function testCommandNameIsDisplayedForNonStringableInput()
{
- $logger = $this->getLogger();
+ $logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('debug')
@@ -120,19 +120,9 @@ public function testCommandNameIsDisplayedForNonStringableInput()
$listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255));
}
- private function getLogger()
- {
- return $this->getMockForAbstractClass(LoggerInterface::class);
- }
-
private function getConsoleTerminateEvent(InputInterface $input, $exitCode)
{
- return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->getOutput(), $exitCode);
- }
-
- private function getOutput()
- {
- return $this->createMock(OutputInterface::class);
+ return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->createMock(OutputInterface::class), $exitCode);
}
}
diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php
index 0ea4bb26bfd12..c857ca622380f 100644
--- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php
+++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php
@@ -77,7 +77,7 @@ public function testCreateNamedBuilderWithTypeName()
{
$options = ['a' => '1', 'b' => '2'];
$resolvedOptions = ['a' => '2', 'b' => '3'];
- $resolvedType = $this->getMockResolvedType();
+ $resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
$this->registry->expects($this->once())
->method('getType')
@@ -105,7 +105,7 @@ public function testCreateNamedBuilderFillsDataOption()
$givenOptions = ['a' => '1', 'b' => '2'];
$expectedOptions = array_merge($givenOptions, ['data' => 'DATA']);
$resolvedOptions = ['a' => '2', 'b' => '3', 'data' => 'DATA'];
- $resolvedType = $this->getMockResolvedType();
+ $resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
$this->registry->expects($this->once())
->method('getType')
@@ -132,7 +132,7 @@ public function testCreateNamedBuilderDoesNotOverrideExistingDataOption()
{
$options = ['a' => '1', 'b' => '2', 'data' => 'CUSTOM'];
$resolvedOptions = ['a' => '2', 'b' => '3', 'data' => 'CUSTOM'];
- $resolvedType = $this->getMockResolvedType();
+ $resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
$this->registry->expects($this->once())
->method('getType')
@@ -211,7 +211,7 @@ public function testCreateNamed()
{
$options = ['a' => '1', 'b' => '2'];
$resolvedOptions = ['a' => '2', 'b' => '3'];
- $resolvedType = $this->getMockResolvedType();
+ $resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
$this->registry->expects($this->once())
->method('getType')
@@ -485,9 +485,4 @@ private function getMockFactory(array $methods = [])
->setConstructorArgs([$this->registry])
->getMock();
}
-
- private function getMockResolvedType()
- {
- return $this->createMock(ResolvedFormTypeInterface::class);
- }
}
diff --git a/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php b/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php
index 80c1b576be3e9..80d9796070bc0 100644
--- a/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php
@@ -31,7 +31,7 @@ public static function tearDownAfterClass(): void
public function testInjectClearersInConstructor()
{
- $clearer = $this->getMockClearer();
+ $clearer = $this->createMock(CacheClearerInterface::class);
$clearer
->expects($this->once())
->method('clear');
@@ -39,9 +39,4 @@ public function testInjectClearersInConstructor()
$chainClearer = new ChainCacheClearer([$clearer]);
$chainClearer->clear(self::$cacheDir);
}
-
- protected function getMockClearer()
- {
- return $this->createMock(CacheClearerInterface::class);
- }
}
diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php
index def3831851345..fab9a8a38f607 100644
--- a/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php
@@ -19,8 +19,6 @@
use Symfony\Component\HttpKernel\KernelEvents;
/**
- * Test AddRequestFormatsListener class.
- *
* @author Gildas Quemener
*/
class AddRequestFormatsListenerTest extends TestCase
@@ -47,7 +45,7 @@ public function testIsAnEventSubscriber()
public function testRegisteredEvent()
{
- $this->assertEquals(
+ $this->assertSame(
[KernelEvents::REQUEST => ['onKernelRequest', 100]],
AddRequestFormatsListener::getSubscribedEvents()
);
@@ -55,7 +53,7 @@ public function testRegisteredEvent()
public function testSetAdditionalFormats()
{
- $request = $this->getRequestMock();
+ $request = $this->createMock(Request::class);
$event = $this->getRequestEventMock($request);
$request->expects($this->once())
@@ -65,11 +63,6 @@ public function testSetAdditionalFormats()
$this->listener->onKernelRequest($event);
}
- protected function getRequestMock()
- {
- return $this->createMock(Request::class);
- }
-
protected function getRequestEventMock(Request $request)
{
$event = $this->createMock(RequestEvent::class);
diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php
index 20c9f9d8c9e44..ab92a7916877e 100644
--- a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php
@@ -40,7 +40,7 @@ public function testLocaleIsSetInOnKernelRequest()
->method('setLocale')
->with($this->equalTo('fr'));
- $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
+ $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
@@ -57,7 +57,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
$this->throwException(new \InvalidArgumentException())
);
- $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
+ $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
@@ -71,7 +71,7 @@ public function testLocaleIsSetInOnKernelFinishRequestWhenParentRequestExists()
$this->requestStack->push($this->createRequest('fr'));
$this->requestStack->push($subRequest = $this->createRequest('de'));
- $event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST);
+ $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
@@ -84,7 +84,7 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo
$this->requestStack->push($subRequest = $this->createRequest('de'));
- $event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST);
+ $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
@@ -104,15 +104,10 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
$this->requestStack->push($this->createRequest('fr'));
$this->requestStack->push($subRequest = $this->createRequest('de'));
- $event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST);
+ $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
- private function createHttpKernel()
- {
- return $this->createMock(HttpKernelInterface::class);
- }
-
private function createRequest($locale)
{
$request = new Request();
diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php
index 26097696dd577..1eb86b7fb99e5 100644
--- a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php
@@ -43,7 +43,7 @@ public function testLocaleIsSetInOnKernelRequest()
->method('setLocale')
->with($this->equalTo('fr'));
- $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
+ $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
@@ -60,7 +60,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
$this->throwException(new \InvalidArgumentException())
);
- $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
+ $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
@@ -72,7 +72,7 @@ public function testLocaleIsSetInOnKernelFinishRequestWhenParentRequestExists()
->with($this->equalTo('fr'));
$this->setMasterRequest($this->createRequest('fr'));
- $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
+ $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
@@ -82,7 +82,7 @@ public function testLocaleIsNotSetInOnKernelFinishRequestWhenParentRequestDoesNo
->expects($this->never())
->method('setLocale');
- $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
+ $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
@@ -100,15 +100,10 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
);
$this->setMasterRequest($this->createRequest('fr'));
- $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
+ $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
- private function createHttpKernel()
- {
- return $this->createMock(HttpKernelInterface::class);
- }
-
private function createRequest($locale)
{
$request = new Request();
diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php
index eb82a596bcfa2..3d6258e2da26b 100644
--- a/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php
+++ b/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationTrustResolverTest.php
@@ -140,8 +140,8 @@ protected function getRememberMeToken()
protected function getResolver()
{
return new AuthenticationTrustResolver(
- 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken',
- 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\RememberMeToken'
+ AnonymousToken::class,
+ RememberMeToken::class
);
}
}
diff --git a/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php b/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php
index cb172d2b5138b..b7e2a411b392d 100644
--- a/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php
+++ b/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php
@@ -24,7 +24,7 @@ class ChainUserProviderTest extends TestCase
{
public function testLoadUserByUsername()
{
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('loadUserByUsername')
@@ -32,12 +32,12 @@ public function testLoadUserByUsername()
->willThrowException(new UsernameNotFoundException('not found'))
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('loadUserByUsername')
->with($this->equalTo('foo'))
- ->willReturn($account = $this->getAccount())
+ ->willReturn($account = $this->createMock(UserInterface::class))
;
$provider = new ChainUserProvider([$provider1, $provider2]);
@@ -47,7 +47,7 @@ public function testLoadUserByUsername()
public function testLoadUserByUsernameThrowsUsernameNotFoundException()
{
$this->expectException(UsernameNotFoundException::class);
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('loadUserByUsername')
@@ -55,7 +55,7 @@ public function testLoadUserByUsernameThrowsUsernameNotFoundException()
->willThrowException(new UsernameNotFoundException('not found'))
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('loadUserByUsername')
@@ -69,14 +69,14 @@ public function testLoadUserByUsernameThrowsUsernameNotFoundException()
public function testRefreshUser()
{
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
->willReturn(false)
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
@@ -89,7 +89,7 @@ public function testRefreshUser()
->willThrowException(new UnsupportedUserException('unsupported'))
;
- $provider3 = $this->getProvider();
+ $provider3 = $this->createMock(UserProviderInterface::class);
$provider3
->expects($this->once())
->method('supportsClass')
@@ -99,16 +99,16 @@ public function testRefreshUser()
$provider3
->expects($this->once())
->method('refreshUser')
- ->willReturn($account = $this->getAccount())
+ ->willReturn($account = $this->createMock(UserInterface::class))
;
$provider = new ChainUserProvider([$provider1, $provider2, $provider3]);
- $this->assertSame($account, $provider->refreshUser($this->getAccount()));
+ $this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
}
public function testRefreshUserAgain()
{
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
@@ -121,7 +121,7 @@ public function testRefreshUserAgain()
->willThrowException(new UsernameNotFoundException('not found'))
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
@@ -131,17 +131,17 @@ public function testRefreshUserAgain()
$provider2
->expects($this->once())
->method('refreshUser')
- ->willReturn($account = $this->getAccount())
+ ->willReturn($account = $this->createMock(UserInterface::class))
;
$provider = new ChainUserProvider([$provider1, $provider2]);
- $this->assertSame($account, $provider->refreshUser($this->getAccount()));
+ $this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
}
public function testRefreshUserThrowsUnsupportedUserException()
{
$this->expectException(UnsupportedUserException::class);
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
@@ -154,7 +154,7 @@ public function testRefreshUserThrowsUnsupportedUserException()
->willThrowException(new UnsupportedUserException('unsupported'))
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
@@ -168,12 +168,12 @@ public function testRefreshUserThrowsUnsupportedUserException()
;
$provider = new ChainUserProvider([$provider1, $provider2]);
- $provider->refreshUser($this->getAccount());
+ $provider->refreshUser($this->createMock(UserInterface::class));
}
public function testSupportsClass()
{
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
@@ -181,7 +181,7 @@ public function testSupportsClass()
->willReturn(false)
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
@@ -195,7 +195,7 @@ public function testSupportsClass()
public function testSupportsClassWhenNotSupported()
{
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
@@ -203,7 +203,7 @@ public function testSupportsClassWhenNotSupported()
->willReturn(false)
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
@@ -217,7 +217,7 @@ public function testSupportsClassWhenNotSupported()
public function testAcceptsTraversable()
{
- $provider1 = $this->getProvider();
+ $provider1 = $this->createMock(UserProviderInterface::class);
$provider1
->expects($this->once())
->method('supportsClass')
@@ -230,7 +230,7 @@ public function testAcceptsTraversable()
->willThrowException(new UnsupportedUserException('unsupported'))
;
- $provider2 = $this->getProvider();
+ $provider2 = $this->createMock(UserProviderInterface::class);
$provider2
->expects($this->once())
->method('supportsClass')
@@ -240,11 +240,11 @@ public function testAcceptsTraversable()
$provider2
->expects($this->once())
->method('refreshUser')
- ->willReturn($account = $this->getAccount())
+ ->willReturn($account = $this->createMock(UserInterface::class))
;
$provider = new ChainUserProvider(new \ArrayObject([$provider1, $provider2]));
- $this->assertSame($account, $provider->refreshUser($this->getAccount()));
+ $this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
}
public function testPasswordUpgrades()
@@ -268,14 +268,4 @@ public function testPasswordUpgrades()
$provider = new ChainUserProvider([$provider1, $provider2]);
$provider->upgradePassword($user, 'foobar');
}
-
- protected function getAccount()
- {
- return $this->createMock(UserInterface::class);
- }
-
- protected function getProvider()
- {
- return $this->createMock(UserProviderInterface::class);
- }
}
diff --git a/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php b/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
index 7c2d93ada1b24..5fc9ba0eae713 100644
--- a/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
+++ b/src/Symfony/Component/Security/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
@@ -54,7 +54,7 @@ protected function setUp(): void
{
$user = $this->createUser();
$this->tokenStorage = $this->createTokenStorage($user);
- $this->encoder = $this->createPasswordEncoder();
+ $this->encoder = $this->createMock(PasswordEncoderInterface::class);
$this->encoderFactory = $this->createEncoderFactory($this->encoder);
parent::setUp();
@@ -147,11 +147,6 @@ protected function createUser()
return $mock;
}
- protected function createPasswordEncoder($isPasswordValid = true)
- {
- return $this->createMock(PasswordEncoderInterface::class);
- }
-
protected function createEncoderFactory($encoder = null)
{
$mock = $this->createMock(EncoderFactoryInterface::class);
diff --git a/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php b/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php
index 94ff9228bca29..69953ae6fd14e 100644
--- a/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php
+++ b/src/Symfony/Component/Security/Http/Tests/Session/SessionAuthenticationStrategyTest.php
@@ -25,7 +25,7 @@ public function testSessionIsNotChanged()
$request->expects($this->never())->method('getSession');
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE);
- $strategy->onAuthentication($request, $this->getToken());
+ $strategy->onAuthentication($request, $this->createMock(TokenInterface::class));
}
public function testUnsupportedStrategy()
@@ -36,7 +36,7 @@ public function testUnsupportedStrategy()
$request->expects($this->never())->method('getSession');
$strategy = new SessionAuthenticationStrategy('foo');
- $strategy->onAuthentication($request, $this->getToken());
+ $strategy->onAuthentication($request, $this->createMock(TokenInterface::class));
}
public function testSessionIsMigrated()
@@ -45,7 +45,7 @@ public function testSessionIsMigrated()
$session->expects($this->once())->method('migrate')->with($this->equalTo(true));
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
- $strategy->onAuthentication($this->getRequest($session), $this->getToken());
+ $strategy->onAuthentication($this->getRequest($session), $this->createMock(TokenInterface::class));
}
public function testSessionIsInvalidated()
@@ -54,7 +54,7 @@ public function testSessionIsInvalidated()
$session->expects($this->once())->method('invalidate');
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::INVALIDATE);
- $strategy->onAuthentication($this->getRequest($session), $this->getToken());
+ $strategy->onAuthentication($this->getRequest($session), $this->createMock(TokenInterface::class));
}
private function getRequest($session = null)
@@ -67,9 +67,4 @@ private function getRequest($session = null)
return $request;
}
-
- private function getToken()
- {
- return $this->createMock(TokenInterface::class);
- }
}
diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php
index bc6aab8a34bf4..6bba637a9b73a 100644
--- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php
+++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/FilesLoaderTest.php
@@ -20,13 +20,13 @@ class FilesLoaderTest extends TestCase
{
public function testCallsGetFileLoaderInstanceForeachPath()
{
- $loader = $this->getFilesLoader($this->getFileLoader());
+ $loader = $this->getFilesLoader($this->createMock(LoaderInterface::class));
$this->assertEquals(4, $loader->getTimesCalled());
}
public function testCallsActualFileLoaderForMetadata()
{
- $fileLoader = $this->getFileLoader();
+ $fileLoader = $this->createMock(LoaderInterface::class);
$fileLoader->expects($this->exactly(4))
->method('loadClassMetadata');
$loader = $this->getFilesLoader($fileLoader);
@@ -42,9 +42,4 @@ public function getFilesLoader(LoaderInterface $loader)
__DIR__.'/constraint-mapping.txt',
], $loader]);
}
-
- public function getFileLoader()
- {
- return $this->createMock(LoaderInterface::class);
- }
}