Use createMock() instead of a getter
This commit is contained in:
parent
8533ea223e
commit
9629dafa66
@ -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);
|
||||
|
@ -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('<html><head></head><body></body></html>');
|
||||
$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('<html><head></head><body></body></html>');
|
||||
$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('<html><head></head><body></body></html>');
|
||||
$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('<html><head></head><body></body></html>', $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('<html><head></head><body></body></html>');
|
||||
|
||||
$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('<html><head></head><body></body></html>');
|
||||
$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('<div>Some content</div>');
|
||||
$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('<html><head></head><body></body></html>');
|
||||
$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('<html><head></head><body></body></html>');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ use Twig\Loader\LoaderInterface;
|
||||
use Twig\Loader\SourceContextLoaderInterface;
|
||||
|
||||
/**
|
||||
* Test for TemplateManager class.
|
||||
*
|
||||
* @author Artur Wielogórski <wodor@wodor.net>
|
||||
*/
|
||||
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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,6 @@ use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* Test AddRequestFormatsListener class.
|
||||
*
|
||||
* @author Gildas Quemener <gildas.quemener@gmail.com>
|
||||
*/
|
||||
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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user