Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate fixture_loader option #790

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@
use Doctrine\ODM\MongoDB\Configuration as ODMConfiguration;
use Doctrine\ODM\MongoDB\Repository\DefaultGridFSRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use LogicException;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

use function class_parents;
use function count;
use function in_array;
use function is_array;
use function is_string;
use function json_decode;
use function preg_match;
use function sprintf;

/**
* FrameworkExtension configuration structure.
Expand Down Expand Up @@ -84,15 +79,11 @@ public function getConfigTreeBuilder()
->scalarNode('persistent_collection_dir')->defaultValue('%kernel.cache_dir%/doctrine/odm/mongodb/PersistentCollections')->end()
->scalarNode('auto_generate_persistent_collection_classes')->defaultValue(ODMConfiguration::AUTOGENERATE_NEVER)->end()
->scalarNode('fixture_loader')
->defaultValue(ContainerAwareLoader::class)
->beforeNormalization()
->ifTrue(static function ($v) {
return ! ($v === ContainerAwareLoader::class || in_array(ContainerAwareLoader::class, class_parents($v)));
})
->then(static function ($v) {
throw new LogicException(sprintf('The %s class is not a subclass of the ContainerAwareLoader', $v));
})
->end()
->setDeprecated(
'doctrine/mongodb-odm-bundle',
'4.7',
'The "fixture_loader" option is deprecated and will be dropped in doctrine/mongodb-odm-bundle 5.0.',
)
->end()
->scalarNode('default_document_manager')->end()
->scalarNode('default_connection')->end()
Expand Down
3 changes: 0 additions & 3 deletions DependencyInjection/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->overrideParameters($config, $container);

if (class_exists(DataFixturesLoader::class)) {
// set the fixtures loader
$container->setParameter('doctrine_mongodb.odm.fixture_loader', $config['fixture_loader']);

// Autowiring fixture loader
$container->registerForAutoconfiguration(ODMFixtureInterface::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);
Expand Down
1 change: 0 additions & 1 deletion Resources/doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ Full Default Configuration
default_document_manager: ~
default_connection: ~
default_database: default
fixture_loader: Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader

.. code-block:: xml

Expand Down
33 changes: 12 additions & 21 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection;

use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Configuration;
use Doctrine\Bundle\MongoDBBundle\Loader\SymfonyFixturesLoader;
use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Filter\BasicFilter;
use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Filter\ComplexFilter;
use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Filter\DisabledFilter;
Expand All @@ -13,9 +14,8 @@
use Doctrine\ODM\MongoDB\Configuration as ODMConfiguration;
use Doctrine\ODM\MongoDB\Repository\DefaultGridFSRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use LogicException;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Util\XmlUtils;
Expand All @@ -26,14 +26,15 @@

class ConfigurationTest extends TestCase
{
use ExpectDeprecationTrait;

public function testDefaults(): void
{
$processor = new Processor();
$configuration = new Configuration();
$options = $processor->processConfiguration($configuration, []);

$defaults = [
'fixture_loader' => ContainerAwareLoader::class,
'auto_generate_hydrator_classes' => false,
'auto_generate_proxy_classes' => ODMConfiguration::AUTOGENERATE_EVAL,
'auto_generate_persistent_collection_classes' => ODMConfiguration::AUTOGENERATE_NEVER,
Expand Down Expand Up @@ -66,7 +67,6 @@ public function testFullConfiguration(array $config): void
$options = $processor->processConfiguration($configuration, [$config]);

$expected = [
'fixture_loader' => ContainerAwareLoader::class,
'auto_generate_hydrator_classes' => 1,
'auto_generate_proxy_classes' => ODMConfiguration::AUTOGENERATE_FILE_NOT_EXISTS,
'auto_generate_persistent_collection_classes' => ODMConfiguration::AUTOGENERATE_EVAL,
Expand Down Expand Up @@ -517,27 +517,18 @@ public function testNullReplicaSetValue(): void
$this->assertFalse(array_key_exists('replicaSet', $processedConfig['connections']['conn1']['options']));
}

/** @dataProvider provideExceptionConfiguration */
public function testFixtureLoaderValidation(array $config): void
/** @group legacy */
public function testFixtureLoaderDeprecated(): void
{
$config = [
'fixture_loader' => SymfonyFixturesLoader::class,
];

$processor = new Processor();
$configuration = new Configuration();
$this->expectException(LogicException::class);
$processor->processConfiguration($configuration, [$config]);
}

/** @return array<mixed[]> */
public static function provideExceptionConfiguration(): array
{
$yaml = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/config/yml/exception.yml'));
$yaml = $yaml['doctrine_mongodb'];

$xml = XmlUtils::loadFile(__DIR__ . '/Fixtures/config/xml/exception.xml');
$xml = XmlUtils::convertDomElementToArray($xml->getElementsByTagName('config')->item(0));
$this->expectDeprecation('Since doctrine/mongodb-odm-bundle 4.7: The "fixture_loader" option is deprecated and will be dropped in doctrine/mongodb-odm-bundle 5.0.');

return [
[$yaml],
[$xml],
];
$processor->processConfiguration($configuration, [$config]);
}
}
13 changes: 0 additions & 13 deletions Tests/DependencyInjection/Fixtures/config/xml/exception.xml

This file was deleted.

1 change: 0 additions & 1 deletion Tests/DependencyInjection/Fixtures/config/xml/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
http://symfony.com/schema/dic/doctrine/odm/mongodb http://symfony.com/schema/dic/doctrine/odm/mongodb/mongodb-1.0.xsd">

<doctrine:config
fixture_loader="Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader"
auto-generate-hydrator-classes="true"
auto-generate-proxy-classes="true"
auto-generate-persistent-collection-classes="3"
Expand Down
2 changes: 0 additions & 2 deletions Tests/DependencyInjection/Fixtures/config/yml/exception.yml

This file was deleted.

1 change: 0 additions & 1 deletion Tests/DependencyInjection/Fixtures/config/yml/full.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
doctrine_mongodb:
fixture_loader: Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader
auto_generate_proxy_classes: 2
auto_generate_hydrator_classes: true
auto_generate_persistent_collection_classes: 3
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE-4.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ UPGRADE FROM 4.6 to 4.7

* The bundle now requires PHP 8.1 or newer. If you're not running PHP 8.1 yet,
it's recommended that you upgrade to PHP 8.1 before upgrading the bundle.

* The `fixture_loader` configuration option was deprecated and will be removed
in 5.0.
* The `doctrine_mongodb.odm.fixture_loader` parameter has been removed.