Use ::class keyword when possible

This commit is contained in:
Fabien Potencier 2021-01-11 11:45:43 +01:00
parent b145df90e6
commit 2922224d29
21 changed files with 160 additions and 160 deletions

View File

@ -160,7 +160,7 @@ class ORMQueryBuilderLoaderTest extends TestCase
$em = DoctrineTestHelper::createTestEntityManager();
$query = $this->getMockBuilder('QueryMock')
$query = $this->getMockBuilder(\QueryMock::class)
->setMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
->getMock();
@ -173,7 +173,7 @@ class ORMQueryBuilderLoaderTest extends TestCase
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [Uuid::fromString('71c5fd46-3f16-4abb-bad7-90ac1e654a2d')->toBinary(), Uuid::fromString('b98e8e11-2897-44df-ad24-d2627eb7f499')->toBinary()], Connection::PARAM_STR_ARRAY)
->willReturn($query);
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
->setConstructorArgs([$em])
->setMethods(['getQuery'])
->getMock();
@ -205,7 +205,7 @@ class ORMQueryBuilderLoaderTest extends TestCase
$em = DoctrineTestHelper::createTestEntityManager();
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
$qb = $this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
->setConstructorArgs([$em])
->setMethods(['getQuery'])
->getMock();

View File

@ -28,7 +28,7 @@ class DoctrineOrmTypeGuesserTest extends TestCase
*/
public function testTypeGuesser(string $type, $expected)
{
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata->fieldMappings['field'] = true;
$classMetadata->expects($this->once())->method('getTypeOfField')->with('field')->willReturn($type);

View File

@ -300,7 +300,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
{
$entity1 = new SingleIntIdEntity(1, null);
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->validator->validate($entity1, $constraint);
}
@ -616,7 +616,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testDedicatedEntityManagerNullObject()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('Object manager "foo" does not exist.');
$constraint = new UniqueEntity([
'message' => 'myMessage',
@ -636,7 +636,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testEntityManagerNullObject()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('Unable to find the object manager associated with an entity of class "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity"');
$constraint = new UniqueEntity([
'message' => 'myMessage',
@ -718,7 +718,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testInvalidateRepositoryForInheritance()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('The "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity" entity repository does not support the "Symfony\Bridge\Doctrine\Tests\Fixtures\Person" entity. The entity should be an instance of or extend "Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity".');
$constraint = new UniqueEntity([
'message' => 'myMessage',

View File

@ -65,13 +65,13 @@ class HttpCodeActivationStrategyTest extends TestCase
public function testExclusionsWithoutCode()
{
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
new HttpCodeActivationStrategy(new RequestStack(), [['urls' => []]], new ErrorLevelActivationStrategy(Logger::WARNING));
}
public function testExclusionsWithoutUrls()
{
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
new HttpCodeActivationStrategy(new RequestStack(), [['code' => 404]], new ErrorLevelActivationStrategy(Logger::WARNING));
}

View File

@ -137,7 +137,7 @@ abstract class FrameworkExtensionTest extends TestCase
public function testCsrfProtectionNeedsSessionToBeEnabled()
{
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('CSRF protection needs sessions to be enabled.');
$this->createContainerFromFile('csrf_needs_session');
}
@ -317,21 +317,21 @@ abstract class FrameworkExtensionTest extends TestCase
public function testWorkflowAreValidated()
{
$this->expectException('Symfony\Component\Workflow\Exception\InvalidDefinitionException');
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
$this->expectExceptionMessage('A transition from a place/state must have an unique name. Multiple transitions named "go" from place/state "first" were found on StateMachine "my_workflow".');
$this->createContainerFromFile('workflow_not_valid');
}
public function testWorkflowCannotHaveBothSupportsAndSupportStrategy()
{
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectExceptionMessage('"supports" and "support_strategy" cannot be used together.');
$this->createContainerFromFile('workflow_with_support_and_support_strategy');
}
public function testWorkflowShouldHaveOneOfSupportsAndSupportStrategy()
{
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectExceptionMessage('"supports" or "support_strategy" should be configured.');
$this->createContainerFromFile('workflow_without_support_and_support_strategy');
}
@ -513,7 +513,7 @@ abstract class FrameworkExtensionTest extends TestCase
public function testRouterRequiresResourceOption()
{
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$container = $this->createContainer();
$loader = new FrameworkExtension();
$loader->load([['router' => true]], $container);
@ -774,14 +774,14 @@ abstract class FrameworkExtensionTest extends TestCase
public function testMessengerMiddlewareFactoryErroneousFormat()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid middleware at path "framework.messenger": a map with a single factory id as key and its arguments as value was expected, {"foo":["qux"],"bar":["baz"]} given.');
$this->createContainerFromFile('messenger_middleware_factory_erroneous_format');
}
public function testMessengerInvalidTransportRouting()
{
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Invalid Messenger routing configuration: the "Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyMessage" class is being routed to a sender called "invalid". This is not a valid transport or service id.');
$this->createContainerFromFile('messenger_routing_invalid_transport');
}
@ -797,19 +797,19 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertSame($container->getParameter('kernel.cache_dir').'/translations', $options['cache_dir']);
$files = array_map('realpath', $options['resource_files']['en']);
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
$ref = new \ReflectionClass(\Symfony\Component\Validator\Validation::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds Validator translation resources'
);
$ref = new \ReflectionClass('Symfony\Component\Form\Form');
$ref = new \ReflectionClass(\Symfony\Component\Form\Form::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/validators.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds Form translation resources'
);
$ref = new \ReflectionClass('Symfony\Component\Security\Core\Security');
$ref = new \ReflectionClass(\Symfony\Component\Security\Core\Security::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/security.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
@ -866,7 +866,7 @@ abstract class FrameworkExtensionTest extends TestCase
$container = $this->createContainerFromFile('full');
$projectDir = $container->getParameter('kernel.project_dir');
$ref = new \ReflectionClass('Symfony\Component\Form\Form');
$ref = new \ReflectionClass(\Symfony\Component\Form\Form::class);
$xmlMappings = [
\dirname($ref->getFileName()).'/Resources/config/validation.xml',
strtr($projectDir.'/config/validator/foo.xml', '/', \DIRECTORY_SEPARATOR),
@ -900,7 +900,7 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('validation_annotations', ['kernel.charset' => 'UTF-8'], false);
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator.alias'));
$this->assertInstanceOf(\Symfony\Component\Validator\Validator\ValidatorInterface::class, $container->get('validator.alias'));
}
public function testAnnotations()

View File

@ -37,7 +37,7 @@ class TwigExtension extends Extension
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.php');
if (class_exists('Symfony\Component\Form\Form')) {
if (class_exists(\Symfony\Component\Form\Form::class)) {
$loader->load('form.php');
}

View File

@ -21,7 +21,7 @@ class TableCellStyleTest extends TestCase
$tableCellStyle = new TableCellStyle(['fg' => 'red']);
$this->assertEquals('red', $tableCellStyle->getOptions()['fg']);
$this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');
$this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class);
new TableCellStyle(['wrong_key' => null]);
}
}

View File

@ -26,7 +26,7 @@ class FragmentHandlerTest extends TestCase
protected function setUp(): void
{
$this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
$this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)
->disableOriginalConstructor()
->getMock()
;
@ -39,14 +39,14 @@ class FragmentHandlerTest extends TestCase
public function testRenderWhenRendererDoesNotExist()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$handler = new FragmentHandler($this->requestStack);
$handler->render('/', 'foo');
}
public function testRenderWithUnknownRenderer()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$handler = $this->getHandler($this->returnValue(new Response('foo')));
$handler->render('/', 'bar');
@ -59,7 +59,7 @@ class FragmentHandlerTest extends TestCase
$handler->render('/', 'foo');
$this->fail('->render() throws a \RuntimeException exception if response is not successful');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e);
$this->assertInstanceOf(\RuntimeException::class, $e);
$this->assertEquals(0, $e->getCode());
$this->assertEquals('Error when rendering "http://localhost/" (Status code is 404).', $e->getMessage());
@ -79,7 +79,7 @@ class FragmentHandlerTest extends TestCase
protected function getHandler($returnValue, $arguments = [])
{
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
$renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock();
$renderer
->expects($this->any())
->method('getName')

View File

@ -25,7 +25,7 @@ class PathHeaderTest extends TestCase
public function testAddressMustComplyWithRfc2822()
{
$this->expectException('Exception');
$this->expectException(\Exception::class);
new PathHeader('Return-Path', new Address('chr is@swiftmailer.org'));
}

View File

@ -103,7 +103,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testGetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path)
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->propertyAccessor->getValue($objectOrArray, $path);
}
@ -130,7 +130,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnabled($objectOrArray, $path)
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
$this->expectException(NoSuchIndexException::class);
$this->propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS, true);
$this->propertyAccessor->getValue($objectOrArray, $path);
}
@ -159,7 +159,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousClass()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
$this->expectExceptionMessage('The method "class@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
$object = eval('return new class() {
@ -179,7 +179,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousStdClass()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
$this->expectExceptionMessage('The method "stdClass@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
$object = eval('return new class() extends \stdClass {
@ -199,7 +199,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousChildClass()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
$this->expectExceptionMessage('The method "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
$object = eval('return new class() extends \Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty {};');
@ -209,7 +209,7 @@ class PropertyAccessorTest extends TestCase
public function testGetValueThrowsExceptionIfNotArrayAccess()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
$this->expectException(NoSuchIndexException::class);
$this->propertyAccessor->getValue(new \stdClass(), '[index]');
}
@ -267,7 +267,7 @@ class PropertyAccessorTest extends TestCase
public function testGetValueDoesNotReadMagicCallByDefault()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->propertyAccessor->getValue(new TestClassMagicCall('Bernhard'), 'magicCallProperty');
}
@ -302,7 +302,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testGetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
$this->propertyAccessor->getValue($objectOrArray, $path);
}
@ -322,7 +322,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testSetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path)
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->propertyAccessor->setValue($objectOrArray, $path, 'Updated');
}
@ -349,7 +349,7 @@ class PropertyAccessorTest extends TestCase
public function testSetValueThrowsExceptionIfNotArrayAccess()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
$this->expectException(NoSuchIndexException::class);
$object = new \stdClass();
$this->propertyAccessor->setValue($object, '[index]', 'Updated');
@ -376,7 +376,7 @@ class PropertyAccessorTest extends TestCase
public function testSetValueThrowsExceptionIfThereAreMissingParameters()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$object = new TestClass('Bernhard');
$this->propertyAccessor->setValue($object, 'publicAccessorWithMoreRequiredParameters', 'Updated');
@ -384,7 +384,7 @@ class PropertyAccessorTest extends TestCase
public function testSetValueDoesNotUpdateMagicCallByDefault()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$author = new TestClassMagicCall('Bernhard');
$this->propertyAccessor->setValue($author, 'magicCallProperty', 'Updated');
@ -421,7 +421,7 @@ class PropertyAccessorTest extends TestCase
*/
public function testSetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
$this->propertyAccessor->setValue($objectOrArray, $path, 'value');
}
@ -679,7 +679,7 @@ class PropertyAccessorTest extends TestCase
public function testThrowTypeError()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected argument of type "DateTime", "string" given at property path "date"');
$object = new TypeHinted();
@ -688,7 +688,7 @@ class PropertyAccessorTest extends TestCase
public function testThrowTypeErrorWithNullArgument()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
$object = new TypeHinted();
@ -740,7 +740,7 @@ class PropertyAccessorTest extends TestCase
public function testThrowTypeErrorWithInterface()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected argument of type "Countable", "string" given');
$object = new TypeHinted();
@ -760,7 +760,7 @@ class PropertyAccessorTest extends TestCase
public function testAnonymousClassReadThrowExceptionOnInvalidPropertyPath()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$obj = $this->generateAnonymousClass('bar');
$this->propertyAccessor->getValue($obj, 'invalid_property');
@ -820,7 +820,7 @@ class PropertyAccessorTest extends TestCase
public function testThrowTypeErrorInsideSetterCall()
{
$this->expectException('TypeError');
$this->expectException(\TypeError::class);
$object = new TestClassTypeErrorInsideCall();
$this->propertyAccessor->setValue($object, 'property', 'foo');
@ -828,7 +828,7 @@ class PropertyAccessorTest extends TestCase
public function testDoNotDiscardReturnTypeError()
{
$this->expectException('TypeError');
$this->expectException(\TypeError::class);
$object = new ReturnTyped();
$this->propertyAccessor->setValue($object, 'foos', [new \DateTime()]);
@ -836,7 +836,7 @@ class PropertyAccessorTest extends TestCase
public function testDoNotDiscardReturnTypeErrorWhenWriterMethodIsMisconfigured()
{
$this->expectException('TypeError');
$this->expectException(\TypeError::class);
$object = new ReturnTyped();
$this->propertyAccessor->setValue($object, 'name', 'foo');
@ -886,7 +886,7 @@ class PropertyAccessorTest extends TestCase
public function testAdderWithoutRemover()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/.*The add method "addFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidMethods" was found, but the corresponding remove method "removeFoo" was not found\./');
$object = new TestAdderRemoverInvalidMethods();
$this->propertyAccessor->setValue($object, 'foos', [1, 2]);
@ -894,7 +894,7 @@ class PropertyAccessorTest extends TestCase
public function testRemoverWithoutAdder()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/.*The remove method "removeBar" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidMethods" was found, but the corresponding add method "addBar" was not found\./');
$object = new TestAdderRemoverInvalidMethods();
$this->propertyAccessor->setValue($object, 'bars', [1, 2]);
@ -902,7 +902,7 @@ class PropertyAccessorTest extends TestCase
public function testAdderAndRemoveNeedsTheExactParametersDefined()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/.*The method "addFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidArgumentLength" requires 0 arguments, but should accept only 1\./');
$object = new TestAdderRemoverInvalidArgumentLength();
$this->propertyAccessor->setValue($object, 'foo', [1, 2]);
@ -910,7 +910,7 @@ class PropertyAccessorTest extends TestCase
public function testSetterNeedsTheExactParametersDefined()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/.*The method "setBar" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidArgumentLength" requires 2 arguments, but should accept only 1\./');
$object = new TestAdderRemoverInvalidArgumentLength();
$this->propertyAccessor->setValue($object, 'bar', [1, 2]);
@ -918,7 +918,7 @@ class PropertyAccessorTest extends TestCase
public function testSetterNeedsPublicAccess()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/.*The method "setFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestClassSetValue" was found but does not have public access./');
$object = new TestClassSetValue(0);
$this->propertyAccessor->setValue($object, 'foo', 1);

View File

@ -33,7 +33,7 @@ class ConstructorExtractorTest extends TestCase
public function testInstanceOf()
{
$this->assertInstanceOf('Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface', $this->extractor);
$this->assertInstanceOf(\Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface::class, $this->extractor);
}
public function testGetTypes()

View File

@ -22,9 +22,9 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
$provider = $this->getProvider();
$this->assertTrue($provider->supports($this->getSupportedToken()));
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
$this->assertFalse($provider->supports($this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock()));
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken')
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken::class)
->disableOriginalConstructor()
->getMock()
;
@ -38,23 +38,23 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenTokenIsNotSupported()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationException::class);
$this->expectExceptionMessage('The token is not supported by this authentication provider.');
$provider = $this->getProvider();
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
$provider->authenticate($this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock());
}
public function testAuthenticateWhenNoUserIsSet()
{
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
$this->expectException(\Symfony\Component\Security\Core\Exception\BadCredentialsException::class);
$provider = $this->getProvider();
$provider->authenticate($this->getSupportedToken(''));
}
public function testAuthenticate()
{
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$user
->expects($this->once())
->method('getRoles')
@ -63,7 +63,7 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
$provider = $this->getProvider($user);
$token = $provider->authenticate($this->getSupportedToken('fabien', 'pass'));
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', $token);
$this->assertInstanceOf(\Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken::class, $token);
$this->assertEquals('pass', $token->getCredentials());
$this->assertEquals('key', $token->getFirewallName());
$this->assertEquals([], $token->getRoleNames());
@ -73,10 +73,10 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenUserCheckerThrowsException()
{
$this->expectException('Symfony\Component\Security\Core\Exception\LockedException');
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$this->expectException(LockedException::class);
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
$userChecker->expects($this->once())
->method('checkPostAuth')
->willThrowException(new LockedException())
@ -89,7 +89,7 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
protected function getSupportedToken($user = false, $credentials = false)
{
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken')->setMethods(['getUser', 'getCredentials', 'getFirewallName'])->disableOriginalConstructor()->getMock();
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken::class)->setMethods(['getUser', 'getCredentials', 'getFirewallName'])->disableOriginalConstructor()->getMock();
if (false !== $user) {
$token->expects($this->once())
->method('getUser')
@ -116,7 +116,7 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
protected function getProvider($user = null, $userChecker = null)
{
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$userProvider = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserProviderInterface::class)->getMock();
if (null !== $user) {
$userProvider->expects($this->once())
->method('loadUserByUsername')
@ -125,7 +125,7 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
}
if (null === $userChecker) {
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
}
return new PreAuthenticatedAuthenticationProvider($userProvider, $userChecker, 'key');

View File

@ -24,23 +24,23 @@ class RememberMeAuthenticationProviderTest extends TestCase
$provider = $this->getProvider();
$this->assertTrue($provider->supports($this->getSupportedToken()));
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->disableOriginalConstructor()->getMock()));
$this->assertFalse($provider->supports($this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock()));
$this->assertFalse($provider->supports($this->getMockBuilder(RememberMeToken::class)->disableOriginalConstructor()->getMock()));
}
public function testAuthenticateWhenTokenIsNotSupported()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationException::class);
$this->expectExceptionMessage('The token is not supported by this authentication provider.');
$provider = $this->getProvider();
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
$provider->authenticate($token);
}
public function testAuthenticateWhenSecretsDoNotMatch()
{
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
$this->expectException(\Symfony\Component\Security\Core\Exception\BadCredentialsException::class);
$provider = $this->getProvider(null, 'secret1');
$token = $this->getSupportedToken(null, 'secret2');
@ -49,7 +49,7 @@ class RememberMeAuthenticationProviderTest extends TestCase
public function testAuthenticateThrowsOnNonUserInterfaceInstance()
{
$this->expectException('Symfony\Component\Security\Core\Exception\LogicException');
$this->expectException(\Symfony\Component\Security\Core\Exception\LogicException::class);
$this->expectExceptionMessage('Method "Symfony\Component\Security\Core\Authentication\Token\RememberMeToken::getUser()" must return a "Symfony\Component\Security\Core\User\UserInterface" instance, "string" returned.');
$provider = $this->getProvider();
@ -60,8 +60,8 @@ class RememberMeAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenPreChecksFails()
{
$this->expectException('Symfony\Component\Security\Core\Exception\DisabledException');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$this->expectException(DisabledException::class);
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
$userChecker->expects($this->once())
->method('checkPreAuth')
->willThrowException(new DisabledException());
@ -73,7 +73,7 @@ class RememberMeAuthenticationProviderTest extends TestCase
public function testAuthenticate()
{
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$user->expects($this->exactly(2))
->method('getRoles')
->willReturn(['ROLE_FOO']);
@ -83,7 +83,7 @@ class RememberMeAuthenticationProviderTest extends TestCase
$token = $this->getSupportedToken($user);
$authToken = $provider->authenticate($token);
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', $authToken);
$this->assertInstanceOf(RememberMeToken::class, $authToken);
$this->assertSame($user, $authToken->getUser());
$this->assertEquals(['ROLE_FOO'], $authToken->getRoleNames());
$this->assertEquals('', $authToken->getCredentials());
@ -92,14 +92,14 @@ class RememberMeAuthenticationProviderTest extends TestCase
protected function getSupportedToken($user = null, $secret = 'test')
{
if (null === $user) {
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$user
->expects($this->any())
->method('getRoles')
->willReturn([]);
}
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(['getFirewallName'])->setConstructorArgs([$user, 'foo', $secret])->getMock();
$token = $this->getMockBuilder(RememberMeToken::class)->setMethods(['getFirewallName'])->setConstructorArgs([$user, 'foo', $secret])->getMock();
$token
->expects($this->once())
->method('getFirewallName')
@ -111,7 +111,7 @@ class RememberMeAuthenticationProviderTest extends TestCase
protected function getProvider($userChecker = null, $key = 'test')
{
if (null === $userChecker) {
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
}
return new RememberMeAuthenticationProvider($userChecker, $key, 'foo');

View File

@ -25,21 +25,21 @@ class UserAuthenticationProviderTest extends TestCase
$provider = $this->getProvider();
$this->assertTrue($provider->supports($this->getSupportedToken()));
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
$this->assertFalse($provider->supports($this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock()));
}
public function testAuthenticateWhenTokenIsNotSupported()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationException::class);
$this->expectExceptionMessage('The token is not supported by this authentication provider.');
$provider = $this->getProvider();
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
$provider->authenticate($this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock());
}
public function testAuthenticateWhenUsernameIsNotFound()
{
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
$this->expectException(UsernameNotFoundException::class);
$provider = $this->getProvider(false, false);
$provider->expects($this->once())
->method('retrieveUser')
@ -51,7 +51,7 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenUsernameIsNotFoundAndHideIsTrue()
{
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
$this->expectException(BadCredentialsException::class);
$provider = $this->getProvider(false, true);
$provider->expects($this->once())
->method('retrieveUser')
@ -63,7 +63,7 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenProviderDoesNotReturnAnUserInterface()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationServiceException::class);
$provider = $this->getProvider(false, true);
$provider->expects($this->once())
->method('retrieveUser')
@ -75,8 +75,8 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenPreChecksFails()
{
$this->expectException('Symfony\Component\Security\Core\Exception\CredentialsExpiredException');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$this->expectException(CredentialsExpiredException::class);
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
$userChecker->expects($this->once())
->method('checkPreAuth')
->willThrowException(new CredentialsExpiredException())
@ -85,7 +85,7 @@ class UserAuthenticationProviderTest extends TestCase
$provider = $this->getProvider($userChecker);
$provider->expects($this->once())
->method('retrieveUser')
->willReturn($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock())
->willReturn($this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock())
;
$provider->authenticate($this->getSupportedToken());
@ -93,8 +93,8 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenPostChecksFails()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AccountExpiredException');
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$this->expectException(AccountExpiredException::class);
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
$userChecker->expects($this->once())
->method('checkPostAuth')
->willThrowException(new AccountExpiredException())
@ -103,7 +103,7 @@ class UserAuthenticationProviderTest extends TestCase
$provider = $this->getProvider($userChecker);
$provider->expects($this->once())
->method('retrieveUser')
->willReturn($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock())
->willReturn($this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock())
;
$provider->authenticate($this->getSupportedToken());
@ -111,12 +111,12 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenPostCheckAuthenticationFails()
{
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
$this->expectException(BadCredentialsException::class);
$this->expectExceptionMessage('Bad credentials');
$provider = $this->getProvider();
$provider->expects($this->once())
->method('retrieveUser')
->willReturn($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock())
->willReturn($this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock())
;
$provider->expects($this->once())
->method('checkAuthentication')
@ -128,12 +128,12 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticateWhenPostCheckAuthenticationFailsWithHideFalse()
{
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
$this->expectException(BadCredentialsException::class);
$this->expectExceptionMessage('Foo');
$provider = $this->getProvider(false, false);
$provider->expects($this->once())
->method('retrieveUser')
->willReturn($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock())
->willReturn($this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock())
;
$provider->expects($this->once())
->method('checkAuthentication')
@ -145,7 +145,7 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticate()
{
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$user->expects($this->once())
->method('getRoles')
->willReturn(['ROLE_FOO'])
@ -165,7 +165,7 @@ class UserAuthenticationProviderTest extends TestCase
$authToken = $provider->authenticate($token);
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $authToken);
$this->assertInstanceOf(\Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::class, $authToken);
$this->assertSame($user, $authToken->getUser());
$this->assertEquals(['ROLE_FOO'], $authToken->getRoleNames());
$this->assertEquals('foo', $authToken->getCredentials());
@ -174,7 +174,7 @@ class UserAuthenticationProviderTest extends TestCase
public function testAuthenticatePreservesOriginalToken()
{
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$user->expects($this->once())
->method('getRoles')
->willReturn(['ROLE_FOO'])
@ -186,8 +186,8 @@ class UserAuthenticationProviderTest extends TestCase
->willReturn($user)
;
$originalToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$token = new SwitchUserToken($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock(), 'foo', 'key', [], $originalToken);
$originalToken = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
$token = new SwitchUserToken($this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock(), 'foo', 'key', [], $originalToken);
$token->setAttributes(['foo' => 'bar']);
$authToken = $provider->authenticate($token);
@ -202,7 +202,7 @@ class UserAuthenticationProviderTest extends TestCase
protected function getSupportedToken()
{
$mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')->setMethods(['getCredentials', 'getFirewallName', 'getRoles'])->disableOriginalConstructor()->getMock();
$mock = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::class)->setMethods(['getCredentials', 'getFirewallName', 'getRoles'])->disableOriginalConstructor()->getMock();
$mock
->expects($this->any())
->method('getFirewallName')
@ -217,9 +217,9 @@ class UserAuthenticationProviderTest extends TestCase
protected function getProvider($userChecker = false, $hide = true)
{
if (false === $userChecker) {
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
}
return $this->getMockForAbstractClass('Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider', [$userChecker, 'key', $hide]);
return $this->getMockForAbstractClass(\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider::class, [$userChecker, 'key', $hide]);
}
}

View File

@ -257,7 +257,7 @@ class AccessListenerTest extends TestCase
$tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
false
);
@ -286,7 +286,7 @@ class AccessListenerTest extends TestCase
$tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
false
);
@ -317,7 +317,7 @@ class AccessListenerTest extends TestCase
$tokenStorage,
$accessDecisionManager,
$accessMap,
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
false
);

View File

@ -42,16 +42,16 @@ class SwitchUserListenerTest extends TestCase
protected function setUp(): void
{
$this->tokenStorage = new TokenStorage();
$this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
$this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
$this->accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock();
$this->userProvider = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserProviderInterface::class)->getMock();
$this->userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
$this->accessDecisionManager = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface::class)->getMock();
$this->request = new Request();
$this->event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $this->request, HttpKernelInterface::MASTER_REQUEST);
}
public function testFirewallNameIsRequired()
{
$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('$firewallName must not be empty');
new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, '', $this->accessDecisionManager);
}
@ -67,7 +67,7 @@ class SwitchUserListenerTest extends TestCase
public function testExitUserThrowsAuthenticationExceptionIfNoCurrentToken()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException::class);
$this->tokenStorage->setToken(null);
$this->request->query->set('_switch_user', '_exit');
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
@ -76,7 +76,7 @@ class SwitchUserListenerTest extends TestCase
public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBeFound()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException::class);
$token = new UsernamePasswordToken('username', '', 'key', ['ROLE_FOO']);
$this->tokenStorage->setToken($token);
@ -98,15 +98,15 @@ class SwitchUserListenerTest extends TestCase
$this->assertSame([], $this->request->query->all());
$this->assertSame('', $this->request->server->get('QUERY_STRING'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $this->event->getResponse());
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $this->event->getResponse());
$this->assertSame($this->request->getUri(), $this->event->getResponse()->getTargetUrl());
$this->assertSame($originalToken, $this->tokenStorage->getToken());
}
public function testExitUserDispatchesEventWithRefreshedUser()
{
$originalUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$refreshedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$originalUser = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$refreshedUser = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$this
->userProvider
->expects($this->any())
@ -156,7 +156,7 @@ class SwitchUserListenerTest extends TestCase
public function testSwitchUserIsDisallowed()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
$token = new UsernamePasswordToken('username', '', 'key', ['ROLE_FOO']);
$user = new User('username', 'password', []);
@ -178,7 +178,7 @@ class SwitchUserListenerTest extends TestCase
public function testSwitchUserTurnsAuthenticationExceptionTo403()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
$token = new UsernamePasswordToken('username', '', 'key', ['ROLE_ALLOWED_TO_SWITCH']);
$this->tokenStorage->setToken($token);
@ -220,7 +220,7 @@ class SwitchUserListenerTest extends TestCase
$this->assertSame([], $this->request->query->all());
$this->assertSame('', $this->request->server->get('QUERY_STRING'));
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken());
$this->assertInstanceOf(UsernamePasswordToken::class, $this->tokenStorage->getToken());
}
public function testSwitchUserAlreadySwitched()
@ -280,7 +280,7 @@ class SwitchUserListenerTest extends TestCase
$this->assertSame([], $this->request->query->all());
$this->assertSame('', $this->request->server->get('QUERY_STRING'));
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken());
$this->assertInstanceOf(UsernamePasswordToken::class, $this->tokenStorage->getToken());
}
public function testSwitchUserKeepsOtherQueryStringParameters()
@ -310,7 +310,7 @@ class SwitchUserListenerTest extends TestCase
$listener($this->event);
$this->assertSame('page=3&section=2', $this->request->server->get('QUERY_STRING'));
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken());
$this->assertInstanceOf(UsernamePasswordToken::class, $this->tokenStorage->getToken());
}
public function testSwitchUserWithReplacedToken()
@ -357,7 +357,7 @@ class SwitchUserListenerTest extends TestCase
public function testSwitchUserThrowsAuthenticationExceptionIfNoCurrentToken()
{
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException::class);
$this->tokenStorage->setToken(null);
$this->request->query->set('_switch_user', 'username');
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
@ -386,7 +386,7 @@ class SwitchUserListenerTest extends TestCase
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', null, true);
$listener($this->event);
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken());
$this->assertInstanceOf(UsernamePasswordToken::class, $this->tokenStorage->getToken());
$this->assertFalse($this->event->hasResponse());
}
}

