Merge branch '5.2' into 5.x
* 5.2: Use createMock() instead of a getter [ErrorHandler] Fix strpos error when trying to call a method without a name use proper keys to not override appended files take into account all label related options Fix console logger according to PSR-3
This commit is contained in:
commit
02cbb3a92c
@ -113,8 +113,18 @@ final class FormExtension extends AbstractExtension
|
|||||||
|
|
||||||
public function getFieldLabel(FormView $view): ?string
|
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(
|
return $this->createFieldTranslation(
|
||||||
$view->vars['label'],
|
$label,
|
||||||
$view->vars['label_translation_parameters'] ?: [],
|
$view->vars['label_translation_parameters'] ?: [],
|
||||||
$view->vars['translation_domain']
|
$view->vars['translation_domain']
|
||||||
);
|
);
|
||||||
|
@ -81,6 +81,7 @@ class FormExtensionFieldHelpersTest extends FormIntegrationTestCase
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
'choice_translation_domain' => 'forms',
|
'choice_translation_domain' => 'forms',
|
||||||
|
'label_format' => 'label format for field "%name%" with id "%id%"',
|
||||||
])
|
])
|
||||||
->add('choice_multiple', ChoiceType::class, [
|
->add('choice_multiple', ChoiceType::class, [
|
||||||
'choices' => [
|
'choices' => [
|
||||||
@ -89,6 +90,7 @@ class FormExtensionFieldHelpersTest extends FormIntegrationTestCase
|
|||||||
],
|
],
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
|
'label' => false,
|
||||||
])
|
])
|
||||||
->getForm()
|
->getForm()
|
||||||
;
|
;
|
||||||
@ -121,6 +123,21 @@ class FormExtensionFieldHelpersTest extends FormIntegrationTestCase
|
|||||||
$this->assertSame('[trans]base.username[/trans]', $this->translatorExtension->getFieldLabel($this->view->children['username']));
|
$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()
|
public function testFieldHelp()
|
||||||
{
|
{
|
||||||
$this->assertSame('base.username_help', $this->rawExtension->getFieldHelp($this->view->children['username']));
|
$this->assertSame('base.username_help', $this->rawExtension->getFieldHelp($this->view->children['username']));
|
||||||
|
@ -65,7 +65,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$response = new Response('Some content', $statusCode);
|
$response = new Response('Some content', $statusCode);
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -78,7 +78,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$response = new Response('Some content', '301');
|
$response = new Response('Some content', '301');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -92,7 +92,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<html><head></head><body></body></html>');
|
$response = new Response('<html><head></head><body></body></html>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -108,7 +108,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<html><head></head><body></body></html>');
|
$response = new Response('<html><head></head><body></body></html>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
$response->headers->set('Content-Type', 'text/xml');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -124,7 +124,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<html><head></head><body></body></html>');
|
$response = new Response('<html><head></head><body></body></html>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
$response->headers->set('Content-Disposition', 'attachment; filename=test.html');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -140,7 +140,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$response = new Response('<html><head></head><body></body></html>', $statusCode);
|
$response = new Response('<html><head></head><body></body></html>', $statusCode);
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -165,7 +165,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$response = new Response('<html><head></head><body></body></html>');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -181,7 +181,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<html><head></head><body></body></html>');
|
$response = new Response('<html><head></head><body></body></html>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -197,7 +197,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<div>Some content</div>');
|
$response = new Response('<div>Some content</div>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -213,7 +213,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<html><head></head><body></body></html>');
|
$response = new Response('<html><head></head><body></body></html>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -229,7 +229,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response('<html><head></head><body></body></html>');
|
$response = new Response('<html><head></head><body></body></html>');
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$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 = new WebDebugToolbarListener($this->getTwigMock());
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -242,7 +242,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
|
|
||||||
$urlGenerator = $this->getUrlGeneratorMock();
|
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||||
$urlGenerator
|
$urlGenerator
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generate')
|
->method('generate')
|
||||||
@ -250,7 +250,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
->willReturn('http://mydomain.com/_profiler/xxxxxxxx')
|
->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 = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -263,7 +263,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
|
|
||||||
$urlGenerator = $this->getUrlGeneratorMock();
|
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||||
$urlGenerator
|
$urlGenerator
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generate')
|
->method('generate')
|
||||||
@ -271,7 +271,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
->willThrowException(new \Exception('foo'))
|
->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 = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -284,7 +284,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
|
||||||
|
|
||||||
$urlGenerator = $this->getUrlGeneratorMock();
|
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||||
$urlGenerator
|
$urlGenerator
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generate')
|
->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"))
|
->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 = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
|
||||||
$listener->onKernelResponse($event);
|
$listener->onKernelResponse($event);
|
||||||
@ -331,14 +331,4 @@ class WebDebugToolbarListenerTest extends TestCase
|
|||||||
|
|
||||||
return $templating;
|
return $templating;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getUrlGeneratorMock()
|
|
||||||
{
|
|
||||||
return $this->createMock(UrlGeneratorInterface::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getKernelMock()
|
|
||||||
{
|
|
||||||
return $this->createMock(Kernel::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,6 @@ use Twig\Environment;
|
|||||||
use Twig\Loader\LoaderInterface;
|
use Twig\Loader\LoaderInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for TemplateManager class.
|
|
||||||
*
|
|
||||||
* @author Artur Wielogórski <wodor@wodor.net>
|
* @author Artur Wielogórski <wodor@wodor.net>
|
||||||
*/
|
*/
|
||||||
class TemplateManagerTest extends TestCase
|
class TemplateManagerTest extends TestCase
|
||||||
@ -37,7 +35,7 @@ class TemplateManagerTest extends TestCase
|
|||||||
protected $profiler;
|
protected $profiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
|
* @var TemplateManager
|
||||||
*/
|
*/
|
||||||
protected $templateManager;
|
protected $templateManager;
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ class TemplateManagerTest extends TestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$profiler = $this->mockProfiler();
|
$this->profiler = $this->createMock(Profiler::class);
|
||||||
$twigEnvironment = $this->mockTwigEnvironment();
|
$twigEnvironment = $this->mockTwigEnvironment();
|
||||||
$templates = [
|
$templates = [
|
||||||
'data_collector.foo' => ['foo', '@Foo/Collector/foo.html.twig'],
|
'data_collector.foo' => ['foo', '@Foo/Collector/foo.html.twig'],
|
||||||
@ -53,7 +51,7 @@ class TemplateManagerTest extends TestCase
|
|||||||
'data_collector.baz' => ['baz', '@Foo/Collector/baz.html.twig'],
|
'data_collector.baz' => ['baz', '@Foo/Collector/baz.html.twig'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
|
$this->templateManager = new TemplateManager($this->profiler, $twigEnvironment, $templates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetNameOfInvalidTemplate()
|
public function testGetNameOfInvalidTemplate()
|
||||||
@ -97,11 +95,6 @@ class TemplateManagerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function mockProfile()
|
|
||||||
{
|
|
||||||
return $this->createMock(Profile::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function mockTwigEnvironment()
|
protected function mockTwigEnvironment()
|
||||||
{
|
{
|
||||||
$this->twigEnvironment = $this->createMock(Environment::class);
|
$this->twigEnvironment = $this->createMock(Environment::class);
|
||||||
@ -116,13 +109,6 @@ class TemplateManagerTest extends TestCase
|
|||||||
|
|
||||||
return $this->twigEnvironment;
|
return $this->twigEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function mockProfiler()
|
|
||||||
{
|
|
||||||
$this->profiler = $this->createMock(Profiler::class);
|
|
||||||
|
|
||||||
return $this->profiler;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProfileDummy extends Profile
|
class ProfileDummy extends Profile
|
||||||
|
@ -40,12 +40,12 @@ class ErrorListener implements EventSubscriberInterface
|
|||||||
$error = $event->getError();
|
$error = $event->getError();
|
||||||
|
|
||||||
if (!$inputString = $this->getInputString($event)) {
|
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;
|
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)
|
public function onConsoleTerminate(ConsoleTerminateEvent $event)
|
||||||
|
@ -30,35 +30,35 @@ class ErrorListenerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$error = new \TypeError('An error occurred');
|
$error = new \TypeError('An error occurred');
|
||||||
|
|
||||||
$logger = $this->getLogger();
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$logger
|
$logger
|
||||||
->expects($this->once())
|
->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'])
|
->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'])
|
||||||
;
|
;
|
||||||
|
|
||||||
$listener = new ErrorListener($logger);
|
$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()
|
public function testOnConsoleErrorWithNoCommandAndNoInputString()
|
||||||
{
|
{
|
||||||
$error = new \RuntimeException('An error occurred');
|
$error = new \RuntimeException('An error occurred');
|
||||||
|
|
||||||
$logger = $this->getLogger();
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$logger
|
$logger
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('error')
|
->method('critical')
|
||||||
->with('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => 'An error occurred'])
|
->with('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => 'An error occurred'])
|
||||||
;
|
;
|
||||||
|
|
||||||
$listener = new ErrorListener($logger);
|
$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()
|
public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog()
|
||||||
{
|
{
|
||||||
$logger = $this->getLogger();
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$logger
|
$logger
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('debug')
|
->method('debug')
|
||||||
@ -71,7 +71,7 @@ class ErrorListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
|
public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
|
||||||
{
|
{
|
||||||
$logger = $this->getLogger();
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$logger
|
$logger
|
||||||
->expects($this->never())
|
->expects($this->never())
|
||||||
->method('debug')
|
->method('debug')
|
||||||
@ -83,7 +83,7 @@ class ErrorListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testGetSubscribedEvents()
|
public function testGetSubscribedEvents()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
[
|
[
|
||||||
'console.error' => ['onConsoleError', -128],
|
'console.error' => ['onConsoleError', -128],
|
||||||
'console.terminate' => ['onConsoleTerminate', -128],
|
'console.terminate' => ['onConsoleTerminate', -128],
|
||||||
@ -94,7 +94,7 @@ class ErrorListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testAllKindsOfInputCanBeLogged()
|
public function testAllKindsOfInputCanBeLogged()
|
||||||
{
|
{
|
||||||
$logger = $this->getLogger();
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$logger
|
$logger
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(3))
|
||||||
->method('debug')
|
->method('debug')
|
||||||
@ -109,7 +109,7 @@ class ErrorListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testCommandNameIsDisplayedForNonStringableInput()
|
public function testCommandNameIsDisplayedForNonStringableInput()
|
||||||
{
|
{
|
||||||
$logger = $this->getLogger();
|
$logger = $this->createMock(LoggerInterface::class);
|
||||||
$logger
|
$logger
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('debug')
|
->method('debug')
|
||||||
@ -120,19 +120,9 @@ class ErrorListenerTest extends TestCase
|
|||||||
$listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255));
|
$listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLogger()
|
|
||||||
{
|
|
||||||
return $this->getMockForAbstractClass(LoggerInterface::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getConsoleTerminateEvent(InputInterface $input, $exitCode)
|
private function getConsoleTerminateEvent(InputInterface $input, $exitCode)
|
||||||
{
|
{
|
||||||
return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->getOutput(), $exitCode);
|
return new ConsoleTerminateEvent(new Command('test:run'), $input, $this->createMock(OutputInterface::class), $exitCode);
|
||||||
}
|
|
||||||
|
|
||||||
private function getOutput()
|
|
||||||
{
|
|
||||||
return $this->createMock(OutputInterface::class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class UndefinedMethodErrorEnhancer implements ErrorEnhancerInterface
|
|||||||
|
|
||||||
$message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className);
|
$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)
|
// 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);
|
return new UndefinedMethodError($message, $error);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,10 @@ class UndefinedMethodErrorEnhancerTest extends TestCase
|
|||||||
'Call to undefined method SplObjectStorage::what()',
|
'Call to undefined method SplObjectStorage::what()',
|
||||||
'Attempted to call an undefined method named "what" of class "SplObjectStorage".',
|
'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()',
|
'Call to undefined method SplObjectStorage::walid()',
|
||||||
"Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",
|
"Attempted to call an undefined method named \"walid\" of class \"SplObjectStorage\".\nDid you mean to call \"valid\"?",
|
||||||
|
@ -654,7 +654,8 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
} elseif ($iterator instanceof \Traversable || \is_array($iterator)) {
|
} elseif ($iterator instanceof \Traversable || \is_array($iterator)) {
|
||||||
$it = new \ArrayIterator();
|
$it = new \ArrayIterator();
|
||||||
foreach ($iterator as $file) {
|
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;
|
$this->iterators[] = $it;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1118,6 +1118,17 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
|||||||
$this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
|
$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()
|
public function testCountDirectories()
|
||||||
{
|
{
|
||||||
$directory = Finder::create()->directories()->in(self::$tmpDir);
|
$directory = Finder::create()->directories()->in(self::$tmpDir);
|
||||||
|
@ -76,7 +76,7 @@ class FormFactoryTest extends TestCase
|
|||||||
{
|
{
|
||||||
$options = ['a' => '1', 'b' => '2'];
|
$options = ['a' => '1', 'b' => '2'];
|
||||||
$resolvedOptions = ['a' => '2', 'b' => '3'];
|
$resolvedOptions = ['a' => '2', 'b' => '3'];
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->once())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
@ -104,7 +104,7 @@ class FormFactoryTest extends TestCase
|
|||||||
$givenOptions = ['a' => '1', 'b' => '2'];
|
$givenOptions = ['a' => '1', 'b' => '2'];
|
||||||
$expectedOptions = array_merge($givenOptions, ['data' => 'DATA']);
|
$expectedOptions = array_merge($givenOptions, ['data' => 'DATA']);
|
||||||
$resolvedOptions = ['a' => '2', 'b' => '3', 'data' => 'DATA'];
|
$resolvedOptions = ['a' => '2', 'b' => '3', 'data' => 'DATA'];
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->once())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
@ -131,7 +131,7 @@ class FormFactoryTest extends TestCase
|
|||||||
{
|
{
|
||||||
$options = ['a' => '1', 'b' => '2', 'data' => 'CUSTOM'];
|
$options = ['a' => '1', 'b' => '2', 'data' => 'CUSTOM'];
|
||||||
$resolvedOptions = ['a' => '2', 'b' => '3', 'data' => 'CUSTOM'];
|
$resolvedOptions = ['a' => '2', 'b' => '3', 'data' => 'CUSTOM'];
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->once())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
@ -196,7 +196,7 @@ class FormFactoryTest extends TestCase
|
|||||||
{
|
{
|
||||||
$options = ['a' => '1', 'b' => '2'];
|
$options = ['a' => '1', 'b' => '2'];
|
||||||
$resolvedOptions = ['a' => '2', 'b' => '3'];
|
$resolvedOptions = ['a' => '2', 'b' => '3'];
|
||||||
$resolvedType = $this->getMockResolvedType();
|
$resolvedType = $this->createMock(ResolvedFormTypeInterface::class);
|
||||||
|
|
||||||
$this->registry->expects($this->once())
|
$this->registry->expects($this->once())
|
||||||
->method('getType')
|
->method('getType')
|
||||||
@ -470,9 +470,4 @@ class FormFactoryTest extends TestCase
|
|||||||
->setConstructorArgs([$this->registry])
|
->setConstructorArgs([$this->registry])
|
||||||
->getMock();
|
->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMockResolvedType()
|
|
||||||
{
|
|
||||||
return $this->createMock(ResolvedFormTypeInterface::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class ChainCacheClearerTest extends TestCase
|
|||||||
|
|
||||||
public function testInjectClearersInConstructor()
|
public function testInjectClearersInConstructor()
|
||||||
{
|
{
|
||||||
$clearer = $this->getMockClearer();
|
$clearer = $this->createMock(CacheClearerInterface::class);
|
||||||
$clearer
|
$clearer
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('clear');
|
->method('clear');
|
||||||
@ -39,9 +39,4 @@ class ChainCacheClearerTest extends TestCase
|
|||||||
$chainClearer = new ChainCacheClearer([$clearer]);
|
$chainClearer = new ChainCacheClearer([$clearer]);
|
||||||
$chainClearer->clear(self::$cacheDir);
|
$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;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test AddRequestFormatsListener class.
|
|
||||||
*
|
|
||||||
* @author Gildas Quemener <gildas.quemener@gmail.com>
|
* @author Gildas Quemener <gildas.quemener@gmail.com>
|
||||||
*/
|
*/
|
||||||
class AddRequestFormatsListenerTest extends TestCase
|
class AddRequestFormatsListenerTest extends TestCase
|
||||||
@ -47,7 +45,7 @@ class AddRequestFormatsListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testRegisteredEvent()
|
public function testRegisteredEvent()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
[KernelEvents::REQUEST => ['onKernelRequest', 100]],
|
[KernelEvents::REQUEST => ['onKernelRequest', 100]],
|
||||||
AddRequestFormatsListener::getSubscribedEvents()
|
AddRequestFormatsListener::getSubscribedEvents()
|
||||||
);
|
);
|
||||||
@ -55,7 +53,7 @@ class AddRequestFormatsListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testSetAdditionalFormats()
|
public function testSetAdditionalFormats()
|
||||||
{
|
{
|
||||||
$request = $this->getRequestMock();
|
$request = $this->createMock(Request::class);
|
||||||
$event = $this->getRequestEventMock($request);
|
$event = $this->getRequestEventMock($request);
|
||||||
|
|
||||||
$request->expects($this->once())
|
$request->expects($this->once())
|
||||||
@ -65,11 +63,6 @@ class AddRequestFormatsListenerTest extends TestCase
|
|||||||
$this->listener->onKernelRequest($event);
|
$this->listener->onKernelRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRequestMock()
|
|
||||||
{
|
|
||||||
return $this->createMock(Request::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getRequestEventMock(Request $request)
|
protected function getRequestEventMock(Request $request)
|
||||||
{
|
{
|
||||||
$event = $this->createMock(RequestEvent::class);
|
$event = $this->createMock(RequestEvent::class);
|
||||||
|
@ -40,7 +40,7 @@ class LocaleAwareListenerTest extends TestCase
|
|||||||
->method('setLocale')
|
->method('setLocale')
|
||||||
->with($this->equalTo('fr'));
|
->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);
|
$this->listener->onKernelRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class LocaleAwareListenerTest extends TestCase
|
|||||||
$this->throwException(new \InvalidArgumentException())
|
$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);
|
$this->listener->onKernelRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ class LocaleAwareListenerTest extends TestCase
|
|||||||
$this->requestStack->push($this->createRequest('fr'));
|
$this->requestStack->push($this->createRequest('fr'));
|
||||||
$this->requestStack->push($subRequest = $this->createRequest('de'));
|
$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);
|
$this->listener->onKernelFinishRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class LocaleAwareListenerTest extends TestCase
|
|||||||
|
|
||||||
$this->requestStack->push($subRequest = $this->createRequest('de'));
|
$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);
|
$this->listener->onKernelFinishRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,15 +104,10 @@ class LocaleAwareListenerTest extends TestCase
|
|||||||
$this->requestStack->push($this->createRequest('fr'));
|
$this->requestStack->push($this->createRequest('fr'));
|
||||||
$this->requestStack->push($subRequest = $this->createRequest('de'));
|
$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);
|
$this->listener->onKernelFinishRequest($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createHttpKernel()
|
|
||||||
{
|
|
||||||
return $this->createMock(HttpKernelInterface::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createRequest($locale)
|
private function createRequest($locale)
|
||||||
{
|
{
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
|
@ -107,8 +107,8 @@ class AuthenticationTrustResolverTest extends TestCase
|
|||||||
protected function getResolver()
|
protected function getResolver()
|
||||||
{
|
{
|
||||||
return new AuthenticationTrustResolver(
|
return new AuthenticationTrustResolver(
|
||||||
'Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken',
|
AnonymousToken::class,
|
||||||
'Symfony\\Component\\Security\\Core\\Authentication\\Token\\RememberMeToken'
|
RememberMeToken::class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testLoadUserByUsername()
|
public function testLoadUserByUsername()
|
||||||
{
|
{
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('loadUserByUsername')
|
->method('loadUserByUsername')
|
||||||
@ -32,12 +32,12 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willThrowException(new UsernameNotFoundException('not found'))
|
->willThrowException(new UsernameNotFoundException('not found'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('loadUserByUsername')
|
->method('loadUserByUsername')
|
||||||
->with($this->equalTo('foo'))
|
->with($this->equalTo('foo'))
|
||||||
->willReturn($account = $this->getAccount())
|
->willReturn($account = $this->createMock(UserInterface::class))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider = new ChainUserProvider([$provider1, $provider2]);
|
$provider = new ChainUserProvider([$provider1, $provider2]);
|
||||||
@ -47,7 +47,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
public function testLoadUserByUsernameThrowsUsernameNotFoundException()
|
public function testLoadUserByUsernameThrowsUsernameNotFoundException()
|
||||||
{
|
{
|
||||||
$this->expectException(UsernameNotFoundException::class);
|
$this->expectException(UsernameNotFoundException::class);
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('loadUserByUsername')
|
->method('loadUserByUsername')
|
||||||
@ -55,7 +55,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willThrowException(new UsernameNotFoundException('not found'))
|
->willThrowException(new UsernameNotFoundException('not found'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('loadUserByUsername')
|
->method('loadUserByUsername')
|
||||||
@ -69,14 +69,14 @@ class ChainUserProviderTest extends TestCase
|
|||||||
|
|
||||||
public function testRefreshUser()
|
public function testRefreshUser()
|
||||||
{
|
{
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
->willReturn(false)
|
->willReturn(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -89,7 +89,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willThrowException(new UnsupportedUserException('unsupported'))
|
->willThrowException(new UnsupportedUserException('unsupported'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider3 = $this->getProvider();
|
$provider3 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider3
|
$provider3
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -99,16 +99,16 @@ class ChainUserProviderTest extends TestCase
|
|||||||
$provider3
|
$provider3
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('refreshUser')
|
->method('refreshUser')
|
||||||
->willReturn($account = $this->getAccount())
|
->willReturn($account = $this->createMock(UserInterface::class))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider = new ChainUserProvider([$provider1, $provider2, $provider3]);
|
$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()
|
public function testRefreshUserAgain()
|
||||||
{
|
{
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -121,7 +121,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willThrowException(new UsernameNotFoundException('not found'))
|
->willThrowException(new UsernameNotFoundException('not found'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -131,17 +131,17 @@ class ChainUserProviderTest extends TestCase
|
|||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('refreshUser')
|
->method('refreshUser')
|
||||||
->willReturn($account = $this->getAccount())
|
->willReturn($account = $this->createMock(UserInterface::class))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider = new ChainUserProvider([$provider1, $provider2]);
|
$provider = new ChainUserProvider([$provider1, $provider2]);
|
||||||
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
|
$this->assertSame($account, $provider->refreshUser($this->createMock(UserInterface::class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRefreshUserThrowsUnsupportedUserException()
|
public function testRefreshUserThrowsUnsupportedUserException()
|
||||||
{
|
{
|
||||||
$this->expectException(UnsupportedUserException::class);
|
$this->expectException(UnsupportedUserException::class);
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -154,7 +154,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willThrowException(new UnsupportedUserException('unsupported'))
|
->willThrowException(new UnsupportedUserException('unsupported'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -168,12 +168,12 @@ class ChainUserProviderTest extends TestCase
|
|||||||
;
|
;
|
||||||
|
|
||||||
$provider = new ChainUserProvider([$provider1, $provider2]);
|
$provider = new ChainUserProvider([$provider1, $provider2]);
|
||||||
$provider->refreshUser($this->getAccount());
|
$provider->refreshUser($this->createMock(UserInterface::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsClass()
|
public function testSupportsClass()
|
||||||
{
|
{
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -181,7 +181,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willReturn(false)
|
->willReturn(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -195,7 +195,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
|
|
||||||
public function testSupportsClassWhenNotSupported()
|
public function testSupportsClassWhenNotSupported()
|
||||||
{
|
{
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -203,7 +203,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willReturn(false)
|
->willReturn(false)
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -217,7 +217,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
|
|
||||||
public function testAcceptsTraversable()
|
public function testAcceptsTraversable()
|
||||||
{
|
{
|
||||||
$provider1 = $this->getProvider();
|
$provider1 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider1
|
$provider1
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -230,7 +230,7 @@ class ChainUserProviderTest extends TestCase
|
|||||||
->willThrowException(new UnsupportedUserException('unsupported'))
|
->willThrowException(new UnsupportedUserException('unsupported'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider2 = $this->getProvider();
|
$provider2 = $this->createMock(UserProviderInterface::class);
|
||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('supportsClass')
|
->method('supportsClass')
|
||||||
@ -240,11 +240,11 @@ class ChainUserProviderTest extends TestCase
|
|||||||
$provider2
|
$provider2
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('refreshUser')
|
->method('refreshUser')
|
||||||
->willReturn($account = $this->getAccount())
|
->willReturn($account = $this->createMock(UserInterface::class))
|
||||||
;
|
;
|
||||||
|
|
||||||
$provider = new ChainUserProvider(new \ArrayObject([$provider1, $provider2]));
|
$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()
|
public function testPasswordUpgrades()
|
||||||
@ -268,14 +268,4 @@ class ChainUserProviderTest extends TestCase
|
|||||||
$provider = new ChainUserProvider([$provider1, $provider2]);
|
$provider = new ChainUserProvider([$provider1, $provider2]);
|
||||||
$provider->upgradePassword($user, 'foobar');
|
$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();
|
$user = $this->createUser();
|
||||||
$this->tokenStorage = $this->createTokenStorage($user);
|
$this->tokenStorage = $this->createTokenStorage($user);
|
||||||
$this->encoder = $this->createPasswordEncoder();
|
$this->encoder = $this->createMock(PasswordEncoderInterface::class);
|
||||||
$this->encoderFactory = $this->createEncoderFactory($this->encoder);
|
$this->encoderFactory = $this->createEncoderFactory($this->encoder);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -154,11 +154,6 @@ abstract class UserPasswordValidatorTest extends ConstraintValidatorTestCase
|
|||||||
return $mock;
|
return $mock;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createPasswordEncoder($isPasswordValid = true)
|
|
||||||
{
|
|
||||||
return $this->createMock(PasswordEncoderInterface::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createEncoderFactory($encoder = null)
|
protected function createEncoderFactory($encoder = null)
|
||||||
{
|
{
|
||||||
$mock = $this->createMock(EncoderFactoryInterface::class);
|
$mock = $this->createMock(EncoderFactoryInterface::class);
|
||||||
|
@ -25,7 +25,7 @@ class SessionAuthenticationStrategyTest extends TestCase
|
|||||||
$request->expects($this->never())->method('getSession');
|
$request->expects($this->never())->method('getSession');
|
||||||
|
|
||||||
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE);
|
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE);
|
||||||
$strategy->onAuthentication($request, $this->getToken());
|
$strategy->onAuthentication($request, $this->createMock(TokenInterface::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUnsupportedStrategy()
|
public function testUnsupportedStrategy()
|
||||||
@ -36,7 +36,7 @@ class SessionAuthenticationStrategyTest extends TestCase
|
|||||||
$request->expects($this->never())->method('getSession');
|
$request->expects($this->never())->method('getSession');
|
||||||
|
|
||||||
$strategy = new SessionAuthenticationStrategy('foo');
|
$strategy = new SessionAuthenticationStrategy('foo');
|
||||||
$strategy->onAuthentication($request, $this->getToken());
|
$strategy->onAuthentication($request, $this->createMock(TokenInterface::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSessionIsMigrated()
|
public function testSessionIsMigrated()
|
||||||
@ -45,7 +45,7 @@ class SessionAuthenticationStrategyTest extends TestCase
|
|||||||
$session->expects($this->once())->method('migrate')->with($this->equalTo(true));
|
$session->expects($this->once())->method('migrate')->with($this->equalTo(true));
|
||||||
|
|
||||||
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
|
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
|
||||||
$strategy->onAuthentication($this->getRequest($session), $this->getToken());
|
$strategy->onAuthentication($this->getRequest($session), $this->createMock(TokenInterface::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSessionIsInvalidated()
|
public function testSessionIsInvalidated()
|
||||||
@ -54,7 +54,7 @@ class SessionAuthenticationStrategyTest extends TestCase
|
|||||||
$session->expects($this->once())->method('invalidate');
|
$session->expects($this->once())->method('invalidate');
|
||||||
|
|
||||||
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::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)
|
private function getRequest($session = null)
|
||||||
@ -67,9 +67,4 @@ class SessionAuthenticationStrategyTest extends TestCase
|
|||||||
|
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getToken()
|
|
||||||
{
|
|
||||||
return $this->createMock(TokenInterface::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ class FilesLoaderTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testCallsGetFileLoaderInstanceForeachPath()
|
public function testCallsGetFileLoaderInstanceForeachPath()
|
||||||
{
|
{
|
||||||
$loader = $this->getFilesLoader($this->getFileLoader());
|
$loader = $this->getFilesLoader($this->createMock(LoaderInterface::class));
|
||||||
$this->assertEquals(4, $loader->getTimesCalled());
|
$this->assertEquals(4, $loader->getTimesCalled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCallsActualFileLoaderForMetadata()
|
public function testCallsActualFileLoaderForMetadata()
|
||||||
{
|
{
|
||||||
$fileLoader = $this->getFileLoader();
|
$fileLoader = $this->createMock(LoaderInterface::class);
|
||||||
$fileLoader->expects($this->exactly(4))
|
$fileLoader->expects($this->exactly(4))
|
||||||
->method('loadClassMetadata');
|
->method('loadClassMetadata');
|
||||||
$loader = $this->getFilesLoader($fileLoader);
|
$loader = $this->getFilesLoader($fileLoader);
|
||||||
@ -43,9 +43,4 @@ class FilesLoaderTest extends TestCase
|
|||||||
__DIR__.'/constraint-mapping.txt',
|
__DIR__.'/constraint-mapping.txt',
|
||||||
], $loader]);
|
], $loader]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFileLoader()
|
|
||||||
{
|
|
||||||
return $this->createMock(LoaderInterface::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user