Use createMock() and use import instead of FQCN

This commit is contained in:
Oskar Stark 2021-01-22 13:09:22 +01:00 committed by Nicolas Grekas
parent 484a95d8d1
commit e7e61ee551
622 changed files with 3640 additions and 2845 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Version;
use Doctrine\Persistence\ManagerRegistry;
@ -236,7 +237,7 @@ EOTXT
->method('getDatabasePlatform')
->willReturn(new MySqlPlatform());
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry = $this->createMock(ManagerRegistry::class);
$registry
->expects($this->any())
->method('getConnectionNames')
@ -249,7 +250,7 @@ EOTXT
->method('getConnection')
->willReturn($connection);
$logger = $this->getMockBuilder(\Doctrine\DBAL\Logging\DebugStack::class)->getMock();
$logger = $this->createMock(DebugStack::class);
$logger->queries = $queries;
$collector = new DoctrineDataCollector($registry);

View File

@ -14,12 +14,13 @@ namespace Symfony\Bridge\Doctrine\Tests\DataFixtures;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Symfony\Bridge\Doctrine\Tests\Fixtures\ContainerAwareFixture;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContainerAwareLoaderTest extends TestCase
{
public function testShouldSetContainerOnContainerAwareFixture()
{
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
$container = $this->createMock(ContainerInterface::class);
$loader = new ContainerAwareLoader($container);
$fixture = new ContainerAwareFixture();

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@ -22,7 +23,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class DoctrineExtensionTest extends TestCase
{
/**
* @var \Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension
* @var AbstractDoctrineExtension
*/
private $extension;
@ -31,7 +32,7 @@ class DoctrineExtensionTest extends TestCase
parent::setUp();
$this->extension = $this
->getMockBuilder(\Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension::class)
->getMockBuilder(AbstractDoctrineExtension::class)
->setMethods([
'getMappingResourceConfigDirectory',
'getObjectManagerElementName',

View File

@ -75,19 +75,17 @@ class DoctrineChoiceLoaderTest extends TestCase
protected function setUp(): void
{
$this->factory = $this->getMockBuilder(ChoiceListFactoryInterface::class)->getMock();
$this->om = $this->getMockBuilder(ObjectManager::class)->getMock();
$this->repository = $this->getMockBuilder(ObjectRepository::class)->getMock();
$this->factory = $this->createMock(ChoiceListFactoryInterface::class);
$this->om = $this->createMock(ObjectManager::class);
$this->repository = $this->createMock(ObjectRepository::class);
$this->class = 'stdClass';
$this->idReader = $this->getMockBuilder(IdReader::class)
->disableOriginalConstructor()
->getMock();
$this->idReader = $this->createMock(IdReader::class);
$this->idReader->expects($this->any())
->method('isSingleId')
->willReturn(true)
;
$this->objectLoader = $this->getMockBuilder(EntityLoaderInterface::class)->getMock();
$this->objectLoader = $this->createMock(EntityLoaderInterface::class);
$this->obj1 = (object) ['name' => 'A'];
$this->obj2 = (object) ['name' => 'B'];
$this->obj3 = (object) ['name' => 'C'];

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\DataTransformer;
use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -64,7 +65,7 @@ class CollectionToArrayTransformerTest extends TestCase
public function testTransformExpectsArrayOrCollection()
{
$this->expectException(\Symfony\Component\Form\Exception\TransformationFailedException::class);
$this->expectException(TransformationFailedException::class);
$this->transformer->transform('Foo');
}

View File

@ -34,21 +34,21 @@ class DoctrineOrmTypeGuesserTest extends TestCase
$return = [];
// Simple field, not nullable
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->fieldMappings['field'] = true;
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(false);
$return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)];
// Simple field, nullable
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->fieldMappings['field'] = true;
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(true);
$return[] = [$classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE)];
// One-to-one, nullable (by default)
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
$mapping = ['joinColumns' => [[]]];
@ -57,7 +57,7 @@ class DoctrineOrmTypeGuesserTest extends TestCase
$return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)];
// One-to-one, nullable (explicit)
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
$mapping = ['joinColumns' => [['nullable' => true]]];
@ -66,7 +66,7 @@ class DoctrineOrmTypeGuesserTest extends TestCase
$return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)];
// One-to-one, not nullable
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
$mapping = ['joinColumns' => [['nullable' => false]]];
@ -75,7 +75,7 @@ class DoctrineOrmTypeGuesserTest extends TestCase
$return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)];
// One-to-many, no clue
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->disableOriginalConstructor()->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(false);
$return[] = [$classMetadata, null];
@ -85,10 +85,10 @@ class DoctrineOrmTypeGuesserTest extends TestCase
private function getGuesser(ClassMetadata $classMetadata)
{
$em = $this->getMockBuilder(ObjectManager::class)->getMock();
$em = $this->createMock(ObjectManager::class);
$em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->willReturn($classMetadata);
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry = $this->createMock(ManagerRegistry::class);
$registry->expects($this->once())->method('getManagers')->willReturn([$em]);
return new DoctrineOrmTypeGuesser($registry);

View File

@ -18,6 +18,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
class MergeDoctrineCollectionListenerTest extends TestCase
{
@ -32,7 +33,7 @@ class MergeDoctrineCollectionListenerTest extends TestCase
{
$this->collection = new ArrayCollection(['test']);
$this->dispatcher = new EventDispatcher();
$this->factory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
$this->factory = $this->createMock(FormFactoryInterface::class);
$this->form = $this->getBuilder()
->getForm();
}

View File

@ -35,7 +35,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
protected function getExtensions()
{
$manager = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$manager = $this->createMock(ManagerRegistry::class);
$manager->expects($this->any())
->method('getManager')

View File

@ -29,11 +29,16 @@ use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringCastableIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Exception\RuntimeException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Tests\Extension\Core\Type\BaseTypeTest;
use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
class EntityTypeTest extends BaseTypeTest
{
@ -118,13 +123,13 @@ class EntityTypeTest extends BaseTypeTest
public function testClassOptionIsRequired()
{
$this->expectException(\Symfony\Component\OptionsResolver\Exception\MissingOptionsException::class);
$this->expectException(MissingOptionsException::class);
$this->factory->createNamed('name', static::TESTED_TYPE);
}
public function testInvalidClassOption()
{
$this->expectException(\Symfony\Component\Form\Exception\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->factory->createNamed('name', static::TESTED_TYPE, null, [
'class' => 'foo',
]);
@ -219,7 +224,7 @@ class EntityTypeTest extends BaseTypeTest
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
{
$this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class);
$this->expectException(InvalidOptionsException::class);
$this->factory->createNamed('name', static::TESTED_TYPE, null, [
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
@ -229,7 +234,7 @@ class EntityTypeTest extends BaseTypeTest
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
{
$this->expectException(\Symfony\Component\Form\Exception\UnexpectedTypeException::class);
$this->expectException(UnexpectedTypeException::class);
$field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
@ -1242,7 +1247,7 @@ class EntityTypeTest extends BaseTypeTest
$choiceLoader2 = $form->get('property2')->getConfig()->getOption('choice_loader');
$choiceLoader3 = $form->get('property3')->getConfig()->getOption('choice_loader');
$this->assertInstanceOf(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class, $choiceLoader1);
$this->assertInstanceOf(ChoiceLoaderInterface::class, $choiceLoader1);
$this->assertSame($choiceLoader1, $choiceLoader2);
$this->assertSame($choiceLoader1, $choiceLoader3);
}
@ -1302,14 +1307,14 @@ class EntityTypeTest extends BaseTypeTest
$choiceLoader2 = $form->get('property2')->getConfig()->getOption('choice_loader');
$choiceLoader3 = $form->get('property3')->getConfig()->getOption('choice_loader');
$this->assertInstanceOf(\Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::class, $choiceLoader1);
$this->assertInstanceOf(ChoiceLoaderInterface::class, $choiceLoader1);
$this->assertSame($choiceLoader1, $choiceLoader2);
$this->assertSame($choiceLoader1, $choiceLoader3);
}
protected function createRegistryMock($name, $em)
{
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry = $this->createMock(ManagerRegistry::class);
$registry->expects($this->any())
->method('getManager')
->with($this->equalTo($name))

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\Tests\Logger;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Doctrine\Logger\DbalLogger;
class DbalLoggerTest extends TestCase
@ -21,7 +22,7 @@ class DbalLoggerTest extends TestCase
*/
public function testLog($sql, $params, $logParams)
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);
$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
@ -53,7 +54,7 @@ class DbalLoggerTest extends TestCase
public function testLogNonUtf8()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);
$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
@ -76,7 +77,7 @@ class DbalLoggerTest extends TestCase
public function testLogNonUtf8Array()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);
$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
@ -107,7 +108,7 @@ class DbalLoggerTest extends TestCase
public function testLogLongString()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);
$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
@ -135,7 +136,7 @@ class DbalLoggerTest extends TestCase
public function testLogUTF8LongString()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);
$dbalLogger = $this
->getMockBuilder(DbalLogger::class)

View File

@ -11,6 +11,7 @@
namespace Symfony\Bridge\Doctrine\Tests\Security\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
@ -20,6 +21,7 @@ use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\User;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
@ -71,9 +73,7 @@ class EntityUserProviderTest extends TestCase
->with('user1')
->willReturn($user);
$em = $this->getMockBuilder(\Doctrine\ORM\EntityManager::class)
->disableOriginalConstructor()
->getMock();
$em = $this->createMock(EntityManager::class);
$em
->expects($this->once())
->method('getRepository')
@ -125,7 +125,7 @@ class EntityUserProviderTest extends TestCase
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
$user2 = new User(1, 2, 'user2');
$this->expectException(\Symfony\Component\Security\Core\Exception\UsernameNotFoundException::class);
$this->expectException(UsernameNotFoundException::class);
$this->expectExceptionMessage('User with id {"id1":1,"id2":2} not found');
$provider->refreshUser($user2);
@ -155,7 +155,7 @@ class EntityUserProviderTest extends TestCase
->method('loadUserByUsername')
->with('name')
->willReturn(
$this->getMockBuilder(UserInterface::class)->getMock()
$this->createMock(UserInterface::class)
);
$provider = new EntityUserProvider(
@ -198,7 +198,7 @@ class EntityUserProviderTest extends TestCase
private function getManager($em, $name = null)
{
$manager = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$manager = $this->createMock(ManagerRegistry::class);
$manager->expects($this->any())
->method('getManager')
->with($this->equalTo($name))

View File

@ -22,6 +22,7 @@ use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Test\TestRepositoryFactory;
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2;
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNullableNameEntity;
@ -30,9 +31,12 @@ use Symfony\Bridge\Doctrine\Tests\Fixtures\Person;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdStringWrapperNameEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapperType;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
@ -67,7 +71,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
$config->setRepositoryFactory($this->repositoryFactory);
if (!Type::hasType('string_wrapper')) {
Type::addType('string_wrapper', 'Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapperType');
Type::addType('string_wrapper', StringWrapperType::class);
}
$this->em = DoctrineTestHelper::createTestEntityManager($config);
@ -79,7 +83,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
protected function createRegistryMock($em = null)
{
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry = $this->createMock(ManagerRegistry::class);
$registry->expects($this->any())
->method('getManager')
->with($this->equalTo(self::EM_NAME))
@ -100,15 +104,13 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
protected function createEntityManagerMock($repositoryMock)
{
$em = $this->getMockBuilder(ObjectManager::class)
->getMock()
;
$em = $this->createMock(ObjectManager::class);
$em->expects($this->any())
->method('getRepository')
->willReturn($repositoryMock)
;
$classMetadata = $this->getMockBuilder(ClassMetadata::class)->getMock();
$classMetadata = $this->createMock(ClassMetadata::class);
$classMetadata
->expects($this->any())
->method('hasField')
@ -137,17 +139,17 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
{
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema([
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNullableNameEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\Person'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\Employee'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity'),
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdStringWrapperNameEntity'),
$em->getClassMetadata(SingleIntIdEntity::class),
$em->getClassMetadata(SingleIntIdNoToStringEntity::class),
$em->getClassMetadata(DoubleNameEntity::class),
$em->getClassMetadata(DoubleNullableNameEntity::class),
$em->getClassMetadata(CompositeIntIdEntity::class),
$em->getClassMetadata(AssociationEntity::class),
$em->getClassMetadata(AssociationEntity2::class),
$em->getClassMetadata(Person::class),
$em->getClassMetadata(Employee::class),
$em->getClassMetadata(CompositeObjectNoToStringIdEntity::class),
$em->getClassMetadata(SingleIntIdStringWrapperNameEntity::class),
]);
}
@ -269,7 +271,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgnoreNullEnabled()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class);
$constraint = new UniqueEntity([
'message' => 'myMessage',
'fields' => ['name', 'name2'],
@ -540,7 +542,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testValidateUniquenessWithArrayValue()
{
$repository = $this->createRepositoryMock();
$this->repositoryFactory->setRepository($this->em, 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity', $repository);
$this->repositoryFactory->setRepository($this->em, SingleIntIdEntity::class, $repository);
$constraint = new UniqueEntity([
'message' => 'myMessage',
@ -578,7 +580,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testDedicatedEntityManagerNullObject()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('Object manager "foo" does not exist.');
$constraint = new UniqueEntity([
'message' => 'myMessage',
@ -598,7 +600,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testEntityManagerNullObject()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(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',
@ -650,7 +652,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
'message' => 'myMessage',
'fields' => ['name'],
'em' => self::EM_NAME,
'entityClass' => 'Symfony\Bridge\Doctrine\Tests\Fixtures\Person',
'entityClass' => Person::class,
]);
$entity1 = new Person(1, 'Foo');
@ -680,13 +682,13 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
public function testInvalidateRepositoryForInheritance()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(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',
'fields' => ['name'],
'em' => self::EM_NAME,
'entityClass' => 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity',
'entityClass' => SingleStringIdEntity::class,
]);
$entity = new Person(1, 'Foo');

View File

@ -13,12 +13,15 @@ namespace Symfony\Bridge\Monolog\Tests\Handler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
@ -46,7 +49,7 @@ class ConsoleHandlerTest extends TestCase
*/
public function testVerbosityMapping($verbosity, $level, $isHandling, array $map = [])
{
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
$output = $this->createMock(OutputInterface::class);
$output
->expects($this->atLeastOnce())
->method('getVerbosity')
@ -61,7 +64,7 @@ class ConsoleHandlerTest extends TestCase
$levelName = Logger::getLevelName($level);
$levelName = sprintf('%-9s', $levelName);
$realOutput = $this->getMockBuilder(\Symfony\Component\Console\Output\Output::class)->setMethods(['doWrite'])->getMock();
$realOutput = $this->getMockBuilder(Output::class)->setMethods(['doWrite'])->getMock();
$realOutput->setVerbosity($verbosity);
if ($realOutput->isDebug()) {
$log = "16:21:54 $levelName [app] My info message\n";
@ -110,7 +113,7 @@ class ConsoleHandlerTest extends TestCase
public function testVerbosityChanged()
{
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
$output = $this->createMock(OutputInterface::class);
$output
->expects($this->exactly(2))
->method('getVerbosity')
@ -131,14 +134,15 @@ class ConsoleHandlerTest extends TestCase
public function testGetFormatter()
{
$handler = new ConsoleHandler();
$this->assertInstanceOf(\Symfony\Bridge\Monolog\Formatter\ConsoleFormatter::class, $handler->getFormatter(),
'-getFormatter returns ConsoleFormatter by default'
$this->assertInstanceOf(
ConsoleFormatter::class, $handler->getFormatter(),
'->getFormatter returns ConsoleFormatter by default'
);
}
public function testWritingAndFormatting()
{
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
$output = $this->createMock(OutputInterface::class);
$output
->expects($this->any())
->method('getVerbosity')
@ -193,12 +197,12 @@ class ConsoleHandlerTest extends TestCase
$logger->info('After terminate message.');
});
$event = new ConsoleCommandEvent(new Command('foo'), $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock(), $output);
$event = new ConsoleCommandEvent(new Command('foo'), $this->createMock(InputInterface::class), $output);
$dispatcher->dispatch($event, ConsoleEvents::COMMAND);
$this->assertStringContainsString('Before command message.', $out = $output->fetch());
$this->assertStringContainsString('After command message.', $out);
$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock(), $output, 0);
$event = new ConsoleTerminateEvent(new Command('foo'), $this->createMock(InputInterface::class), $output, 0);
$dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
$this->assertStringContainsString('Before terminate message.', $out = $output->fetch());
$this->assertStringContainsString('After terminate message.', $out);

View File

@ -44,7 +44,7 @@ class ServerLogHandlerTest extends TestCase
{
$handler = new ServerLogHandler('tcp://127.0.0.1:9999');
$this->assertInstanceOf(VarDumperFormatter::class, $handler->getFormatter(),
'-getFormatter returns VarDumperFormatter by default'
'->getFormatter returns VarDumperFormatter by default'
);
}

View File

@ -84,7 +84,7 @@ class LoggerTest extends TestCase
public function testGetLogsWithDebugProcessor3()
{
$request = new Request();
$processor = $this->getMockBuilder(DebugProcessor::class)->getMock();
$processor = $this->createMock(DebugProcessor::class);
$processor->expects($this->once())->method('getLogs')->with($request);
$processor->expects($this->once())->method('countErrors')->with($request);

View File

@ -61,12 +61,12 @@ class ConsoleCommandProcessorTest extends TestCase
private function getConsoleEvent(): ConsoleEvent
{
$input = $this->getMockBuilder(InputInterface::class)->getMock();
$input = $this->createMock(InputInterface::class);
$input->method('getArguments')->willReturn(self::TEST_ARGUMENTS);
$input->method('getOptions')->willReturn(self::TEST_OPTIONS);
$command = $this->getMockBuilder(Command::class)->disableOriginalConstructor()->getMock();
$command = $this->createMock(Command::class);
$command->method('getName')->willReturn(self::TEST_NAME);
$consoleEvent = $this->getMockBuilder(ConsoleEvent::class)->disableOriginalConstructor()->getMock();
$consoleEvent = $this->createMock(ConsoleEvent::class);
$consoleEvent->method('getCommand')->willReturn($command);
$consoleEvent->method('getInput')->willReturn($input);

View File

@ -149,7 +149,7 @@ class RouteProcessorTest extends TestCase
private function mockRequest(array $attributes): Request
{
$request = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
$request = $this->createMock(Request::class);
$request->attributes = new ParameterBag($attributes);
return $request;

View File

@ -26,7 +26,7 @@ class TokenProcessorTest extends TestCase
public function testProcessor()
{
$token = new UsernamePasswordToken('user', 'password', 'provider', ['ROLE_USER']);
$tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$tokenStorage->method('getToken')->willReturn($token);
$processor = new TokenProcessor($tokenStorage);

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper;
use PHPUnit\Framework\TestCase;
use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@ -46,7 +47,7 @@ class PhpDumperTest extends TestCase
$proxy = $container->get('foo');
$this->assertInstanceOf(\stdClass::class, $proxy);
$this->assertInstanceOf(\ProxyManager\Proxy\LazyLoadingInterface::class, $proxy);
$this->assertInstanceOf(LazyLoadingInterface::class, $proxy);
$this->assertSame($proxy, $container->get('foo'));
$this->assertFalse($proxy->isProxyInitialized());

View File

@ -12,7 +12,10 @@
namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Instantiator;
use PHPUnit\Framework\TestCase;
use ProxyManager\Proxy\LazyLoadingInterface;
use ProxyManager\Proxy\ValueHolderInterface;
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
/**
@ -38,17 +41,17 @@ class RuntimeInstantiatorTest extends TestCase
public function testInstantiateProxy()
{
$instance = new \stdClass();
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
$container = $this->createMock(ContainerInterface::class);
$definition = new Definition('stdClass');
$instantiator = function () use ($instance) {
return $instance;
};
/* @var $proxy \ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */
/* @var $proxy LazyLoadingInterface|ValueHolderInterface */
$proxy = $this->instantiator->instantiateProxy($container, $definition, 'foo', $instantiator);
$this->assertInstanceOf(\ProxyManager\Proxy\LazyLoadingInterface::class, $proxy);
$this->assertInstanceOf(\ProxyManager\Proxy\ValueHolderInterface::class, $proxy);
$this->assertInstanceOf(LazyLoadingInterface::class, $proxy);
$this->assertInstanceOf(ValueHolderInterface::class, $proxy);
$this->assertFalse($proxy->isProxyInitialized());
$proxy->initializeProxy();

View File

@ -5,8 +5,12 @@ namespace Symfony\Bridge\Twig\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\AppVariable;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class AppVariableTest extends TestCase
{
@ -50,7 +54,7 @@ class AppVariableTest extends TestCase
*/
public function testGetSession()
{
$request = $this->getMockBuilder(Request::class)->getMock();
$request = $this->createMock(Request::class);
$request->method('hasSession')->willReturn(true);
$request->method('getSession')->willReturn($session = new Session());
@ -75,10 +79,10 @@ class AppVariableTest extends TestCase
public function testGetToken()
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->appVariable->setTokenStorage($tokenStorage);
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
$token = $this->createMock(TokenInterface::class);
$tokenStorage->method('getToken')->willReturn($token);
$this->assertEquals($token, $this->appVariable->getToken());
@ -86,7 +90,7 @@ class AppVariableTest extends TestCase
public function testGetUser()
{
$this->setTokenStorage($user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock());
$this->setTokenStorage($user = $this->createMock(UserInterface::class));
$this->assertEquals($user, $this->appVariable->getUser());
}
@ -100,7 +104,7 @@ class AppVariableTest extends TestCase
public function testGetTokenWithNoToken()
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->appVariable->setTokenStorage($tokenStorage);
$this->assertNull($this->appVariable->getToken());
@ -108,7 +112,7 @@ class AppVariableTest extends TestCase
public function testGetUserWithNoToken()
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->appVariable->setTokenStorage($tokenStorage);
$this->assertNull($this->appVariable->getUser());
@ -224,7 +228,7 @@ class AppVariableTest extends TestCase
protected function setRequestStack($request)
{
$requestStackMock = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStackMock = $this->createMock(RequestStack::class);
$requestStackMock->method('getCurrentRequest')->willReturn($request);
$this->appVariable->setRequestStack($requestStackMock);
@ -232,10 +236,10 @@ class AppVariableTest extends TestCase
protected function setTokenStorage($user)
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->appVariable->setTokenStorage($tokenStorage);
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
$token = $this->createMock(TokenInterface::class);
$tokenStorage->method('getToken')->willReturn($token);
$token->method('getUser')->willReturn($user);
@ -251,11 +255,11 @@ class AppVariableTest extends TestCase
$flashBag = new FlashBag();
$flashBag->initialize($flashMessages);
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$session->method('isStarted')->willReturn($sessionHasStarted);
$session->method('getFlashBag')->willReturn($flashBag);
$request = $this->getMockBuilder(Request::class)->getMock();
$request = $this->createMock(Request::class);
$request->method('hasSession')->willReturn(true);
$request->method('getSession')->willReturn($session);
$this->setRequestStack($request);

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\Tests\Command;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Command\DebugCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Tester\CommandTester;
use Twig\Environment;
use Twig\Loader\ChainLoader;
@ -91,7 +92,7 @@ class DebugCommandTest extends TestCase
public function testMalformedTemplateName()
{
$this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Malformed namespaced template name "@foo" (expecting "@namespace/template_name").');
$this->createCommandTester()->execute(['name' => '@foo']);
}

View File

@ -18,6 +18,7 @@ use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\VarDumper\VarDumper;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\Loader\LoaderInterface;
class DumpExtensionTest extends TestCase
{
@ -67,7 +68,7 @@ class DumpExtensionTest extends TestCase
public function testDump($context, $args, $expectedOutput, $debug = true)
{
$extension = new DumpExtension(new VarCloner());
$twig = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), [
$twig = new Environment($this->createMock(LoaderInterface::class), [
'debug' => $debug,
'cache' => false,
'optimizations' => 0,
@ -124,7 +125,7 @@ class DumpExtensionTest extends TestCase
'</pre><script>Sfdump("%s")</script>'
);
$extension = new DumpExtension(new VarCloner(), $dumper);
$twig = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), [
$twig = new Environment($this->createMock(LoaderInterface::class), [
'debug' => true,
'cache' => false,
'optimizations' => 0,

View File

@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3HorizontalLayoutTest
@ -50,7 +51,7 @@ class FormExtensionBootstrap3HorizontalLayoutTest extends AbstractBootstrap3Hori
'bootstrap_3_horizontal_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}

View File

@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
@ -46,7 +47,7 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
'bootstrap_3_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}
@ -88,7 +89,7 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
'bootstrap_3_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
$view = $this->factory

View File

@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
/**
@ -52,7 +53,7 @@ class FormExtensionBootstrap4HorizontalLayoutTest extends AbstractBootstrap4Hori
'bootstrap_4_horizontal_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}

View File

@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
/**
@ -50,7 +51,7 @@ class FormExtensionBootstrap4LayoutTest extends AbstractBootstrap4LayoutTest
'bootstrap_4_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}
@ -92,7 +93,7 @@ class FormExtensionBootstrap4LayoutTest extends AbstractBootstrap4LayoutTest
'bootstrap_4_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
$view = $this->factory

View File

@ -20,6 +20,7 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
@ -53,7 +54,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
'form_div_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}
@ -181,7 +182,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
'form_div_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
$view = $this->factory

View File

@ -19,6 +19,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Tests\AbstractTableLayoutTest;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
@ -50,7 +51,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
'form_table_layout.html.twig',
'custom_widgets.html.twig',
], $environment);
$this->renderer = new FormRenderer($rendererEngine, $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock());
$this->renderer = new FormRenderer($rendererEngine, $this->createMock(CsrfTokenManagerInterface::class));
$this->registerTwigRuntimeLoader($environment, $this->renderer);
}

View File

@ -15,10 +15,13 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\RuntimeLoader\RuntimeLoaderInterface;
class HttpKernelExtensionTest extends TestCase
{
@ -41,10 +44,7 @@ class HttpKernelExtensionTest extends TestCase
public function testUnknownFragmentRenderer()
{
$context = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)
->disableOriginalConstructor()
->getMock()
;
$context = $this->createMock(RequestStack::class);
$renderer = new FragmentHandler($context);
$this->expectException(\InvalidArgumentException::class);
@ -55,14 +55,11 @@ class HttpKernelExtensionTest extends TestCase
protected function getFragmentHandler($return)
{
$strategy = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock();
$strategy = $this->createMock(FragmentRendererInterface::class);
$strategy->expects($this->once())->method('getName')->willReturn('inline');
$strategy->expects($this->once())->method('render')->will($return);
$context = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)
->disableOriginalConstructor()
->getMock()
;
$context = $this->createMock(RequestStack::class);
$context->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));
@ -75,7 +72,7 @@ class HttpKernelExtensionTest extends TestCase
$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
$twig->addExtension(new HttpKernelExtension());
$loader = $this->getMockBuilder(\Twig\RuntimeLoader\RuntimeLoaderInterface::class)->getMock();
$loader = $this->createMock(RuntimeLoaderInterface::class);
$loader->expects($this->any())->method('load')->willReturnMap([
['Symfony\Bridge\Twig\Extension\HttpKernelRuntime', new HttpKernelRuntime($renderer)],
]);

View File

@ -13,7 +13,9 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\RoutingExtension;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\FilterExpression;
use Twig\Source;
@ -24,8 +26,8 @@ class RoutingExtensionTest extends TestCase
*/
public function testEscaping($template, $mustBeEscaped)
{
$twig = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), ['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);
$twig->addExtension(new RoutingExtension($this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock()));
$twig = new Environment($this->createMock(LoaderInterface::class), ['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);
$twig->addExtension(new RoutingExtension($this->createMock(UrlGeneratorInterface::class)));
$nodes = $twig->parse($twig->tokenize(new Source($template, '')));

View File

@ -13,12 +13,13 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
use Symfony\Component\Form\FormRenderer;
use Twig\Environment;
use Twig\RuntimeLoader\RuntimeLoaderInterface;
trait RuntimeLoaderProvider
{
protected function registerTwigRuntimeLoader(Environment $environment, FormRenderer $renderer)
{
$loader = $this->getMockBuilder(\Twig\RuntimeLoader\RuntimeLoaderInterface::class)->getMock();
$loader = $this->createMock(RuntimeLoaderInterface::class);
$loader->expects($this->any())->method('load')->will($this->returnValueMap([
['Symfony\Component\Form\FormRenderer', $renderer],
]));

View File

@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\StopwatchExtension;
use Symfony\Component\Stopwatch\Stopwatch;
use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Loader\ArrayLoader;
@ -55,7 +56,7 @@ class StopwatchExtensionTest extends TestCase
protected function getStopwatch($events = [])
{
$events = \is_array($events) ? $events : [$events];
$stopwatch = $this->getMockBuilder(\Symfony\Component\Stopwatch\Stopwatch::class)->getMock();
$stopwatch = $this->createMock(Stopwatch::class);
$expectedCalls = 0;
$expectedStartCalls = [];

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\DumpNode;
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Node;
@ -24,7 +25,7 @@ class DumpNodeTest extends TestCase
{
$node = new DumpNode('bar', null, 7);
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock());
$env = new Environment($this->createMock(LoaderInterface::class));
$compiler = new Compiler($env);
$expected = <<<'EOTXT'
@ -48,7 +49,7 @@ EOTXT;
{
$node = new DumpNode('bar', null, 7);
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock());
$env = new Environment($this->createMock(LoaderInterface::class));
$compiler = new Compiler($env);
$expected = <<<'EOTXT'
@ -75,7 +76,7 @@ EOTXT;
]);
$node = new DumpNode('bar', $vars, 7);
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock());
$env = new Environment($this->createMock(LoaderInterface::class));
$compiler = new Compiler($env);
$expected = <<<'EOTXT'
@ -99,7 +100,7 @@ EOTXT;
]);
$node = new DumpNode('bar', $vars, 7);
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock());
$env = new Environment($this->createMock(LoaderInterface::class));
$compiler = new Compiler($env);
$expected = <<<'EOTXT'

View File

@ -18,6 +18,7 @@ use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormRendererEngineInterface;
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\NameExpression;
@ -54,8 +55,8 @@ class FormThemeTest extends TestCase
$node = new FormThemeNode($form, $resources, 0);
$environment = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock());
$formRenderer = new FormRenderer($this->getMockBuilder(FormRendererEngineInterface::class)->getMock());
$environment = new Environment($this->createMock(LoaderInterface::class));
$formRenderer = new FormRenderer($this->createMock(FormRendererEngineInterface::class));
$this->registerTwigRuntimeLoader($environment, $formRenderer);
$compiler = new Compiler($environment);

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConditionalExpression;
use Twig\Node\Expression\ConstantExpression;
@ -31,7 +32,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
$this->assertEquals(
sprintf(
@ -54,7 +55,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
$this->assertEquals(
sprintf(
@ -74,7 +75,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
$this->assertEquals(
sprintf(
@ -94,7 +95,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@ -116,7 +117,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@ -137,7 +138,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
$this->assertEquals(
sprintf(
@ -161,7 +162,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@ -190,7 +191,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
$this->assertEquals(
sprintf(
@ -218,7 +219,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.
@ -255,7 +256,7 @@ class SearchAndRenderBlockNodeTest extends TestCase
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0);
$compiler = new Compiler(new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock()));
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
// "label" => null must not be included in the output!
// Otherwise the default label is overwritten with null.

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\TransNode;
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\NameExpression;
use Twig\Node\TextNode;
@ -29,7 +30,7 @@ class TransNodeTest extends TestCase
$vars = new NameExpression('foo', 0);
$node = new TransNode($body, null, null, $vars);
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), ['strict_variables' => true]);
$env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]);
$compiler = new Compiler($env);
$this->assertEquals(

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Node;
@ -26,7 +27,7 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
/** @dataProvider getDefaultDomainAssignmentTestData */
public function testDefaultDomainAssignment(Node $node)
{
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$visitor = new TranslationDefaultDomainNodeVisitor();
// visit trans_default_domain tag
@ -52,7 +53,7 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
/** @dataProvider getDefaultDomainAssignmentTestData */
public function testNewModuleWithoutDefaultDomainTag(Node $node)
{
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$visitor = new TranslationDefaultDomainNodeVisitor();
// visit trans_default_domain tag

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
@ -25,7 +26,7 @@ class TranslationNodeVisitorTest extends TestCase
/** @dataProvider getMessagesExtractionTestData */
public function testMessagesExtraction(Node $node, array $expectedMessages)
{
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$visitor = new TranslationNodeVisitor();
$visitor->enable();
$visitor->enterNode($node, $env);

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\FormThemeNode;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\NameExpression;
@ -28,7 +29,7 @@ class FormThemeTokenParserTest extends TestCase
*/
public function testCompile($source, $expected)
{
$env = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env->addTokenParser(new FormThemeTokenParser());
$source = new Source($source, '');
$stream = $env->tokenize($source);

View File

@ -18,6 +18,7 @@ use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\Loader\LoaderInterface;
class TwigExtractorTest extends TestCase
{
@ -26,14 +27,14 @@ class TwigExtractorTest extends TestCase
*/
public function testExtract($template, $messages)
{
$loader = $this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$twig = new Environment($loader, [
'strict_variables' => true,
'debug' => true,
'cache' => false,
'autoescape' => false,
]);
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
$twig->addExtension(new TranslationExtension($this->createMock(TranslatorInterface::class)));
$extractor = new TwigExtractor($twig);
$extractor->setPrefix('prefix');
@ -102,8 +103,8 @@ class TwigExtractorTest extends TestCase
*/
public function testExtractSyntaxError($resources, array $messages)
{
$twig = new Environment($this->getMockBuilder(\Twig\Loader\LoaderInterface::class)->getMock());
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
$twig = new Environment($this->createMock(LoaderInterface::class));
$twig->addExtension(new TranslationExtension($this->createMock(TranslatorInterface::class)));
$extractor = new TwigExtractor($twig);
$catalogue = new MessageCatalogue('en');
@ -132,7 +133,7 @@ class TwigExtractorTest extends TestCase
'cache' => false,
'autoescape' => false,
]);
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
$twig->addExtension(new TranslationExtension($this->createMock(TranslatorInterface::class)));
$extractor = new TwigExtractor($twig);
$catalogue = new MessageCatalogue('en');

View File

@ -13,9 +13,12 @@ namespace Symfony\Bridge\Twig\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\TwigEngine;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReference;
use Twig\Environment;
use Twig\Error\SyntaxError;
use Twig\Loader\ArrayLoader;
use Twig\Template;
/**
* @group legacy
@ -26,7 +29,7 @@ class TwigEngineTest extends TestCase
{
$engine = $this->getTwig();
$this->assertTrue($engine->exists($this->getMockForAbstractClass(\Twig\Template::class, [], '', false)));
$this->assertTrue($engine->exists($this->getMockForAbstractClass(Template::class, [], '', false)));
}
public function testExistsWithNonExistentTemplates()
@ -63,7 +66,7 @@ class TwigEngineTest extends TestCase
public function testRenderWithError()
{
$this->expectException(\Twig\Error\SyntaxError::class);
$this->expectException(SyntaxError::class);
$engine = $this->getTwig();
$engine->render(new TemplateReference('error'));
@ -75,7 +78,7 @@ class TwigEngineTest extends TestCase
'index' => 'foo',
'error' => '{{ foo }',
]));
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$parser = $this->createMock(TemplateNameParserInterface::class);
return new TwigEngine($twig, $parser);
}

View File

@ -125,7 +125,7 @@ class AnnotationsCacheWarmerTest extends TestCase
*/
private function getReadOnlyReader()
{
$readerMock = $this->getMockBuilder(Reader::class)->getMock();
$readerMock = $this->createMock(Reader::class);
$readerMock->expects($this->exactly(0))->method('getClassAnnotations');
$readerMock->expects($this->exactly(0))->method('getClassAnnotation');
$readerMock->expects($this->exactly(0))->method('getMethodAnnotations');

View File

@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateFilenameParser;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BaseBundle\BaseBundle;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\HttpKernel\Kernel;
/**
* @group legacy
@ -23,12 +24,7 @@ class TemplateFinderTest extends TestCase
{
public function testFindAllTemplates()
{
$kernel = $this
->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class)
->disableOriginalConstructor()
->getMock()
;
$kernel = $this->createMock(Kernel::class);
$kernel
->expects($this->any())
->method('getBundle')

View File

@ -17,6 +17,7 @@ use Symfony\Bundle\FrameworkBundle\Command\CachePoolDeleteCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
use Symfony\Component\HttpKernel\KernelInterface;
@ -26,8 +27,7 @@ class CachePoolDeleteCommandTest extends TestCase
protected function setUp(): void
{
$this->cachePool = $this->getMockBuilder(CacheItemPoolInterface::class)
->getMock();
$this->cachePool = $this->createMock(CacheItemPoolInterface::class);
}
public function testCommandWithValidKey()
@ -88,14 +88,9 @@ class CachePoolDeleteCommandTest extends TestCase
*/
private function getKernel()
{
$container = $this
->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)
->getMock();
$kernel = $this
->getMockBuilder(KernelInterface::class)
->getMock();
$container = $this->createMock(ContainerInterface::class);
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getContainer')

View File

@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class CachePruneCommandTest extends TestCase
@ -54,14 +55,9 @@ class CachePruneCommandTest extends TestCase
*/
private function getKernel()
{
$container = $this
->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)
->getMock();
$kernel = $this
->getMockBuilder(KernelInterface::class)
->getMock();
$container = $this->createMock(ContainerInterface::class);
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getContainer')
@ -80,10 +76,7 @@ class CachePruneCommandTest extends TestCase
*/
private function getPruneableInterfaceMock()
{
$pruneable = $this
->getMockBuilder(PruneableInterface::class)
->getMock();
$pruneable = $this->createMock(PruneableInterface::class);
$pruneable
->expects($this->atLeastOnce())
->method('prune');

View File

@ -16,10 +16,12 @@ use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;
class RouterMatchCommandTest extends TestCase
{
@ -55,7 +57,7 @@ class RouterMatchCommandTest extends TestCase
$routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('foo'));
$requestContext = new RequestContext();
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
$router = $this->createMock(RouterInterface::class);
$router
->expects($this->any())
->method('getRouteCollection')
@ -70,7 +72,7 @@ class RouterMatchCommandTest extends TestCase
private function getKernel()
{
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
$container = $this->createMock(ContainerInterface::class);
$container
->expects($this->atLeastOnce())
->method('has')
@ -85,7 +87,7 @@ class RouterMatchCommandTest extends TestCase
->willReturn($this->getRouter())
;
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getContainer')

View File

@ -18,6 +18,11 @@ use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Translation\Extractor\ExtractorInterface;
use Symfony\Component\Translation\Reader\TranslationReader;
use Symfony\Component\Translation\Translator;
class TranslationDebugCommandTest extends TestCase
{
@ -101,7 +106,7 @@ class TranslationDebugCommandTest extends TestCase
{
$this->fs->mkdir($this->translationDir.'/customDir/translations');
$this->fs->mkdir($this->translationDir.'/customDir/templates');
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel->expects($this->once())
->method('getBundle')
->with($this->equalTo($this->translationDir.'/customDir'))
@ -117,7 +122,7 @@ class TranslationDebugCommandTest extends TestCase
public function testDebugInvalidDirectory()
{
$this->expectException(\InvalidArgumentException::class);
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel->expects($this->once())
->method('getBundle')
->with($this->equalTo('dir'))
@ -142,16 +147,13 @@ class TranslationDebugCommandTest extends TestCase
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
{
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
->disableOriginalConstructor()
->getMock();
$translator = $this->createMock(Translator::class);
$translator
->expects($this->any())
->method('getFallbackLocales')
->willReturn(['en']);
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
$extractor = $this->createMock(ExtractorInterface::class);
$extractor
->expects($this->any())
->method('extract')
@ -161,7 +163,7 @@ class TranslationDebugCommandTest extends TestCase
}
);
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
$loader = $this->createMock(TranslationReader::class);
$loader
->expects($this->any())
->method('read')
@ -182,7 +184,7 @@ class TranslationDebugCommandTest extends TestCase
['test', true, $this->getBundle('test')],
];
}
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getBundle')
@ -212,7 +214,7 @@ class TranslationDebugCommandTest extends TestCase
private function getBundle($path)
{
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
$bundle = $this->createMock(BundleInterface::class);
$bundle
->expects($this->any())
->method('getPath')

View File

@ -18,6 +18,12 @@ use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Translation\Extractor\ExtractorInterface;
use Symfony\Component\Translation\Reader\TranslationReader;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Writer\TranslationWriter;
class TranslationUpdateCommandTest extends TestCase
{
@ -152,18 +158,15 @@ class TranslationUpdateCommandTest extends TestCase
/**
* @return CommandTester
*/
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
{
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
->disableOriginalConstructor()
->getMock();
$translator = $this->createMock(Translator::class);
$translator
->expects($this->any())
->method('getFallbackLocales')
->willReturn(['en']);
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
$extractor = $this->createMock(ExtractorInterface::class);
$extractor
->expects($this->any())
->method('extract')
@ -175,7 +178,7 @@ class TranslationUpdateCommandTest extends TestCase
}
);
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
$loader = $this->createMock(TranslationReader::class);
$loader
->expects($this->any())
->method('read')
@ -185,7 +188,7 @@ class TranslationUpdateCommandTest extends TestCase
}
);
$writer = $this->getMockBuilder(\Symfony\Component\Translation\Writer\TranslationWriter::class)->getMock();
$writer = $this->createMock(TranslationWriter::class);
$writer
->expects($this->any())
->method('getFormats')
@ -204,7 +207,7 @@ class TranslationUpdateCommandTest extends TestCase
['test', true, $this->getBundle('test')],
];
}
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getBundle')
@ -233,7 +236,7 @@ class TranslationUpdateCommandTest extends TestCase
private function getBundle($path)
{
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
$bundle = $this->createMock(BundleInterface::class);
$bundle
->expects($this->any())
->method('getPath')

View File

@ -73,20 +73,14 @@ EOF;
private function getKernelAwareApplicationMock()
{
$kernel = $this->getMockBuilder(KernelInterface::class)
->disableOriginalConstructor()
->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->once())
->method('locateResource')
->with('@AppBundle/Resources')
->willReturn(sys_get_temp_dir().'/xliff-lint-test');
$application = $this->getMockBuilder(Application::class)
->disableOriginalConstructor()
->getMock();
$application = $this->createMock(Application::class);
$application
->expects($this->once())
->method('getKernel')

View File

@ -120,20 +120,14 @@ EOF;
private function getKernelAwareApplicationMock()
{
$kernel = $this->getMockBuilder(KernelInterface::class)
->disableOriginalConstructor()
->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->once())
->method('locateResource')
->with('@AppBundle/Resources')
->willReturn(sys_get_temp_dir().'/yml-lint-test');
$application = $this->getMockBuilder(Application::class)
->disableOriginalConstructor()
->getMock();
$application = $this->createMock(Application::class);
$application
->expects($this->once())
->method('getKernel')

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Console;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@ -23,14 +24,18 @@ use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class ApplicationTest extends TestCase
{
public function testBundleInterfaceImplementation()
{
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
$bundle = $this->createMock(BundleInterface::class);
$kernel = $this->getKernel([$bundle], true);
@ -110,7 +115,7 @@ class ApplicationTest extends TestCase
*/
public function testBundleCommandsHaveRightContainer()
{
$command = $this->getMockForAbstractClass(\Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand::class, ['foo'], '', true, true, true, ['setContainer']);
$command = $this->getMockForAbstractClass(ContainerAwareCommand::class, ['foo'], '', true, true, true, ['setContainer']);
$command->setCode(function () {});
$command->expects($this->exactly(2))->method('setContainer');
@ -149,7 +154,7 @@ class ApplicationTest extends TestCase
$container->register(ThrowingCommand::class, ThrowingCommand::class);
$container->setParameter('console.command.ids', [ThrowingCommand::class => ThrowingCommand::class]);
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->method('getBundles')
->willReturn([$this->createBundleMock(
@ -177,7 +182,7 @@ class ApplicationTest extends TestCase
$container = new ContainerBuilder();
$container->register('event_dispatcher', EventDispatcher::class);
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->method('getBundles')
->willReturn([$this->createBundleMock(
@ -206,7 +211,7 @@ class ApplicationTest extends TestCase
$container->register(ThrowingCommand::class, ThrowingCommand::class);
$container->setParameter('console.command.ids', [ThrowingCommand::class => ThrowingCommand::class]);
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel->expects($this->once())->method('boot');
$kernel
->method('getBundles')
@ -259,10 +264,10 @@ class ApplicationTest extends TestCase
private function getKernel(array $bundles, $useDispatcher = false)
{
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
$container = $this->createMock(ContainerInterface::class);
if ($useDispatcher) {
$dispatcher = $this->getMockBuilder(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class)->getMock();
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher
->expects($this->atLeastOnce())
->method('dispatch')
@ -287,7 +292,7 @@ class ApplicationTest extends TestCase
->willReturnOnConsecutiveCalls([], [])
;
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel->expects($this->once())->method('boot');
$kernel
->expects($this->any())
@ -305,7 +310,7 @@ class ApplicationTest extends TestCase
private function createBundleMock(array $commands)
{
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock();
$bundle = $this->createMock(Bundle::class);
$bundle
->expects($this->once())
->method('registerCommands')

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
@ -68,7 +69,7 @@ class AbstractControllerTest extends ControllerTraitTest
public function testMissingParameterBag()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException::class);
$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage('TestAbstractController::getParameter()" method is missing a parameter bag');
$container = new Container();

View File

@ -14,7 +14,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Composer\Autoload\ClassLoader;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* @group legacy
@ -151,7 +153,7 @@ class ControllerNameParserTest extends TestCase
'FooBundle' => $this->getBundle('TestBundle\FooBundle', 'FooBundle'),
];
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getBundle')
@ -180,7 +182,7 @@ class ControllerNameParserTest extends TestCase
private function getBundle($namespace, $name)
{
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
$bundle = $this->createMock(BundleInterface::class);
$bundle->expects($this->any())->method('getName')->willReturn($name);
$bundle->expects($this->any())->method('getNamespace')->willReturn($namespace);

View File

@ -32,7 +32,7 @@ class ControllerResolverTest extends ContainerControllerResolverTest
$controller = $resolver->getController($request);
$this->assertInstanceOf(\Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::class, $controller[0]);
$this->assertInstanceOf(ContainerAwareController::class, $controller[0]);
$this->assertInstanceOf(ContainerInterface::class, $controller[0]->getContainer());
$this->assertSame('testAction', $controller[1]);
}
@ -45,7 +45,7 @@ class ControllerResolverTest extends ContainerControllerResolverTest
$controller = $resolver->getController($request);
$this->assertInstanceOf(\Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::class, $controller);
$this->assertInstanceOf(ContainerAwareController::class, $controller);
$this->assertInstanceOf(ContainerInterface::class, $controller->getContainer());
}
@ -69,7 +69,7 @@ class ControllerResolverTest extends ContainerControllerResolverTest
$controller = $resolver->getController($request);
$this->assertInstanceOf(\Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController::class, $controller[0]);
$this->assertInstanceOf(ContainerAwareController::class, $controller[0]);
$this->assertInstanceOf(ContainerInterface::class, $controller[0]->getContainer());
$this->assertSame('testAction', $controller[1]);
}
@ -200,12 +200,12 @@ class ControllerResolverTest extends ContainerControllerResolverTest
protected function createMockParser()
{
return $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
return $this->createMock(ControllerNameParser::class);
}
protected function createMockContainer()
{
return $this->getMockBuilder(ContainerInterface::class)->getMock();
return $this->createMock(ContainerInterface::class);
}
}

View File

@ -12,23 +12,38 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\WebLink\Link;
use Twig\Environment;
abstract class ControllerTraitTest extends TestCase
{
@ -43,7 +58,7 @@ abstract class ControllerTraitTest extends TestCase
$requestStack = new RequestStack();
$requestStack->push($request);
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
return new Response($request->getRequestFormat().'--'.$request->getLocale());
});
@ -100,7 +115,7 @@ abstract class ControllerTraitTest extends TestCase
private function getContainerWithTokenStorage($token = null): Container
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage::class)->getMock();
$tokenStorage = $this->createMock(TokenStorage::class);
$tokenStorage
->expects($this->once())
->method('getToken')
@ -126,7 +141,7 @@ abstract class ControllerTraitTest extends TestCase
{
$container = new Container();
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->expects($this->once())
->method('serialize')
@ -147,7 +162,7 @@ abstract class ControllerTraitTest extends TestCase
{
$container = new Container();
$serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
$serializer = $this->createMock(SerializerInterface::class);
$serializer
->expects($this->once())
->method('serialize')
@ -169,7 +184,7 @@ abstract class ControllerTraitTest extends TestCase
public function testFile()
{
$container = new Container();
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$container->set('http_kernel', $kernel);
$controller = $this->createController();
@ -270,7 +285,7 @@ abstract class ControllerTraitTest extends TestCase
public function testFileWhichDoesNotExist()
{
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
$this->expectException(FileNotFoundException::class);
$controller = $this->createController();
$controller->file('some-file.txt', 'test.php');
@ -278,7 +293,7 @@ abstract class ControllerTraitTest extends TestCase
public function testIsGranted()
{
$authorizationChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::class)->getMock();
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(true);
$container = new Container();
@ -292,8 +307,8 @@ abstract class ControllerTraitTest extends TestCase
public function testdenyAccessUnlessGranted()
{
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
$authorizationChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::class)->getMock();
$this->expectException(AccessDeniedException::class);
$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(false);
$container = new Container();
@ -307,7 +322,7 @@ abstract class ControllerTraitTest extends TestCase
public function testRenderViewTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = new Container();
@ -321,7 +336,7 @@ abstract class ControllerTraitTest extends TestCase
public function testRenderTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$twig->expects($this->once())->method('render')->willReturn('bar');
$container = new Container();
@ -335,7 +350,7 @@ abstract class ControllerTraitTest extends TestCase
public function testStreamTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$container = new Container();
$container->set('twig', $twig);
@ -343,12 +358,12 @@ abstract class ControllerTraitTest extends TestCase
$controller = $this->createController();
$controller->setContainer($container);
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\StreamedResponse::class, $controller->stream('foo'));
$this->assertInstanceOf(StreamedResponse::class, $controller->stream('foo'));
}
public function testRedirectToRoute()
{
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
$router = $this->createMock(RouterInterface::class);
$router->expects($this->once())->method('generate')->willReturn('/foo');
$container = new Container();
@ -358,7 +373,7 @@ abstract class ControllerTraitTest extends TestCase
$controller->setContainer($container);
$response = $controller->redirectToRoute('foo');
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertSame('/foo', $response->getTargetUrl());
$this->assertSame(302, $response->getStatusCode());
}
@ -369,7 +384,7 @@ abstract class ControllerTraitTest extends TestCase
public function testAddFlash()
{
$flashBag = new FlashBag();
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class)->getMock();
$session = $this->createMock(Session::class);
$session->expects($this->once())->method('getFlashBag')->willReturn($flashBag);
$container = new Container();
@ -386,12 +401,12 @@ abstract class ControllerTraitTest extends TestCase
{
$controller = $this->createController();
$this->assertInstanceOf(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class, $controller->createAccessDeniedException());
$this->assertInstanceOf(AccessDeniedException::class, $controller->createAccessDeniedException());
}
public function testIsCsrfTokenValid()
{
$tokenManager = $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock();
$tokenManager = $this->createMock(CsrfTokenManagerInterface::class);
$tokenManager->expects($this->once())->method('isTokenValid')->willReturn(true);
$container = new Container();
@ -405,7 +420,7 @@ abstract class ControllerTraitTest extends TestCase
public function testGenerateUrl()
{
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
$router = $this->createMock(RouterInterface::class);
$router->expects($this->once())->method('generate')->willReturn('/foo');
$container = new Container();
@ -422,7 +437,7 @@ abstract class ControllerTraitTest extends TestCase
$controller = $this->createController();
$response = $controller->redirect('https://dunglas.fr', 301);
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertSame('https://dunglas.fr', $response->getTargetUrl());
$this->assertSame(301, $response->getStatusCode());
}
@ -432,7 +447,7 @@ abstract class ControllerTraitTest extends TestCase
*/
public function testRenderViewTemplating()
{
$templating = $this->getMockBuilder(\Symfony\Bundle\FrameworkBundle\Templating\EngineInterface::class)->getMock();
$templating = $this->createMock(EngineInterface::class);
$templating->expects($this->once())->method('render')->willReturn('bar');
$container = new Container();
@ -449,7 +464,7 @@ abstract class ControllerTraitTest extends TestCase
*/
public function testRenderTemplating()
{
$templating = $this->getMockBuilder(\Symfony\Bundle\FrameworkBundle\Templating\EngineInterface::class)->getMock();
$templating = $this->createMock(EngineInterface::class);
$templating->expects($this->once())->method('render')->willReturn('bar');
$container = new Container();
@ -466,7 +481,7 @@ abstract class ControllerTraitTest extends TestCase
*/
public function testStreamTemplating()
{
$templating = $this->getMockBuilder(\Symfony\Bundle\FrameworkBundle\Templating\EngineInterface::class)->getMock();
$templating = $this->createMock(EngineInterface::class);
$container = new Container();
$container->set('templating', $templating);
@ -474,21 +489,21 @@ abstract class ControllerTraitTest extends TestCase
$controller = $this->createController();
$controller->setContainer($container);
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\StreamedResponse::class, $controller->stream('foo'));
$this->assertInstanceOf(StreamedResponse::class, $controller->stream('foo'));
}
public function testCreateNotFoundException()
{
$controller = $this->createController();
$this->assertInstanceOf(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class, $controller->createNotFoundException());
$this->assertInstanceOf(NotFoundHttpException::class, $controller->createNotFoundException());
}
public function testCreateForm()
{
$form = new Form($this->getMockBuilder(FormConfigInterface::class)->getMock());
$form = new Form($this->createMock(FormConfigInterface::class));
$formFactory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
$formFactory = $this->createMock(FormFactoryInterface::class);
$formFactory->expects($this->once())->method('create')->willReturn($form);
$container = new Container();
@ -502,9 +517,9 @@ abstract class ControllerTraitTest extends TestCase
public function testCreateFormBuilder()
{
$formBuilder = $this->getMockBuilder(\Symfony\Component\Form\FormBuilderInterface::class)->getMock();
$formBuilder = $this->createMock(FormBuilderInterface::class);
$formFactory = $this->getMockBuilder(\Symfony\Component\Form\FormFactoryInterface::class)->getMock();
$formFactory = $this->createMock(FormFactoryInterface::class);
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
$container = new Container();

View File

@ -85,7 +85,7 @@ class RedirectControllerTest extends TestCase
$request->attributes = new ParameterBag($attributes);
$router = $this->getMockBuilder(UrlGeneratorInterface::class)->getMock();
$router = $this->createMock(UrlGeneratorInterface::class);
$router
->expects($this->exactly(2))
->method('generate')
@ -304,7 +304,7 @@ class RedirectControllerTest extends TestCase
$request = $this->createRequestObject($scheme, $host, $port, $baseUrl, 'b.se=zaza&f[%2525][%26][%3D][p.c]=d');
$request->attributes = new ParameterBag(['_route_params' => ['base2' => 'zaza']]);
$urlGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$urlGenerator->expects($this->exactly(2))
->method('generate')
->willReturn('/test?b.se=zaza&base2=zaza&f[%2525][%26][%3D][p.c]=d')
@ -326,7 +326,7 @@ class RedirectControllerTest extends TestCase
$request = $this->createRequestObject($scheme, $host, $port, $baseUrl, 'b.se=zaza');
$request->attributes = new ParameterBag(['_route_params' => ['b.se' => 'zouzou']]);
$urlGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$urlGenerator->expects($this->exactly(2))->method('generate')->willReturn('/test?b.se=zouzou')->with('/test', ['b.se' => 'zouzou'], UrlGeneratorInterface::ABSOLUTE_URL);
$controller = new RedirectController($urlGenerator);

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Twig\Environment;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
@ -22,7 +23,7 @@ class TemplateControllerTest extends TestCase
{
public function testTwig()
{
$twig = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$twig = $this->createMock(Environment::class);
$twig->expects($this->exactly(2))->method('render')->willReturn('bar');
$controller = new TemplateController($twig);
@ -36,7 +37,7 @@ class TemplateControllerTest extends TestCase
*/
public function testTemplating()
{
$templating = $this->getMockBuilder(EngineInterface::class)->getMock();
$templating = $this->createMock(EngineInterface::class);
$templating->expects($this->exactly(2))->method('render')->willReturn('bar');
$controller = new TemplateController(null, $templating);

View File

@ -17,6 +17,7 @@ use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
/**
@ -61,7 +62,7 @@ class CachePoolPrunerPassTest extends TestCase
public function testCompilerPassThrowsOnInvalidDefinitionClass()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Class "Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\NotFound" used for service "pool.not-found" cannot be found.');
$container = new ContainerBuilder();
$container->register('console.command.cache_pool_prune')->addArgument([]);

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
@ -54,7 +55,7 @@ class WorkflowGuardListenerPassTest extends TestCase
public function testExceptionIfTheTokenStorageServiceIsNotPresent()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\LogicException::class);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('The "security.token_storage" service is needed to be able to use the workflow guard listener.');
$this->container->setParameter('workflow.has_guard_listeners', true);
$this->container->register('security.authorization_checker', AuthorizationCheckerInterface::class);
@ -66,7 +67,7 @@ class WorkflowGuardListenerPassTest extends TestCase
public function testExceptionIfTheAuthorizationCheckerServiceIsNotPresent()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\LogicException::class);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('The "security.authorization_checker" service is needed to be able to use the workflow guard listener.');
$this->container->setParameter('workflow.has_guard_listeners', true);
$this->container->register('security.token_storage', TokenStorageInterface::class);
@ -78,7 +79,7 @@ class WorkflowGuardListenerPassTest extends TestCase
public function testExceptionIfTheAuthenticationTrustResolverServiceIsNotPresent()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\LogicException::class);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('The "security.authentication.trust_resolver" service is needed to be able to use the workflow guard listener.');
$this->container->setParameter('workflow.has_guard_listeners', true);
$this->container->register('security.token_storage', TokenStorageInterface::class);
@ -90,7 +91,7 @@ class WorkflowGuardListenerPassTest extends TestCase
public function testExceptionIfTheRoleHierarchyServiceIsNotPresent()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\LogicException::class);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('The "security.role_hierarchy" service is needed to be able to use the workflow guard listener.');
$this->container->setParameter('workflow.has_guard_listeners', true);
$this->container->register('security.token_storage', TokenStorageInterface::class);

View File

@ -27,6 +27,7 @@ use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\ProxyAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
@ -37,10 +38,12 @@ use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpClient\ScopingHttpClient;
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
use Symfony\Component\Messenger\Transport\TransportFactory;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
@ -54,7 +57,10 @@ use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow;
use Symfony\Component\Workflow\Exception\InvalidDefinitionException;
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -331,28 +337,28 @@ abstract class FrameworkExtensionTest extends TestCase
public function testWorkflowAreValidated()
{
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
$this->expectException(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 testWorkflowCannotHaveBothTypeAndService()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('"type" and "service" cannot be used together.');
$this->createContainerFromFile('workflow_legacy_with_type_and_service');
}
public function testWorkflowCannotHaveBothSupportsAndSupportStrategy()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(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::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('"supports" or "support_strategy" should be configured.');
$this->createContainerFromFile('workflow_without_support_and_support_strategy');
}
@ -362,7 +368,7 @@ abstract class FrameworkExtensionTest extends TestCase
*/
public function testWorkflowCannotHaveBothArgumentsAndService()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('"arguments" and "service" cannot be used together.');
$this->createContainerFromFile('workflow_legacy_with_arguments_and_service');
}
@ -524,7 +530,7 @@ abstract class FrameworkExtensionTest extends TestCase
public function testRouterRequiresResourceOption()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$container = $this->createContainer();
$loader = new FrameworkExtension();
$loader->load([['router' => true]], $container);
@ -838,19 +844,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::class);
$ref = new \ReflectionClass(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::class);
$ref = new \ReflectionClass(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::class);
$ref = new \ReflectionClass(Security::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations/security.en.xlf', '/', \DIRECTORY_SEPARATOR),
$files,
@ -921,7 +927,7 @@ abstract class FrameworkExtensionTest extends TestCase
*/
public function testTemplatingRequiresAtLeastOneEngine()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$container = $this->createContainer();
$loader = new FrameworkExtension();
$loader->load([['templating' => null]], $container);
@ -932,7 +938,7 @@ abstract class FrameworkExtensionTest extends TestCase
$container = $this->createContainerFromFile('full');
$projectDir = $container->getParameter('kernel.project_dir');
$ref = new \ReflectionClass(\Symfony\Component\Form\Form::class);
$ref = new \ReflectionClass(Form::class);
$xmlMappings = [
\dirname($ref->getFileName()).'/Resources/config/validation.xml',
strtr($projectDir.'/config/validator/foo.xml', '/', \DIRECTORY_SEPARATOR),
@ -969,7 +975,7 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('validation_annotations', ['kernel.charset' => 'UTF-8'], false);
$this->assertInstanceOf(\Symfony\Component\Validator\Validator\ValidatorInterface::class, $container->get('validator'));
$this->assertInstanceOf(ValidatorInterface::class, $container->get('validator'));
}
public function testAnnotations()
@ -1097,7 +1103,7 @@ abstract class FrameworkExtensionTest extends TestCase
*/
public function testCannotConfigureStrictEmailAndEmailValidationModeAtTheSameTime()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('"strict_email" and "email_validation_mode" cannot be used together.');
$this->createContainerFromFile('validation_strict_email_and_validation_mode');
}

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\Workflow\Exception\InvalidDefinitionException;
class PhpFrameworkExtensionTest extends FrameworkExtensionTest
{
@ -55,7 +56,7 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest
public function testWorkflowValidationStateMachine()
{
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('A transition from a place/state must have an unique name. Multiple transitions named "a_to_b" from place/state "a" were found on StateMachine "article".');
$this->createContainerFromClosure(function ($container) {
$container->loadFromExtension('framework', [
@ -157,7 +158,7 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest
*/
public function testWorkflowValidationSingleState()
{
$this->expectException(\Symfony\Component\Workflow\Exception\InvalidDefinitionException::class);
$this->expectException(InvalidDefinitionException::class);
$this->expectExceptionMessage('The marking store of workflow "article" can not store many places. But the transition "a_to_b" has too many output (2). Only one is accepted.');
$this->createContainerFromClosure(function ($container) {
$container->loadFromExtension('framework', [

View File

@ -26,12 +26,12 @@ class ResolveControllerNameSubscriberTest extends TestCase
{
public function testReplacesControllerAttribute()
{
$parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
$parser = $this->createMock(ControllerNameParser::class);
$parser->expects($this->any())
->method('parse')
->with('AppBundle:Starting:format')
->willReturn('App\\Final\\Format::methodName');
$httpKernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$httpKernel = $this->createMock(HttpKernelInterface::class);
$request = new Request();
$request->attributes->set('_controller', 'AppBundle:Starting:format');
@ -50,10 +50,10 @@ class ResolveControllerNameSubscriberTest extends TestCase
*/
public function testSkipsOtherControllerFormats($controller)
{
$parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
$parser = $this->createMock(ControllerNameParser::class);
$parser->expects($this->never())
->method('parse');
$httpKernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$httpKernel = $this->createMock(HttpKernelInterface::class);
$request = new Request();
$request->attributes->set('_controller', $controller);

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* @group functional
@ -67,7 +68,7 @@ class CachePoolClearCommandTest extends AbstractWebTestCase
public function testClearUnexistingPool()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException::class);
$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage('You have requested a non-existent service "unknown_pool"');
$this->createCommandTester()
->execute(['pools' => ['unknown_pool']], ['decorated' => false]);

View File

@ -10,6 +10,7 @@ use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCompiler;
class DelegatingLoaderTest extends TestCase
{
@ -19,20 +20,16 @@ class DelegatingLoaderTest extends TestCase
*/
public function testConstructorApi()
{
$controllerNameParser = $this->getMockBuilder(ControllerNameParser::class)
->disableOriginalConstructor()
->getMock();
$controllerNameParser = $this->createMock(ControllerNameParser::class);
new DelegatingLoader($controllerNameParser, new LoaderResolver());
$this->assertTrue(true, '__construct() takes a ControllerNameParser and LoaderResolverInterface respectively as its first and second argument.');
}
public function testLoadDefaultOptions()
{
$loaderResolver = $this->getMockBuilder(LoaderResolverInterface::class)
->disableOriginalConstructor()
->getMock();
$loaderResolver = $this->createMock(LoaderResolverInterface::class);
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loaderResolver->expects($this->once())
->method('resolve')
@ -52,13 +49,13 @@ class DelegatingLoaderTest extends TestCase
$this->assertCount(2, $loadedRouteCollection);
$expected = [
'compiler_class' => 'Symfony\Component\Routing\RouteCompiler',
'compiler_class' => RouteCompiler::class,
'utf8' => false,
];
$this->assertSame($expected, $routeCollection->get('foo')->getOptions());
$expected = [
'compiler_class' => 'Symfony\Component\Routing\RouteCompiler',
'compiler_class' => RouteCompiler::class,
'foo' => 123,
'utf8' => true,
];
@ -71,20 +68,15 @@ class DelegatingLoaderTest extends TestCase
*/
public function testLoad()
{
$controllerNameParser = $this->getMockBuilder(ControllerNameParser::class)
->disableOriginalConstructor()
->getMock();
$controllerNameParser = $this->createMock(ControllerNameParser::class);
$controllerNameParser->expects($this->once())
->method('parse')
->with('foo:bar:baz')
->willReturn('some_parsed::controller');
$loaderResolver = $this->getMockBuilder(LoaderResolverInterface::class)
->disableOriginalConstructor()
->getMock();
$loaderResolver = $this->createMock(LoaderResolverInterface::class);
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loaderResolver->expects($this->once())
->method('resolve')

View File

@ -17,6 +17,7 @@ use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@ -375,7 +376,7 @@ class RouterTest extends TestCase
public function testExceptionOnNonExistentParameterWithSfContainer()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException::class);
$this->expectException(ParameterNotFoundException::class);
$this->expectExceptionMessage('You have requested a non-existent parameter "nope".');
$routes = new RouteCollection();
@ -504,7 +505,7 @@ class RouterTest extends TestCase
private function getServiceContainer(RouteCollection $routes): Container
{
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader
->expects($this->any())
@ -525,7 +526,7 @@ class RouterTest extends TestCase
private function getPsr11ServiceContainer(RouteCollection $routes): ContainerInterface
{
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader
->expects($this->any())
@ -533,7 +534,7 @@ class RouterTest extends TestCase
->willReturn($routes)
;
$sc = $this->getMockBuilder(ContainerInterface::class)->getMock();
$sc = $this->createMock(ContainerInterface::class);
$sc
->expects($this->once())
@ -546,7 +547,7 @@ class RouterTest extends TestCase
private function getParameterBag(array $params = []): ContainerInterface
{
$bag = $this->getMockBuilder(ContainerInterface::class)->getMock();
$bag = $this->createMock(ContainerInterface::class);
$bag
->expects($this->any())
->method('get')

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\EngineInterface;
/**
* @group legacy
@ -88,7 +89,7 @@ class DelegatingEngineTest extends TestCase
private function getEngineMock($template, $supports)
{
$engine = $this->getMockBuilder(\Symfony\Component\Templating\EngineInterface::class)->getMock();
$engine = $this->createMock(EngineInterface::class);
$engine->expects($this->once())
->method('supports')
@ -100,7 +101,7 @@ class DelegatingEngineTest extends TestCase
private function getFrameworkEngineMock($template, $supports)
{
$engine = $this->getMockBuilder(\Symfony\Bundle\FrameworkBundle\Templating\EngineInterface::class)->getMock();
$engine = $this->createMock(\Symfony\Bundle\FrameworkBundle\Templating\EngineInterface::class);
$engine->expects($this->once())
->method('supports')

View File

@ -14,6 +14,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @group legacy
@ -36,14 +39,14 @@ class GlobalVariablesTest extends TestCase
public function testGetTokenNoToken()
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->container->set('security.token_storage', $tokenStorage);
$this->assertNull($this->globals->getToken());
}
public function testGetToken()
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->container->set('security.token_storage', $tokenStorage);
@ -62,7 +65,7 @@ class GlobalVariablesTest extends TestCase
public function testGetUserNoToken()
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->container->set('security.token_storage', $tokenStorage);
$this->assertNull($this->globals->getUser());
}
@ -72,8 +75,8 @@ class GlobalVariablesTest extends TestCase
*/
public function testGetUser($user, $expectedUser)
{
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
$tokenStorage = $this->createMock(TokenStorageInterface::class);
$token = $this->createMock(TokenInterface::class);
$this->container->set('security.token_storage', $tokenStorage);
@ -92,9 +95,9 @@ class GlobalVariablesTest extends TestCase
public function getUserProvider()
{
$user = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
$user = $this->createMock(UserInterface::class);
$std = new \stdClass();
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
$token = $this->createMock(TokenInterface::class);
return [
[$user, $user],

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
@ -36,7 +37,7 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
{
// should be moved to the Form component once absolute file paths are supported
// by the default name parser in the Templating component
$reflClass = new \ReflectionClass(\Symfony\Bundle\FrameworkBundle\FrameworkBundle::class);
$reflClass = new \ReflectionClass(FrameworkBundle::class);
$root = realpath(\dirname($reflClass->getFileName()).'/Resources/views');
$rootTheme = realpath(__DIR__.'/Resources');
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
@ -80,7 +81,7 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
{
// should be moved to the Form component once absolute file paths are supported
// by the default name parser in the Templating component
$reflClass = new \ReflectionClass(\Symfony\Bundle\FrameworkBundle\FrameworkBundle::class);
$reflClass = new \ReflectionClass(FrameworkBundle::class);
$root = realpath(\dirname($reflClass->getFileName()).'/Resources/views');
$rootTheme = realpath(__DIR__.'/Resources');
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\StopwatchHelper;
use Symfony\Component\Stopwatch\Stopwatch;
/**
* @group legacy
@ -21,7 +22,7 @@ class StopwatchHelperTest extends TestCase
{
public function testDevEnvironment()
{
$stopwatch = $this->getMockBuilder(\Symfony\Component\Stopwatch\Stopwatch::class)->getMock();
$stopwatch = $this->createMock(Stopwatch::class);
$stopwatch->expects($this->once())
->method('start')
->with('foo');

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Loader;
use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Config\FileLocator;
/**
* @group legacy
@ -90,7 +91,7 @@ class TemplateLocatorTest extends TestCase
protected function getFileLocator()
{
return $this
->getMockBuilder(\Symfony\Component\Config\FileLocator::class)
->getMockBuilder(FileLocator::class)
->setMethods(['locate'])
->setConstructorArgs(['/path/to/fallback'])
->getMock()

View File

@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Templating\Loader\Loader;
use Symfony\Component\Templating\TemplateNameParser;
/**
@ -29,7 +30,7 @@ class PhpEngineTest extends TestCase
public function testEvaluateAddsAppGlobal()
{
$container = $this->getContainer();
$loader = $this->getMockForAbstractClass(\Symfony\Component\Templating\Loader\Loader::class);
$loader = $this->getMockForAbstractClass(Loader::class);
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader, $app = new GlobalVariables($container));
$globals = $engine->getGlobals();
$this->assertSame($app, $globals['app']);
@ -38,7 +39,7 @@ class PhpEngineTest extends TestCase
public function testEvaluateWithoutAvailableRequest()
{
$container = new Container();
$loader = $this->getMockForAbstractClass(\Symfony\Component\Templating\Loader\Loader::class);
$loader = $this->getMockForAbstractClass(Loader::class);
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader, new GlobalVariables($container));
$this->assertFalse($container->has('request_stack'));
@ -50,7 +51,7 @@ class PhpEngineTest extends TestCase
{
$this->expectException(\InvalidArgumentException::class);
$container = $this->getContainer();
$loader = $this->getMockForAbstractClass(\Symfony\Component\Templating\Loader\Loader::class);
$loader = $this->getMockForAbstractClass(Loader::class);
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader);
$engine->get('non-existing-helper');

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
/**
@ -25,7 +26,7 @@ class TemplateNameParserTest extends TestCase
protected function setUp(): void
{
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getBundle')

View File

@ -20,6 +20,7 @@ use Symfony\Component\Stopwatch\StopwatchEvent;
use Symfony\Component\Templating\Loader\Loader;
use Symfony\Component\Templating\Storage\StringStorage;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
/**
* @group legacy
@ -49,13 +50,13 @@ class TimedPhpEngineTest extends TestCase
private function getContainer(): Container
{
return $this->getMockBuilder(Container::class)->getMock();
return $this->createMock(Container::class);
}
private function getTemplateNameParser(): TemplateNameParserInterface
{
$templateReference = $this->getMockBuilder(\Symfony\Component\Templating\TemplateReferenceInterface::class)->getMock();
$templateNameParser = $this->getMockBuilder(TemplateNameParserInterface::class)->getMock();
$templateReference = $this->createMock(TemplateReferenceInterface::class);
$templateNameParser = $this->createMock(TemplateNameParserInterface::class);
$templateNameParser->expects($this->any())
->method('parse')
->willReturn($templateReference);
@ -65,9 +66,7 @@ class TimedPhpEngineTest extends TestCase
private function getGlobalVariables(): GlobalVariables
{
return $this->getMockBuilder(GlobalVariables::class)
->disableOriginalConstructor()
->getMock();
return $this->createMock(GlobalVariables::class);
}
private function getStorage(): StringStorage
@ -92,13 +91,11 @@ class TimedPhpEngineTest extends TestCase
private function getStopwatchEvent(): StopwatchEvent
{
return $this->getMockBuilder(StopwatchEvent::class)
->disableOriginalConstructor()
->getMock();
return $this->createMock(StopwatchEvent::class);
}
private function getStopwatch(): Stopwatch
{
return $this->getMockBuilder(Stopwatch::class)->getMock();
return $this->createMock(Stopwatch::class);
}
}

View File

@ -12,12 +12,14 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Config\Resource\FileExistenceResource;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Translation\Exception\InvalidArgumentException;
use Symfony\Component\Translation\Formatter\MessageFormatter;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Translation\MessageCatalogue;
@ -94,7 +96,7 @@ class TranslatorTest extends TestCase
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
// do it another time as the cache is primed now
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader->expects($this->never())->method('load');
$translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir]);
@ -124,7 +126,7 @@ class TranslatorTest extends TestCase
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
// do it another time as the cache is primed now
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader->expects($this->never())->method('load');
$translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir]);
@ -139,7 +141,7 @@ class TranslatorTest extends TestCase
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid "invalid locale" locale.');
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$translator = $this->getTranslator($loader, ['cache_dir' => $this->tmpDir], 'loader', TranslatorWithInvalidLocale::class);
$translator->trans('foo');
@ -162,7 +164,7 @@ class TranslatorTest extends TestCase
public function testGetDefaultLocale()
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMock();
$container = $this->createMock(\Psr\Container\ContainerInterface::class);
$translator = new Translator($container, new MessageFormatter(), 'en');
$this->assertSame('en', $translator->getLocale());
@ -170,9 +172,9 @@ class TranslatorTest extends TestCase
public function testInvalidOptions()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The Translator does not support the following options: \'foo\'');
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
$container = $this->createMock(ContainerInterface::class);
(new Translator($container, new MessageFormatter(), 'en', [], ['foo' => 'bar']));
}
@ -182,7 +184,7 @@ class TranslatorTest extends TestCase
{
$someCatalogue = $this->getCatalogue('some_locale', []);
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader->expects($this->exactly(2))
->method('load')
@ -300,7 +302,7 @@ class TranslatorTest extends TestCase
protected function getLoader()
{
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader
->expects($this->exactly(7))
->method('load')
@ -336,7 +338,7 @@ class TranslatorTest extends TestCase
protected function getContainer($loader)
{
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
$container = $this->createMock(ContainerInterface::class);
$container
->expects($this->any())
->method('get')
@ -377,7 +379,7 @@ class TranslatorTest extends TestCase
$translator->setFallbackLocales(['fr']);
$translator->warmup($this->tmpDir);
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Loader\LoaderInterface::class)->getMock();
$loader = $this->createMock(LoaderInterface::class);
$loader
->expects($this->never())
->method('load');

View File

@ -220,7 +220,7 @@ class SecurityDataCollectorTest extends TestCase
public function testGetListeners()
{
$request = new Request();
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
$event->setResponse($response = new Response());
$listener = function ($e) use ($event, &$listenerCalled) {
$listenerCalled += $e === $event;

View File

@ -29,15 +29,12 @@ class TraceableFirewallListenerTest extends TestCase
public function testOnKernelRequestRecordsListeners()
{
$request = new Request();
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
$event->setResponse($response = new Response());
$listener = function ($e) use ($event, &$listenerCalled) {
$listenerCalled += $e === $event;
};
$firewallMap = $this
->getMockBuilder(FirewallMap::class)
->disableOriginalConstructor()
->getMock();
$firewallMap = $this->createMock(FirewallMap::class);
$firewallMap
->expects($this->once())
->method('getFirewallConfig')

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@ -610,7 +611,7 @@ abstract class CompleteConfigurationTest extends TestCase
public function testAccessDecisionManagerServiceAndStrategyCannotBeUsedAtTheSameTime()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "security.access_decision_manager": "strategy" and "service" cannot be used together.');
$this->getContainer('access_decision_manager_service_and_strategy');
}
@ -628,14 +629,14 @@ abstract class CompleteConfigurationTest extends TestCase
public function testFirewallUndefinedUserProvider()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid firewall "main": user provider "undefined" not found.');
$this->getContainer('firewall_undefined_provider');
}
public function testFirewallListenerUndefinedProvider()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid firewall "main": user provider "undefined" not found.');
$this->getContainer('listener_undefined_provider');
}

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\DependencyInjection\MainConfiguration;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
class MainConfigurationTest extends TestCase
@ -34,7 +35,7 @@ class MainConfigurationTest extends TestCase
public function testNoConfigForProvider()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$config = [
'providers' => [
'stub' => [],
@ -48,7 +49,7 @@ class MainConfigurationTest extends TestCase
public function testManyConfigForProvider()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$config = [
'providers' => [
'stub' => [

View File

@ -12,6 +12,7 @@
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Security\Factory;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@ -127,7 +128,7 @@ class AbstractFactoryTest extends TestCase
protected function callFactory($id, $config, $userProviderId, $defaultEntryPointId)
{
$factory = $this->getMockForAbstractClass(\Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory::class, []);
$factory = $this->getMockForAbstractClass(AbstractFactory::class);
$factory
->expects($this->once())

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Security\Facto
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\GuardAuthenticationFactory;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@ -41,7 +42,7 @@ class GuardAuthenticationFactoryTest extends TestCase
*/
public function testAddInvalidConfiguration(array $inputConfig)
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$factory = new GuardAuthenticationFactory();
$nodeDefinition = new ArrayNodeDefinition('guard');
$factory->addConfiguration($nodeDefinition);

View File

@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\DummyProvider;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@ -26,7 +27,7 @@ class SecurityExtensionTest extends TestCase
{
public function testInvalidCheckPath()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*".');
$container = $this->getRawContainer();
@ -50,7 +51,7 @@ class SecurityExtensionTest extends TestCase
public function testFirewallWithoutAuthenticationListener()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('No authentication listener registered for firewall "some_firewall"');
$container = $this->getRawContainer();
@ -71,7 +72,7 @@ class SecurityExtensionTest extends TestCase
public function testFirewallWithInvalidUserProvider()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Unable to create definition for "security.user.provider.concrete.my_foo" user provider');
$container = $this->getRawContainer();
@ -190,7 +191,7 @@ class SecurityExtensionTest extends TestCase
public function testMissingProviderForListener()
{
$this->expectException(\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException::class);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Not configuring explicitly the provider for the "http_basic" listener on "ambiguous" firewall is ambiguous as there is more than one registered provider.');
$container = $this->getRawContainer();
$container->loadFromExtension('security', [

View File

@ -301,7 +301,7 @@ EOTXT
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('There are no configured encoders for the "security" extension.');
$application = new ConsoleApplication();
$application->add(new UserPasswordEncoderCommand($this->getMockBuilder(EncoderFactoryInterface::class)->getMock(), []));
$application->add(new UserPasswordEncoderCommand($this->createMock(EncoderFactoryInterface::class), []));
$passwordEncoderCommand = $application->find('security:encode-password');

View File

@ -30,7 +30,7 @@ class FirewallMapTest extends TestCase
$request = new Request();
$map = [];
$container = $this->getMockBuilder(Container::class)->getMock();
$container = $this->createMock(Container::class);
$container->expects($this->never())->method('get');
$firewallMap = new FirewallMap($container, $map);
@ -46,7 +46,7 @@ class FirewallMapTest extends TestCase
$request->attributes->set(self::ATTRIBUTE_FIREWALL_CONTEXT, 'foo');
$map = [];
$container = $this->getMockBuilder(Container::class)->getMock();
$container = $this->createMock(Container::class);
$container->expects($this->never())->method('get');
$firewallMap = new FirewallMap($container, $map);
@ -60,7 +60,7 @@ class FirewallMapTest extends TestCase
{
$request = new Request();
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
$firewallContext = $this->createMock(FirewallContext::class);
$firewallConfig = new FirewallConfig('main', 'user_checker');
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
@ -68,19 +68,19 @@ class FirewallMapTest extends TestCase
$listener = function () {};
$firewallContext->expects($this->once())->method('getListeners')->willReturn([$listener]);
$exceptionListener = $this->getMockBuilder(ExceptionListener::class)->disableOriginalConstructor()->getMock();
$exceptionListener = $this->createMock(ExceptionListener::class);
$firewallContext->expects($this->once())->method('getExceptionListener')->willReturn($exceptionListener);
$logoutListener = $this->getMockBuilder(LogoutListener::class)->disableOriginalConstructor()->getMock();
$logoutListener = $this->createMock(LogoutListener::class);
$firewallContext->expects($this->once())->method('getLogoutListener')->willReturn($logoutListener);
$matcher = $this->getMockBuilder(RequestMatcherInterface::class)->getMock();
$matcher = $this->createMock(RequestMatcherInterface::class);
$matcher->expects($this->once())
->method('matches')
->with($request)
->willReturn(true);
$container = $this->getMockBuilder(Container::class)->getMock();
$container = $this->createMock(Container::class);
$container->expects($this->exactly(2))->method('get')->willReturn($firewallContext);
$firewallMap = new FirewallMap($container, ['security.firewall.map.context.foo' => $matcher]);

View File

@ -37,8 +37,8 @@ class SecurityUserValueResolverTest extends TestCase
public function testResolveNoUser()
{
$mock = $this->getMockBuilder(UserInterface::class)->getMock();
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
$mock = $this->createMock(UserInterface::class);
$token = $this->createMock(TokenInterface::class);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
@ -59,8 +59,8 @@ class SecurityUserValueResolverTest extends TestCase
public function testResolve()
{
$user = $this->getMockBuilder(UserInterface::class)->getMock();
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
$user = $this->createMock(UserInterface::class);
$token = $this->createMock(TokenInterface::class);
$token->expects($this->any())->method('getUser')->willReturn($user);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
@ -74,8 +74,8 @@ class SecurityUserValueResolverTest extends TestCase
public function testIntegration()
{
$user = $this->getMockBuilder(UserInterface::class)->getMock();
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
$user = $this->createMock(UserInterface::class);
$token = $this->createMock(TokenInterface::class);
$token->expects($this->any())->method('getUser')->willReturn($user);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
@ -86,7 +86,7 @@ class SecurityUserValueResolverTest extends TestCase
public function testIntegrationNoUser()
{
$token = $this->getMockBuilder(TokenInterface::class)->getMock();
$token = $this->createMock(TokenInterface::class);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);

View File

@ -30,7 +30,7 @@ class PreviewErrorControllerTest extends TestCase
$code = 123;
$logicalControllerName = 'foo:bar:baz';
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$kernel = $this->createMock(HttpKernelInterface::class);
$kernel
->expects($this->once())
->method('handle')

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\LogicException;
class TwigLoaderPassTest extends TestCase
{
@ -89,7 +90,7 @@ class TwigLoaderPassTest extends TestCase
public function testMapperPassWithZeroTaggedLoaders()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\LogicException::class);
$this->expectException(LogicException::class);
$this->pass->process($this->builder);
}
}

View File

@ -13,7 +13,10 @@ namespace Symfony\Bundle\TwigBundle\Tests\Loader;
use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader;
use Symfony\Bundle\TwigBundle\Tests\TestCase;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
use Twig\Error\LoaderError;
/**
* @group legacy
@ -22,8 +25,8 @@ class FilesystemLoaderTest extends TestCase
{
public function testGetSourceContext()
{
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$locator = $this->getMockBuilder(\Symfony\Component\Config\FileLocatorInterface::class)->getMock();
$parser = $this->createMock(TemplateNameParserInterface::class);
$locator = $this->createMock(FileLocatorInterface::class);
$locator
->expects($this->once())
->method('locate')
@ -42,8 +45,8 @@ class FilesystemLoaderTest extends TestCase
public function testExists()
{
// should return true for templates that Twig does not find, but Symfony does
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$locator = $this->getMockBuilder(\Symfony\Component\Config\FileLocatorInterface::class)->getMock();
$parser = $this->createMock(TemplateNameParserInterface::class);
$locator = $this->createMock(FileLocatorInterface::class);
$locator
->expects($this->once())
->method('locate')
@ -56,16 +59,16 @@ class FilesystemLoaderTest extends TestCase
public function testTwigErrorIfLocatorThrowsInvalid()
{
$this->expectException(\Twig\Error\LoaderError::class);
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$this->expectException(LoaderError::class);
$parser = $this->createMock(TemplateNameParserInterface::class);
$parser
->expects($this->once())
->method('parse')
->with('name.format.engine')
->willReturn($this->getMockBuilder(TemplateReferenceInterface::class)->getMock())
->willReturn($this->createMock(TemplateReferenceInterface::class))
;
$locator = $this->getMockBuilder(\Symfony\Component\Config\FileLocatorInterface::class)->getMock();
$locator = $this->createMock(FileLocatorInterface::class);
$locator
->expects($this->once())
->method('locate')
@ -78,16 +81,16 @@ class FilesystemLoaderTest extends TestCase
public function testTwigErrorIfLocatorReturnsFalse()
{
$this->expectException(\Twig\Error\LoaderError::class);
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$this->expectException(LoaderError::class);
$parser = $this->createMock(TemplateNameParserInterface::class);
$parser
->expects($this->once())
->method('parse')
->with('name.format.engine')
->willReturn($this->getMockBuilder(TemplateReferenceInterface::class)->getMock())
->willReturn($this->createMock(TemplateReferenceInterface::class))
;
$locator = $this->getMockBuilder(\Symfony\Component\Config\FileLocatorInterface::class)->getMock();
$locator = $this->createMock(FileLocatorInterface::class);
$locator
->expects($this->once())
->method('locate')
@ -100,10 +103,10 @@ class FilesystemLoaderTest extends TestCase
public function testTwigErrorIfTemplateDoesNotExist()
{
$this->expectException(\Twig\Error\LoaderError::class);
$this->expectException(LoaderError::class);
$this->expectExceptionMessageMatches('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.templates\)/');
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$locator = $this->getMockBuilder(\Symfony\Component\Config\FileLocatorInterface::class)->getMock();
$parser = $this->createMock(TemplateNameParserInterface::class);
$locator = $this->createMock(FileLocatorInterface::class);
$loader = new FilesystemLoader($locator, $parser);
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/templates');
@ -115,8 +118,8 @@ class FilesystemLoaderTest extends TestCase
public function testTwigSoftErrorIfTemplateDoesNotExist()
{
$parser = $this->getMockBuilder(\Symfony\Component\Templating\TemplateNameParserInterface::class)->getMock();
$locator = $this->getMockBuilder(\Symfony\Component\Config\FileLocatorInterface::class)->getMock();
$parser = $this->createMock(TemplateNameParserInterface::class);
$locator = $this->createMock(FileLocatorInterface::class);
$loader = new FilesystemLoader($locator, $parser);
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/templates');

View File

@ -4,6 +4,7 @@ namespace Symfony\Bundle\TwigBundle\Tests\Loader;
use Symfony\Bundle\TwigBundle\Loader\NativeFilesystemLoader;
use Symfony\Bundle\TwigBundle\Tests\TestCase;
use Twig\Error\LoaderError;
class NativeFilesystemLoaderTest extends TestCase
{
@ -17,7 +18,7 @@ class NativeFilesystemLoaderTest extends TestCase
public function testWithLegacyStyle1()
{
$this->expectException(\Twig\Error\LoaderError::class);
$this->expectException(LoaderError::class);
$this->expectExceptionMessage('Template reference "TestBundle::Foo/index.html.twig" not found, did you mean "@Test/Foo/index.html.twig"?');
$loader = new NativeFilesystemLoader(null, __DIR__.'/../');
$loader->addPath('Fixtures/templates', 'Test');
@ -27,7 +28,7 @@ class NativeFilesystemLoaderTest extends TestCase
public function testWithLegacyStyle2()
{
$this->expectException(\Twig\Error\LoaderError::class);
$this->expectException(LoaderError::class);
$this->expectExceptionMessage('Template reference "TestBundle:Foo:index.html.twig" not found, did you mean "@Test/Foo/index.html.twig"?');
$loader = new NativeFilesystemLoader(null, __DIR__.'/../');
$loader->addPath('Fixtures/templates', 'Test');

View File

@ -12,16 +12,18 @@
namespace Symfony\Bundle\TwigBundle\Tests;
use Symfony\Bundle\TwigBundle\TemplateIterator;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
class TemplateIteratorTest extends TestCase
{
public function testGetIterator()
{
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
$bundle = $this->createMock(BundleInterface::class);
$bundle->expects($this->any())->method('getName')->willReturn('BarBundle');
$bundle->expects($this->any())->method('getPath')->willReturn(__DIR__.'/Fixtures/templates/BarBundle');
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class)->disableOriginalConstructor()->getMock();
$kernel = $this->createMock(Kernel::class);
$kernel->expects($this->any())->method('getBundles')->willReturn([
$bundle,
]);

View File

@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController;
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
use Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator;
use Symfony\Bundle\WebProfilerBundle\Tests\Functional\WebProfilerBundleKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -24,6 +25,7 @@ use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
@ -35,8 +37,8 @@ class ProfilerControllerTest extends WebTestCase
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('The profiler must be enabled.');
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$controller = new ProfilerController($urlGenerator, null, $twig, []);
$controller->homeAction();
@ -111,8 +113,8 @@ class ProfilerControllerTest extends WebTestCase
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('The profiler must be enabled.');
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$controller = new ProfilerController($urlGenerator, null, $twig, []);
$controller->toolbarAction(Request::create('/_wdt/foo-token'), null);
@ -123,12 +125,9 @@ class ProfilerControllerTest extends WebTestCase
*/
public function testToolbarActionWithEmptyToken($token)
{
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$profiler = $this
->getMockBuilder(Profiler::class)
->disableOriginalConstructor()
->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$profiler = $this->createMock(Profiler::class);
$controller = new ProfilerController($urlGenerator, $profiler, $twig, []);
@ -150,12 +149,9 @@ class ProfilerControllerTest extends WebTestCase
*/
public function testOpeningDisallowedPaths($path, $isAllowed)
{
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$profiler = $this
->getMockBuilder(Profiler::class)
->disableOriginalConstructor()
->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$profiler = $this->createMock(Profiler::class);
$controller = new ProfilerController($urlGenerator, $profiler, $twig, [], null, __DIR__.'/../..');
@ -186,11 +182,8 @@ class ProfilerControllerTest extends WebTestCase
*/
public function testReturns404onTokenNotFound($withCsp)
{
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$profiler = $this
->getMockBuilder(Profiler::class)
->disableOriginalConstructor()
->getMock();
$twig = $this->createMock(Environment::class);
$profiler = $this->createMock(Profiler::class);
$profiler
->expects($this->exactly(2))
@ -214,8 +207,8 @@ class ProfilerControllerTest extends WebTestCase
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('The profiler must be enabled.');
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$controller = new ProfilerController($urlGenerator, null, $twig, []);
$controller->searchBarAction(Request::create('/_profiler/search_bar'));
@ -240,11 +233,8 @@ class ProfilerControllerTest extends WebTestCase
*/
public function testSearchResultsAction($withCsp)
{
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$profiler = $this
->getMockBuilder(Profiler::class)
->disableOriginalConstructor()
->getMock();
$twig = $this->createMock(Environment::class);
$profiler = $this->createMock(Profiler::class);
$controller = $this->createController($profiler, $twig, $withCsp);
@ -306,8 +296,8 @@ class ProfilerControllerTest extends WebTestCase
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('The profiler must be enabled.');
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$controller = new ProfilerController($urlGenerator, null, $twig, []);
$controller->searchBarAction(Request::create('/_profiler/search'));
@ -345,8 +335,8 @@ class ProfilerControllerTest extends WebTestCase
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('The profiler must be enabled.');
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$controller = new ProfilerController($urlGenerator, null, $twig, []);
$controller->phpinfoAction(Request::create('/_profiler/phpinfo'));
@ -464,10 +454,10 @@ class ProfilerControllerTest extends WebTestCase
private function createController($profiler, $twig, $withCSP, array $templates = []): ProfilerController
{
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
if ($withCSP) {
$nonceGenerator = $this->getMockBuilder(\Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator::class)->getMock();
$nonceGenerator = $this->createMock(NonceGenerator::class);
$nonceGenerator->method('generate')->willReturn('dummy_nonce');
return new ProfilerController($urlGenerator, $profiler, $twig, $templates, new ContentSecurityPolicyHandler($nonceGenerator));

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\WebProfilerBundle\Tests\Csp;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
use Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -210,7 +211,7 @@ class ContentSecurityPolicyHandlerTest extends TestCase
private function mockNonceGenerator($value)
{
$generator = $this->getMockBuilder(\Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator::class)->getMock();
$generator = $this->createMock(NonceGenerator::class);
$generator->expects($this->any())
->method('generate')

View File

@ -52,7 +52,7 @@ class WebProfilerExtensionTest extends TestCase
{
parent::setUp();
$this->kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$this->kernel = $this->createMock(KernelInterface::class);
$this->container = new ContainerBuilder();
$this->container->register('error_handler.error_renderer.html', HtmlErrorRenderer::class)->setPublic(true);

View File

@ -16,9 +16,12 @@ use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
class WebDebugToolbarListenerTest extends TestCase
{
@ -310,7 +313,7 @@ class WebDebugToolbarListenerTest extends TestCase
$request->headers = new HeaderBag();
if ($hasSession) {
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class)->disableOriginalConstructor()->getMock();
$session = $this->createMock(Session::class);
$request->expects($this->any())
->method('getSession')
->willReturn($session);
@ -321,7 +324,7 @@ class WebDebugToolbarListenerTest extends TestCase
protected function getTwigMock($render = 'WDT')
{
$templating = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
$templating = $this->createMock(Environment::class);
$templating->expects($this->any())
->method('render')
->willReturn($render);
@ -331,11 +334,11 @@ class WebDebugToolbarListenerTest extends TestCase
protected function getUrlGeneratorMock()
{
return $this->getMockBuilder(UrlGeneratorInterface::class)->getMock();
return $this->createMock(UrlGeneratorInterface::class);
}
protected function getKernelMock()
{
return $this->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class)->disableOriginalConstructor()->getMock();
return $this->createMock(Kernel::class);
}
}

View File

@ -13,7 +13,9 @@ namespace Symfony\Bundle\WebProfilerBundle\Tests\Profiler;
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
use Twig\Loader\SourceContextLoaderInterface;
@ -31,7 +33,7 @@ class TemplateManagerTest extends TestCase
protected $twigEnvironment;
/**
* @var \Symfony\Component\HttpKernel\Profiler\Profiler
* @var Profiler
*/
protected $profiler;
@ -57,7 +59,7 @@ class TemplateManagerTest extends TestCase
public function testGetNameOfInvalidTemplate()
{
$this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);
$this->expectException(NotFoundHttpException::class);
$this->templateManager->getName(new Profile('token'), 'notexistingpanel');
}
@ -98,12 +100,12 @@ class TemplateManagerTest extends TestCase
protected function mockProfile()
{
return $this->getMockBuilder(Profile::class)->disableOriginalConstructor()->getMock();
return $this->createMock(Profile::class);
}
protected function mockTwigEnvironment()
{
$this->twigEnvironment = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$this->twigEnvironment = $this->createMock(Environment::class);
if (Environment::MAJOR_VERSION > 1) {
$loader = $this->createMock(LoaderInterface::class);
@ -122,9 +124,7 @@ class TemplateManagerTest extends TestCase
protected function mockProfiler()
{
$this->profiler = $this->getMockBuilder(\Symfony\Component\HttpKernel\Profiler\Profiler::class)
->disableOriginalConstructor()
->getMock();
$this->profiler = $this->createMock(Profiler::class);
return $this->profiler;
}

View File

@ -13,12 +13,14 @@ namespace Symfony\Component\Asset\Tests\Context;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\RequestStackContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class RequestStackContextTest extends TestCase
{
public function testGetBasePathEmpty()
{
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStackContext = new RequestStackContext($requestStack);
$this->assertEmpty($requestStackContext->getBasePath());
@ -28,10 +30,10 @@ class RequestStackContextTest extends TestCase
{
$testBasePath = 'test-path';
$request = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class)->getMock();
$request = $this->createMock(Request::class);
$request->method('getBasePath')
->willReturn($testBasePath);
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStack->method('getMasterRequest')
->willReturn($request);
@ -42,7 +44,7 @@ class RequestStackContextTest extends TestCase
public function testIsSecureFalse()
{
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStackContext = new RequestStackContext($requestStack);
$this->assertFalse($requestStackContext->isSecure());
@ -50,10 +52,10 @@ class RequestStackContextTest extends TestCase
public function testIsSecureTrue()
{
$request = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class)->getMock();
$request = $this->createMock(Request::class);
$request->method('isSecure')
->willReturn(true);
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStack->method('getMasterRequest')
->willReturn($request);
@ -64,7 +66,7 @@ class RequestStackContextTest extends TestCase
public function testDefaultContext()
{
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStackContext = new RequestStackContext($requestStack, 'default-path', true);
$this->assertSame('default-path', $requestStackContext->getBasePath());

View File

@ -12,7 +12,10 @@
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Exception\InvalidArgumentException;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\PackageInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
@ -21,8 +24,8 @@ class PackagesTest extends TestCase
public function testGetterSetters()
{
$packages = new Packages();
$packages->setDefaultPackage($default = $this->getMockBuilder(\Symfony\Component\Asset\PackageInterface::class)->getMock());
$packages->addPackage('a', $a = $this->getMockBuilder(\Symfony\Component\Asset\PackageInterface::class)->getMock());
$packages->setDefaultPackage($default = $this->createMock(PackageInterface::class));
$packages->addPackage('a', $a = $this->createMock(PackageInterface::class));
$this->assertSame($default, $packages->getPackage());
$this->assertSame($a, $packages->getPackage('a'));
@ -57,14 +60,14 @@ class PackagesTest extends TestCase
public function testNoDefaultPackage()
{
$this->expectException(\Symfony\Component\Asset\Exception\LogicException::class);
$this->expectException(LogicException::class);
$packages = new Packages();
$packages->getPackage();
}
public function testUndefinedPackage()
{
$this->expectException(\Symfony\Component\Asset\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$packages = new Packages();
$packages->getPackage('a');
}

View File

@ -12,8 +12,10 @@
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
class PathPackageTest extends TestCase
{
@ -77,7 +79,7 @@ class PathPackageTest extends TestCase
public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder(\Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface::class)->getMock();
$versionStrategy = $this->createMock(VersionStrategyInterface::class);
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
@ -88,7 +90,7 @@ class PathPackageTest extends TestCase
private function getContext($basePath)
{
$context = $this->getMockBuilder(\Symfony\Component\Asset\Context\ContextInterface::class)->getMock();
$context = $this->createMock(ContextInterface::class);
$context->expects($this->any())->method('getBasePath')->willReturn($basePath);
return $context;

View File

@ -12,9 +12,13 @@
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\Exception\InvalidArgumentException;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Asset\UrlPackage;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
class UrlPackageTest extends TestCase
{
@ -86,7 +90,7 @@ class UrlPackageTest extends TestCase
public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder(\Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface::class)->getMock();
$versionStrategy = $this->createMock(VersionStrategyInterface::class);
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
@ -97,7 +101,7 @@ class UrlPackageTest extends TestCase
public function testNoBaseUrls()
{
$this->expectException(\Symfony\Component\Asset\Exception\LogicException::class);
$this->expectException(LogicException::class);
new UrlPackage([], new EmptyVersionStrategy());
}
@ -106,7 +110,7 @@ class UrlPackageTest extends TestCase
*/
public function testWrongBaseUrl($baseUrls)
{
$this->expectException(\Symfony\Component\Asset\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
new UrlPackage($baseUrls, new EmptyVersionStrategy());
}
@ -120,7 +124,7 @@ class UrlPackageTest extends TestCase
private function getContext($secure)
{
$context = $this->getMockBuilder(\Symfony\Component\Asset\Context\ContextInterface::class)->getMock();
$context = $this->createMock(ContextInterface::class);
$context->expects($this->any())->method('isSecure')->willReturn($secure);
return $context;

Some files were not shown because too many files have changed in this diff Show More