View File

@ -33,9 +33,9 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
public function testHandleWhenUsernameLength($username, $ok)
{
$request = Request::create('/login_check', 'POST', ['_username' => $username, '_password' => 'symfony']);
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
$httpUtils = $this->getMockBuilder(HttpUtils::class)->getMock();
$httpUtils
->expects($this->any())
->method('checkRequestPath')
@ -46,14 +46,14 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
->willReturn(new RedirectResponse('/hello'))
;
$failureHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface')->getMock();
$failureHandler = $this->getMockBuilder(\Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface::class)->getMock();
$failureHandler
->expects($ok ? $this->never() : $this->once())
->method('onAuthenticationFailure')
->willReturn(new Response())
;
$authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager')->disableOriginalConstructor()->getMock();
$authenticationManager = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager::class)->disableOriginalConstructor()->getMock();
$authenticationManager
->expects($ok ? $this->once() : $this->never())
->method('authenticate')
@ -61,9 +61,9 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
;
$listener = new UsernamePasswordFormAuthenticationListener(
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock(),
$authenticationManager,
$this->getMockBuilder('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface::class)->getMock(),
$httpUtils,
'TheProviderKey',
new DefaultAuthenticationSuccessHandler($httpUtils),
@ -86,18 +86,18 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
*/
public function testHandleNonStringUsernameWithArray($postOnly)
{
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
$this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_username" must be a string, "array" given.');
$request = Request::create('/login_check', 'POST', ['_username' => []]);
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
$listener = new UsernamePasswordFormAuthenticationListener(
new TokenStorage(),
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
$httpUtils = new HttpUtils(),
'foo',
new DefaultAuthenticationSuccessHandler($httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
['require_previous_session' => false, 'post_only' => $postOnly]
);
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
@ -109,18 +109,18 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
*/
public function testHandleNonStringUsernameWithInt($postOnly)
{
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
$this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_username" must be a string, "int" given.');
$request = Request::create('/login_check', 'POST', ['_username' => 42]);
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
$listener = new UsernamePasswordFormAuthenticationListener(
new TokenStorage(),
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
$httpUtils = new HttpUtils(),
'foo',
new DefaultAuthenticationSuccessHandler($httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
['require_previous_session' => false, 'post_only' => $postOnly]
);
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
@ -132,18 +132,18 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
*/
public function testHandleNonStringUsernameWithObject($postOnly)
{
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
$this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_username" must be a string, "stdClass" given.');
$request = Request::create('/login_check', 'POST', ['_username' => new \stdClass()]);
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
$listener = new UsernamePasswordFormAuthenticationListener(
new TokenStorage(),
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
$httpUtils = new HttpUtils(),
'foo',
new DefaultAuthenticationSuccessHandler($httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
['require_previous_session' => false, 'post_only' => $postOnly]
);
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
@ -162,18 +162,18 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
->willReturn('someUsername');
$request = Request::create('/login_check', 'POST', ['_username' => $usernameClass, '_password' => 'symfony']);
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
$listener = new UsernamePasswordFormAuthenticationListener(
new TokenStorage(),
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
$httpUtils = new HttpUtils(),
'foo',
new DefaultAuthenticationSuccessHandler($httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
['require_previous_session' => false, 'post_only' => $postOnly]
);
$event = new RequestEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
$listener($event);
}
@ -182,19 +182,19 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
*/
public function testHandleWhenPasswordAreNull($postOnly)
{
$this->expectException('LogicException');
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The key "_password" cannot be null; check that the password field name of the form matches.');
$request = Request::create('/login_check', 'POST', ['_username' => 'symfony', 'password' => 'symfony']);
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
$listener = new UsernamePasswordFormAuthenticationListener(
new TokenStorage(),
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
$httpUtils = new HttpUtils(),
'foo',
new DefaultAuthenticationSuccessHandler($httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
['require_previous_session' => false, 'post_only' => $postOnly]
);
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);

View File

@ -20,7 +20,7 @@ class RedisArrayStoreTest extends AbstractRedisStoreTest
{
public static function setUpBeforeClass(): void
{
if (!class_exists('RedisArray')) {
if (!class_exists(\RedisArray::class)) {
self::markTestSkipped('The RedisArray class is required.');
}
try {

View File

@ -160,7 +160,7 @@ class BicValidatorTest extends ConstraintValidatorTestCase
*/
public function testThrowsConstraintExceptionIfBothValueAndPropertyPathNamed()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('The "iban" and "ibanPropertyPath" options of the Iban constraint cannot be used at the same time');
eval('new \Symfony\Component\Validator\Constraints\Bic(iban: "value", ibanPropertyPath: "propertyPath");');

View File

@ -12,7 +12,7 @@ class RangeTest extends TestCase
public function testThrowsConstraintExceptionIfBothMinLimitAndPropertyPath()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('requires only one of the "min" or "minPropertyPath" options to be set, not both.');
new Range([
'min' => 'min',
@ -25,14 +25,14 @@ class RangeTest extends TestCase
*/
public function testThrowsConstraintExceptionIfBothMinLimitAndPropertyPathNamed()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('requires only one of the "min" or "minPropertyPath" options to be set, not both.');
eval('new \Symfony\Component\Validator\Constraints\Range(min: "min", minPropertyPath: "minPropertyPath");');
}
public function testThrowsConstraintExceptionIfBothMaxLimitAndPropertyPath()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('requires only one of the "max" or "maxPropertyPath" options to be set, not both.');
new Range([
'max' => 'max',
@ -45,14 +45,14 @@ class RangeTest extends TestCase
*/
public function testThrowsConstraintExceptionIfBothMaxLimitAndPropertyPathNamed()
{
$this->expectException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectExceptionMessage('requires only one of the "max" or "maxPropertyPath" options to be set, not both.');
eval('new \Symfony\Component\Validator\Constraints\Range(max: "max", maxPropertyPath: "maxPropertyPath");');
}
public function testThrowsConstraintExceptionIfNoLimitNorPropertyPath()
{
$this->expectException('Symfony\Component\Validator\Exception\MissingOptionsException');
$this->expectException(\Symfony\Component\Validator\Exception\MissingOptionsException::class);
$this->expectExceptionMessage('Either option "min", "minPropertyPath", "max" or "maxPropertyPath" must be given');
new Range([]);
}

View File

@ -21,7 +21,7 @@ class GetterMetadataTest extends TestCase
public function testInvalidPropertyName()
{
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
$this->expectException(\Symfony\Component\Validator\Exception\ValidatorException::class);
new GetterMetadata(self::CLASSNAME, 'foobar');
}
@ -63,7 +63,7 @@ class GetterMetadataTest extends TestCase
public function testUndefinedMethodNameThrowsException()
{
$this->expectException('Symfony\Component\Validator\Exception\ValidatorException');
$this->expectException(\Symfony\Component\Validator\Exception\ValidatorException::class);
$this->expectExceptionMessage('The "hasLastName()" method does not exist in class "Symfony\Component\Validator\Tests\Fixtures\Annotation\Entity".');
new GetterMetadata(self::CLASSNAME, 'lastName', 'hasLastName');
}