Skip to content

Commit

Permalink
Merge pull request #681 from franmomu/remove_deprecated_code
Browse files Browse the repository at this point in the history
Remove deprecated code
  • Loading branch information
malarzm authored Jul 19, 2021
2 parents ca6350c + 095bc4f commit f411813
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
20 changes: 7 additions & 13 deletions Form/DoctrineMongoDBTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\MappingException;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
Expand All @@ -21,7 +20,6 @@
use Symfony\Component\Form\Guess\ValueGuess;

use function array_key_exists;
use function method_exists;

/**
* Tries to guess form types according to ODM mappings
Expand All @@ -34,13 +32,9 @@ class DoctrineMongoDBTypeGuesser implements FormTypeGuesserInterface
/** @var array */
private $cache = [];

/** @var bool */
private $typeFQCN;

public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
$this->typeFQCN = method_exists(AbstractType::class, 'getBlockPrefix');
}

/**
Expand All @@ -64,7 +58,7 @@ public function guessType($class, $property)
$mapping = $metadata->getFieldMapping($property);

return new TypeGuess(
$this->typeFQCN ? DocumentType::class : 'document',
DocumentType::class,
[
'class' => $mapping['targetDocument'],
'multiple' => $multiple,
Expand All @@ -78,45 +72,45 @@ public function guessType($class, $property)
switch ($fieldMapping['type']) {
case 'collection':
return new TypeGuess(
$this->typeFQCN ? CollectionType::class : 'collection',
CollectionType::class,
[],
Guess::MEDIUM_CONFIDENCE
);

case 'bool':
case 'boolean':
return new TypeGuess(
$this->typeFQCN ? CheckboxType::class : 'checkbox',
CheckboxType::class,
[],
Guess::HIGH_CONFIDENCE
);

case 'date':
case 'timestamp':
return new TypeGuess(
$this->typeFQCN ? DateTimeType::class : 'datetime',
DateTimeType::class,
[],
Guess::HIGH_CONFIDENCE
);

case 'float':
return new TypeGuess(
$this->typeFQCN ? NumberType::class : 'number',
NumberType::class,
[],
Guess::MEDIUM_CONFIDENCE
);

case 'int':
case 'integer':
return new TypeGuess(
$this->typeFQCN ? IntegerType::class : 'integer',
IntegerType::class,
[],
Guess::MEDIUM_CONFIDENCE
);

case 'string':
return new TypeGuess(
$this->typeFQCN ? TextType::class : 'text',
TextType::class,
[],
Guess::MEDIUM_CONFIDENCE
);
Expand Down
4 changes: 2 additions & 2 deletions Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class SymfonyFixturesLoader extends ContainerAwareLoader implements Symfon
*
* @param array $fixtures
*/
public function addFixtures(array $fixtures)
public function addFixtures(array $fixtures): void
{
// Because parent::addFixture may call $this->createFixture
// we cannot call $this->addFixture in this loop
Expand All @@ -48,7 +48,7 @@ public function addFixtures(array $fixtures)
}
}

public function addFixture(FixtureInterface $fixture)
public function addFixture(FixtureInterface $fixture): void
{
$class = get_class($fixture);
$this->loadedFixtures[$class] = $fixture;
Expand Down
4 changes: 1 addition & 3 deletions ManagerConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ public function configure(DocumentManager $documentManager)

/**
* Enable filters for an given document manager
*
* @return null
*/
private function enableFilters(DocumentManager $documentManager)
private function enableFilters(DocumentManager $documentManager): void
{
if (empty($this->enabledFilters)) {
return;
Expand Down
18 changes: 6 additions & 12 deletions Tests/Form/Type/DocumentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,23 @@
use InvalidArgumentException;
use MongoDB\BSON\ObjectId;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Test\TypeTestCase;

use function array_merge;
use function method_exists;

class DocumentTypeTest extends TypeTestCase
{
/** @var DocumentManager */
private $dm;

/** @var MockObject */
/** @var MockObject&ManagerRegistry */
private $dmRegistry;

private $typeFQCN;

protected function setUp(): void
{
$this->typeFQCN = method_exists(AbstractType::class, 'getBlockPrefix');

$this->dm = TestCase::createTestDocumentManager([
__DIR__ . '/../../Fixtures/Form/Document',
]);
Expand All @@ -61,7 +55,7 @@ protected function tearDown(): void

public function testDocumentManagerOptionSetsEmOption(): void
{
$field = $this->factory->createNamed('name', $this->typeFQCN ? DocumentType::class : 'document', null, [
$field = $this->factory->createNamed('name', DocumentType::class, null, [
'class' => Document::class,
'document_manager' => 'default',
]);
Expand All @@ -71,7 +65,7 @@ public function testDocumentManagerOptionSetsEmOption(): void

public function testDocumentManagerInstancePassedAsOption(): void
{
$field = $this->factory->createNamed('name', $this->typeFQCN ? DocumentType::class : 'document', null, [
$field = $this->factory->createNamed('name', DocumentType::class, null, [
'class' => Document::class,
'document_manager' => $this->dm,
]);
Expand All @@ -82,7 +76,7 @@ public function testDocumentManagerInstancePassedAsOption(): void
public function testSettingDocumentManagerAndEmOptionShouldThrowException(): void
{
$this->expectException(InvalidArgumentException::class);
$this->factory->createNamed('name', $this->typeFQCN ? DocumentType::class : 'document', null, [
$this->factory->createNamed('name', DocumentType::class, null, [
'document_manager' => 'default',
'em' => 'default',
]);
Expand All @@ -101,10 +95,10 @@ public function testManyToManyReferences(): void

$this->dm->flush();

$form = $this->factory->create($this->typeFQCN ? FormType::class : 'form', $document)
$form = $this->factory->create(FormType::class, $document)
->add(
'categories',
$this->typeFQCN ? DocumentType::class : 'document',
DocumentType::class,
[
'class' => Category::class,
'multiple' => true,
Expand Down
12 changes: 3 additions & 9 deletions Tests/Form/Type/TypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,22 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Test\TypeTestCase;

use function array_merge;
use function method_exists;

class TypeGuesserTest extends TypeTestCase
{
/** @var DocumentManager */
private $dm;

/** @var MockObject */
/** @var MockObject&ManagerRegistry */
private $dmRegistry;

private $typeFQCN;

protected function setUp(): void
{
$this->typeFQCN = method_exists(AbstractType::class, 'getBlockPrefix');

$this->dm = TestCase::createTestDocumentManager([
__DIR__ . '/../../Fixtures/Form/Guesser',
]);
Expand Down Expand Up @@ -62,7 +56,7 @@ protected function tearDown(): void
*/
public function testTypesShouldBeGuessedCorrectly(): void
{
$form = $this->factory->create($this->typeFQCN ? GuesserTestType::class : new GuesserTestType(), null, ['dm' => $this->dm]);
$form = $this->factory->create(GuesserTestType::class, null, ['dm' => $this->dm]);
$this->assertType('text', $form->get('name'));
$this->assertType('document', $form->get('categories'));
$this->assertType('datetime', $form->get('date'));
Expand All @@ -76,7 +70,7 @@ public function testTypesShouldBeGuessedCorrectly(): void

protected function assertType(string $type, FormInterface $form): void
{
$this->assertEquals($type, $this->typeFQCN ? $form->getConfig()->getType()->getBlockPrefix() : $form->getConfig()->getType()->getName());
$this->assertEquals($type, $form->getConfig()->getType()->getBlockPrefix());
}

/**
Expand Down

0 comments on commit f411813

Please sign in to comment.