From 69fcd075eb641b5a24b2ecfed9632f578006df57 Mon Sep 17 00:00:00 2001 From: Alexandre Parent Date: Thu, 21 Jan 2021 09:05:34 -0500 Subject: [PATCH 1/5] Fix console logger according to PSR-3 --- src/Symfony/Component/Console/EventListener/ErrorListener.php | 4 ++-- .../Console/Tests/EventListener/ErrorListenerTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/EventListener/ErrorListener.php b/src/Symfony/Component/Console/EventListener/ErrorListener.php index a34075793e..897d9853f2 100644 --- a/src/Symfony/Component/Console/EventListener/ErrorListener.php +++ b/src/Symfony/Component/Console/EventListener/ErrorListener.php @@ -40,12 +40,12 @@ class ErrorListener implements EventSubscriberInterface $error = $event->getError(); if (!$inputString = $this->getInputString($event)) { - $this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); + $this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]); return; } - $this->logger->error('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); + $this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]); } public function onConsoleTerminate(ConsoleTerminateEvent $event) diff --git a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php index 68b4b3a3e1..0b9fb4d367 100644 --- a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php +++ b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php @@ -33,7 +33,7 @@ class ErrorListenerTest extends TestCase $logger = $this->getLogger(); $logger ->expects($this->once()) - ->method('error') + ->method('critical') ->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred']) ; @@ -48,7 +48,7 @@ class ErrorListenerTest extends TestCase $logger = $this->getLogger(); $logger ->expects($this->once()) - ->method('error') + ->method('critical') ->with('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => 'An error occurred']) ; From adb0fd1c7dcfc5c6332223f677173da5a7d5fad4 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 27 Jan 2021 21:50:32 +0100 Subject: [PATCH 2/5] take into account all label related options --- .../Bridge/Twig/Extension/FormExtension.php | 12 +++++++++++- .../Extension/FormExtensionFieldHelpersTest.php | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index c8229f1049..7f0b1ed597 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -113,8 +113,18 @@ final class FormExtension extends AbstractExtension public function getFieldLabel(FormView $view): ?string { + if (false === $label = $view->vars['label']) { + return null; + } + + if (!$label && $labelFormat = $view->vars['label_format']) { + $label = str_replace(['%id%', '%name%'], [$view->vars['id'], $view->vars['name']], $labelFormat); + } elseif (!$label) { + $label = ucfirst(strtolower(trim(preg_replace(['/([A-Z])/', '/[_\s]+/'], ['_$1', ' '], $view->vars['name'])))); + } + return $this->createFieldTranslation( - $view->vars['label'], + $label, $view->vars['label_translation_parameters'] ?: [], $view->vars['translation_domain'] ); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php index b5f936e1c7..ce3ee926e1 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php @@ -81,6 +81,7 @@ class FormExtensionFieldHelpersTest extends FormIntegrationTestCase ], ], 'choice_translation_domain' => 'forms', + 'label_format' => 'label format for field "%name%" with id "%id%"', ]) ->add('choice_multiple', ChoiceType::class, [ 'choices' => [ @@ -89,6 +90,7 @@ class FormExtensionFieldHelpersTest extends FormIntegrationTestCase ], 'multiple' => true, 'expanded' => true, + 'label' => false, ]) ->getForm() ; @@ -121,6 +123,21 @@ class FormExtensionFieldHelpersTest extends FormIntegrationTestCase $this->assertSame('[trans]base.username[/trans]', $this->translatorExtension->getFieldLabel($this->view->children['username'])); } + public function testFieldLabelFromFormat() + { + $this->assertSame('label format for field "choice_grouped" with id "register_choice_grouped"', $this->rawExtension->getFieldLabel($this->view->children['choice_grouped'])); + } + + public function testFieldLabelFallsBackToName() + { + $this->assertSame('Choice flat', $this->rawExtension->getFieldLabel($this->view->children['choice_flat'])); + } + + public function testFieldLabelReturnsNullWhenLabelIsDisabled() + { + $this->assertNull($this->rawExtension->getFieldLabel($this->view->children['choice_multiple'])); + } + public function testFieldHelp() { $this->assertSame('base.username_help', $this->rawExtension->getFieldHelp($this->view->children['username'])); From 036c8d71fdc4e00091278c5b145b51c0ca8b4387 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 28 Jan 2021 12:34:38 +0100 Subject: [PATCH 3/5] use proper keys to not override appended files --- src/Symfony/Component/Finder/Finder.php | 3 ++- src/Symfony/Component/Finder/Tests/FinderTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index 4cf723bf33..82c2ec78dc 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -669,7 +669,8 @@ class Finder implements \IteratorAggregate, \Countable } elseif ($iterator instanceof \Traversable || \is_array($iterator)) { $it = new \ArrayIterator(); foreach ($iterator as $file) { - $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file)); + $file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file); + $it[$file->getPathname()] = $file; } $this->iterators[] = $it; } else { diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index db3c4a55ef..dbc66cbc47 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -1119,6 +1119,17 @@ class FinderTest extends Iterator\RealIteratorTestCase $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator()); } + public function testMultipleAppendCallsWithSorting() + { + $finder = $this->buildFinder() + ->sortByName() + ->append([self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1000_1.php']) + ->append([self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1002_0.php']) + ; + + $this->assertOrderedIterator($this->toAbsolute(['qux_1000_1.php', 'qux_1002_0.php']), $finder->getIterator()); + } + public function testCountDirectories() { $directory = Finder::create()->directories()->in(self::$tmpDir); From 66be87bffc92a28c5edada77b08cd424a9cba5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Deuchnord?= Date: Wed, 27 Jan 2021 17:03:07 +0100 Subject: [PATCH 4/5] [ErrorHandler] Fix strpos error when trying to call a method without a name --- .../UndefinedMethodFatalErrorHandler.php | 2 +- .../UndefinedMethodFatalErrorHandlerTest.php | 9 +++++++++ .../ErrorEnhancer/UndefinedMethodErrorEnhancer.php | 2 +- .../ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php index 773f4dfa78..4f622deeca 100644 --- a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php +++ b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php @@ -40,7 +40,7 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); - if (!class_exists($className) || null === $methods = get_class_methods($className)) { + if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) { // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class) return new UndefinedMethodException($message, $exception); } diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php index 55f2f62880..160dc7fa05 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php @@ -48,6 +48,15 @@ class UndefinedMethodFatalErrorHandlerTest extends TestCase ], 'Attempted to call an undefined method named "what" of class "SplObjectStorage".', ], + [ + [ + 'type' => 1, + 'line' => 12, + 'file' => 'foo.php', + 'message' => 'Call to undefined method SplObjectStorage::()', + ], + 'Attempted to call an undefined method named "" of class "SplObjectStorage".', + ], [ [ 'type' => 1, diff --git a/src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedMethodErrorEnhancer.php b/src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedMethodErrorEnhancer.php index ad0e4b3eef..c4355f92ce 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedMethodErrorEnhancer.php +++ b/src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedMethodErrorEnhancer.php @@ -39,7 +39,7 @@ class UndefinedMethodErrorEnhancer implements ErrorEnhancerInterface $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); - if (!class_exists($className) || null === $methods = get_class_methods($className)) { + if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) { // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class) return new UndefinedMethodError($message, $error); } diff --git a/src/Symfony/Component/ErrorHandler/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php b/src/Symfony/Component/ErrorHandler/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php index d6ac6c029c..b31c6c292a 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php @@ -40,6 +40,10 @@ class UndefinedMethodErrorEnhancerTest extends TestCase 'Call to undefined method SplObjectStorage::what()', 'Attempted to call an undefined method named "what" of class "SplObjectStorage".', ], + [ + 'Call to undefined method SplObjectStorage::()', + 'Attempted to call an undefined method named "" of class "SplObjectStorage".', + ], [ 'Call to undefined method SplObjectStorage::walid()', "Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?", From 9629dafa661db0834c424fddbdb34c77da8f5d2a Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 27 Jan 2021 14:04:45 +0100 Subject: [PATCH 5/5] Use createMock() instead of a getter --- .../Tests/Templating/TimedPhpEngineTest.php | 7 +-- .../WebDebugToolbarListenerTest.php | 44 ++++++-------- .../Tests/Profiler/TemplateManagerTest.php | 20 +------ .../Tests/EventListener/ErrorListenerTest.php | 30 ++++------ .../Component/Form/Tests/FormFactoryTest.php | 13 ++-- .../CacheClearer/ChainCacheClearerTest.php | 7 +-- .../AddRequestFormatsListenerTest.php | 11 +--- .../EventListener/LocaleAwareListenerTest.php | 15 ++--- .../EventListener/TranslatorListenerTest.php | 15 ++--- .../AuthenticationTrustResolverTest.php | 4 +- .../Core/Tests/User/ChainUserProviderTest.php | 60 ++++++++----------- .../Constraints/UserPasswordValidatorTest.php | 7 +-- .../SessionAuthenticationStrategyTest.php | 13 ++-- .../Tests/Mapping/Loader/FilesLoaderTest.php | 9 +-- 14 files changed, 82 insertions(+), 173 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TimedPhpEngineTest.php index 86c6d3940c..72e3fb0f78 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 @@ class TimedPhpEngineTest extends TestCase $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 30b3edf164..01d586346a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php @@ -65,7 +65,7 @@ class WebDebugToolbarListenerTest extends TestCase { $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 @@ class WebDebugToolbarListenerTest extends TestCase { $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase { $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 @@ class WebDebugToolbarListenerTest extends TestCase { $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase ->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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase ->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 @@ class WebDebugToolbarListenerTest extends TestCase $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 @@ class WebDebugToolbarListenerTest extends TestCase ->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 @@ class WebDebugToolbarListenerTest extends TestCase 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 9b43ab5350..5e746c63bf 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\LoaderInterface; 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 @@ class TemplateManagerTest extends TestCase { 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 @@ class TemplateManagerTest extends TestCase '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 @@ class TemplateManagerTest extends TestCase } } - protected function mockProfile() - { - return $this->createMock(Profile::class); - } - protected function mockTwigEnvironment() { $this->twigEnvironment = $this->createMock(Environment::class); @@ -121,13 +114,6 @@ class TemplateManagerTest extends TestCase 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 ce3df1a0ec..280395803c 100644 --- a/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php +++ b/src/Symfony/Component/Console/Tests/EventListener/ErrorListenerTest.php @@ -30,7 +30,7 @@ class ErrorListenerTest extends TestCase { $error = new \TypeError('An error occurred'); - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('error') @@ -38,14 +38,14 @@ class ErrorListenerTest extends TestCase ; $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 @@ class ErrorListenerTest extends TestCase ; $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 @@ class ErrorListenerTest extends TestCase public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->never()) ->method('debug') @@ -83,7 +83,7 @@ class ErrorListenerTest extends TestCase public function testGetSubscribedEvents() { - $this->assertEquals( + $this->assertSame( [ 'console.error' => ['onConsoleError', -128], 'console.terminate' => ['onConsoleTerminate', -128], @@ -94,7 +94,7 @@ class ErrorListenerTest extends TestCase public function testAllKindsOfInputCanBeLogged() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->exactly(3)) ->method('debug') @@ -109,7 +109,7 @@ class ErrorListenerTest extends TestCase public function testCommandNameIsDisplayedForNonStringableInput() { - $logger = $this->getLogger(); + $logger = $this->createMock(LoggerInterface::class); $logger ->expects($this->once()) ->method('debug') @@ -120,19 +120,9 @@ class ErrorListenerTest extends TestCase $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 0ea4bb26bf..c857ca6223 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -77,7 +77,7 @@ class FormFactoryTest extends TestCase { $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 @@ class FormFactoryTest extends TestCase $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 @@ class FormFactoryTest extends TestCase { $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 @@ class FormFactoryTest extends TestCase { $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 @@ class FormFactoryTest extends TestCase ->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 80c1b576be..80d9796070 100644 --- a/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php @@ -31,7 +31,7 @@ class ChainCacheClearerTest extends TestCase public function testInjectClearersInConstructor() { - $clearer = $this->getMockClearer(); + $clearer = $this->createMock(CacheClearerInterface::class); $clearer ->expects($this->once()) ->method('clear'); @@ -39,9 +39,4 @@ class ChainCacheClearerTest extends TestCase $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 def3831851..fab9a8a38f 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\EventListener\AddRequestFormatsListener; use Symfony\Component\HttpKernel\KernelEvents; /** - * Test AddRequestFormatsListener class. - * * @author Gildas Quemener */ class AddRequestFormatsListenerTest extends TestCase @@ -47,7 +45,7 @@ class AddRequestFormatsListenerTest extends TestCase public function testRegisteredEvent() { - $this->assertEquals( + $this->assertSame( [KernelEvents::REQUEST => ['onKernelRequest', 100]], AddRequestFormatsListener::getSubscribedEvents() ); @@ -55,7 +53,7 @@ class AddRequestFormatsListenerTest extends TestCase public function testSetAdditionalFormats() { - $request = $this->getRequestMock(); + $request = $this->createMock(Request::class); $event = $this->getRequestEventMock($request); $request->expects($this->once()) @@ -65,11 +63,6 @@ class AddRequestFormatsListenerTest extends TestCase $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 20c9f9d8c9..ab92a79168 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php @@ -40,7 +40,7 @@ class LocaleAwareListenerTest extends TestCase ->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 @@ class LocaleAwareListenerTest extends TestCase $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 @@ class LocaleAwareListenerTest extends TestCase $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 @@ class LocaleAwareListenerTest extends TestCase $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 @@ class LocaleAwareListenerTest extends TestCase $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 26097696dd..1eb86b7fb9 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php @@ -43,7 +43,7 @@ class TranslatorListenerTest extends TestCase ->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 @@ class TranslatorListenerTest extends TestCase $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 @@ class TranslatorListenerTest extends TestCase ->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 @@ class TranslatorListenerTest extends TestCase ->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 @@ class TranslatorListenerTest extends TestCase ); $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 eb82a596bc..3d6258e2da 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 @@ class AuthenticationTrustResolverTest extends TestCase 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 cb172d2b51..b7e2a411b3 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 @@ class ChainUserProviderTest extends TestCase ->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 @@ class ChainUserProviderTest extends TestCase 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 @@ class ChainUserProviderTest extends TestCase ->willThrowException(new UsernameNotFoundException('not found')) ; - $provider2 = $this->getProvider(); + $provider2 = $this->createMock(UserProviderInterface::class); $provider2 ->expects($this->once()) ->method('loadUserByUsername') @@ -69,14 +69,14 @@ class ChainUserProviderTest extends TestCase 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 @@ class ChainUserProviderTest extends TestCase ->willThrowException(new UnsupportedUserException('unsupported')) ; - $provider3 = $this->getProvider(); + $provider3 = $this->createMock(UserProviderInterface::class); $provider3 ->expects($this->once()) ->method('supportsClass') @@ -99,16 +99,16 @@ class ChainUserProviderTest extends TestCase $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 @@ class ChainUserProviderTest extends TestCase ->willThrowException(new UsernameNotFoundException('not found')) ; - $provider2 = $this->getProvider(); + $provider2 = $this->createMock(UserProviderInterface::class); $provider2 ->expects($this->once()) ->method('supportsClass') @@ -131,17 +131,17 @@ class ChainUserProviderTest extends TestCase $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 @@ class ChainUserProviderTest extends TestCase ->willThrowException(new UnsupportedUserException('unsupported')) ; - $provider2 = $this->getProvider(); + $provider2 = $this->createMock(UserProviderInterface::class); $provider2 ->expects($this->once()) ->method('supportsClass') @@ -168,12 +168,12 @@ class ChainUserProviderTest extends TestCase ; $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 @@ class ChainUserProviderTest extends TestCase ->willReturn(false) ; - $provider2 = $this->getProvider(); + $provider2 = $this->createMock(UserProviderInterface::class); $provider2 ->expects($this->once()) ->method('supportsClass') @@ -195,7 +195,7 @@ class ChainUserProviderTest extends TestCase public function testSupportsClassWhenNotSupported() { - $provider1 = $this->getProvider(); + $provider1 = $this->createMock(UserProviderInterface::class); $provider1 ->expects($this->once()) ->method('supportsClass') @@ -203,7 +203,7 @@ class ChainUserProviderTest extends TestCase ->willReturn(false) ; - $provider2 = $this->getProvider(); + $provider2 = $this->createMock(UserProviderInterface::class); $provider2 ->expects($this->once()) ->method('supportsClass') @@ -217,7 +217,7 @@ class ChainUserProviderTest extends TestCase public function testAcceptsTraversable() { - $provider1 = $this->getProvider(); + $provider1 = $this->createMock(UserProviderInterface::class); $provider1 ->expects($this->once()) ->method('supportsClass') @@ -230,7 +230,7 @@ class ChainUserProviderTest extends TestCase ->willThrowException(new UnsupportedUserException('unsupported')) ; - $provider2 = $this->getProvider(); + $provider2 = $this->createMock(UserProviderInterface::class); $provider2 ->expects($this->once()) ->method('supportsClass') @@ -240,11 +240,11 @@ class ChainUserProviderTest extends TestCase $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 @@ class ChainUserProviderTest extends TestCase $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 7c2d93ada1..5fc9ba0eae 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 @@ abstract class UserPasswordValidatorTest extends ConstraintValidatorTestCase { $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 @@ abstract class UserPasswordValidatorTest extends ConstraintValidatorTestCase 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 94ff9228bc..69953ae6fd 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 @@ class SessionAuthenticationStrategyTest extends TestCase $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 @@ class SessionAuthenticationStrategyTest extends TestCase $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 @@ class SessionAuthenticationStrategyTest extends TestCase $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 @@ class SessionAuthenticationStrategyTest extends TestCase $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 @@ class SessionAuthenticationStrategyTest extends TestCase 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 bc6aab8a34..6bba637a9b 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 @@ class FilesLoaderTest extends TestCase __DIR__.'/constraint-mapping.txt', ], $loader]); } - - public function getFileLoader() - { - return $this->createMock(LoaderInterface::class); - } }