Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Use createMock() and use import instead of FQCN
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
2 parents edc262d + a908956 commit 290deda
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 65 deletions.
5 changes: 3 additions & 2 deletions Tests/DataCollector/DoctrineDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -236,7 +237,7 @@ private function createCollector($queries)
->method('getDatabasePlatform')
->willReturn(new MySqlPlatform());

$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry = $this->createMock(ManagerRegistry::class);
$registry
->expects($this->any())
->method('getConnectionNames')
Expand All @@ -249,7 +250,7 @@ private function createCollector($queries)
->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);
Expand Down
3 changes: 2 additions & 1 deletion Tests/DataFixtures/ContainerAwareLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
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();

Expand Down
5 changes: 3 additions & 2 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,7 @@
class DoctrineExtensionTest extends TestCase
{
/**
* @var \Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension
* @var AbstractDoctrineExtension
*/
private $extension;

Expand All @@ -31,7 +32,7 @@ protected function setUp(): void
parent::setUp();

$this->extension = $this
->getMockBuilder(\Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension::class)
->getMockBuilder(AbstractDoctrineExtension::class)
->setMethods([
'getMappingResourceConfigDirectory',
'getObjectManagerElementName',
Expand Down
12 changes: 5 additions & 7 deletions Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 <[email protected]>
Expand Down Expand Up @@ -64,7 +65,7 @@ public function testTransformNull()

public function testTransformExpectsArrayOrCollection()
{
$this->expectException(\Symfony\Component\Form\Exception\TransformationFailedException::class);
$this->expectException(TransformationFailedException::class);
$this->transformer->transform('Foo');
}

Expand Down
16 changes: 8 additions & 8 deletions Tests/Form/DoctrineOrmTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public function requiredProvider()
$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' => [[]]];
Expand All @@ -57,7 +57,7 @@ public function requiredProvider()
$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]]];
Expand All @@ -66,7 +66,7 @@ public function requiredProvider()
$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]]];
Expand All @@ -75,7 +75,7 @@ public function requiredProvider()
$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];
Expand All @@ -85,10 +85,10 @@ public function requiredProvider()

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;

class MergeDoctrineCollectionListenerTest extends TestCase
{
Expand All @@ -32,7 +33,7 @@ protected function setUp(): void
{
$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();
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Form/Type/EntityTypePerformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
19 changes: 12 additions & 7 deletions Tests/Form/Type/EntityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
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\LazyChoiceList;
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
{
Expand Down Expand Up @@ -118,13 +123,13 @@ protected function persist(array $entities)

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',
]);
Expand Down Expand Up @@ -219,7 +224,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()

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,
Expand All @@ -229,7 +234,7 @@ public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()

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,
Expand Down Expand Up @@ -1242,7 +1247,7 @@ public function testLoaderCaching()
$choiceList2 = $form->get('property2')->getConfig()->getAttribute('choice_list');
$choiceList3 = $form->get('property3')->getConfig()->getAttribute('choice_list');

$this->assertInstanceOf(\Symfony\Component\Form\ChoiceList\LazyChoiceList::class, $choiceList1);
$this->assertInstanceOf(LazyChoiceList::class, $choiceList1);
$this->assertSame($choiceList1, $choiceList2);
$this->assertSame($choiceList1, $choiceList3);
}
Expand Down Expand Up @@ -1302,14 +1307,14 @@ public function testLoaderCachingWithParameters()
$choiceList2 = $form->get('property2')->getConfig()->getAttribute('choice_list');
$choiceList3 = $form->get('property3')->getConfig()->getAttribute('choice_list');

$this->assertInstanceOf(\Symfony\Component\Form\ChoiceList\LazyChoiceList::class, $choiceList1);
$this->assertInstanceOf(LazyChoiceList::class, $choiceList1);
$this->assertSame($choiceList1, $choiceList2);
$this->assertSame($choiceList1, $choiceList3);
}

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))
Expand Down
11 changes: 6 additions & 5 deletions Tests/Logger/DbalLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -53,7 +54,7 @@ public function getLogFixtures()

public function testLogNonUtf8()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);

$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
Expand All @@ -76,7 +77,7 @@ public function testLogNonUtf8()

public function testLogNonUtf8Array()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);

$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
Expand Down Expand Up @@ -107,7 +108,7 @@ public function testLogNonUtf8Array()

public function testLogLongString()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);

$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
Expand Down Expand Up @@ -135,7 +136,7 @@ public function testLogLongString()

public function testLogUTF8LongString()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);

$dbalLogger = $this
->getMockBuilder(DbalLogger::class)
Expand Down
12 changes: 6 additions & 6 deletions Tests/Security/User/EntityUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@
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;

Expand Down Expand Up @@ -71,9 +73,7 @@ public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty
->with('user1')
->willReturn($user);

$em = $this->getMockBuilder(\Doctrine\ORM\EntityManager::class)
->disableOriginalConstructor()
->getMock();
$em = $this->createMock(EntityManager::class);
$em
->expects($this->once())
->method('getRepository')
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testRefreshInvalidUser()
$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);
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
->method('loadUserByUsername')
->with('name')
->willReturn(
$this->getMockBuilder(UserInterface::class)->getMock()
$this->createMock(UserInterface::class)
);

$provider = new EntityUserProvider(
Expand Down Expand Up @@ -198,7 +198,7 @@ public function testPasswordUpgrades()

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))
Expand Down
Loading

0 comments on commit 290deda

Please sign in to comment.