From 0d24d7d199d08fa8d17a23cc794bb09145e8bd47 Mon Sep 17 00:00:00 2001 From: Jordi Date: Sun, 14 Jun 2020 20:31:46 +0200 Subject: [PATCH] Make SonataEasyExtends optional --- UPGRADE-3.x.md | 12 +- composer.json | 3 +- docs/reference/advanced_configuration.rst | 40 +-- docs/reference/installation.rst | 285 ++++++++++-------- .../SonataNewsExtension.php | 101 ++++++- tests/App/AppKernel.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 58 +++- .../SonataNewsExtensionTest.php | 77 ++--- tests/Fixtures/configuration.yaml | 5 + 9 files changed, 361 insertions(+), 222 deletions(-) create mode 100644 tests/Fixtures/configuration.yaml diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 5ddbb6cd..4bf08b2b 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -1,6 +1,14 @@ UPGRADE 3.x =========== +UPGRADE FROM 3.x to 3.x +======================== + +### SonataEasyExtends is deprecated + +Registering `SonataEasyExtendsBundle` bundle is deprecated, it SHOULD NOT be registered. +Register `SonataDoctrineBundle` bundle instead. + UPGRADE FROM 3.1 to 3.2 ======================= @@ -11,6 +19,6 @@ UPGRADE FROM 3.0 to 3.1 ### Tests -All files under the ``Tests`` directory are now correctly handled as internal test classes. -You can't extend them anymore, because they are only loaded when running internal tests. +All files under the ``Tests`` directory are now correctly handled as internal test classes. +You can't extend them anymore, because they are only loaded when running internal tests. More information can be found in the [composer docs](https://getcomposer.org/doc/04-schema.md#autoload-dev). diff --git a/composer.json b/composer.json index 85d040f3..2e60c1cc 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,7 @@ "php": "^7.2", "sonata-project/classification-bundle": "^3.12", "sonata-project/datagrid-bundle": "^2.3.1", - "sonata-project/doctrine-extensions": "^1.5.1", - "sonata-project/easy-extends-bundle": "^2.5", + "sonata-project/doctrine-extensions": "^1.8", "sonata-project/form-extensions": "^0.1 || ^1.4", "sonata-project/formatter-bundle": "^4.0", "sonata-project/intl-bundle": "^2.4", diff --git a/docs/reference/advanced_configuration.rst b/docs/reference/advanced_configuration.rst index 745e5ab3..753fb7de 100644 --- a/docs/reference/advanced_configuration.rst +++ b/docs/reference/advanced_configuration.rst @@ -6,36 +6,36 @@ Advanced Configuration # config/packages/sonata_news.yaml sonata_news: - title: Sonata Project - link: https://sonata-project.org - description: Cool bundles on top of Symfony2 - salt: 'secureToken' + title: Sonata Project + link: https://sonata-project.org + description: Cool bundles on top of Symfony2 + salt: 'secureToken' permalink_generator: sonata.news.permalink.date # sonata.news.permalink.collection permalink: - date: '%%1$04d/%%2$02d/%%3$02d/%%4$s' # => 2012/02/01/slug - db_driver: 'no_driver' + date: '%%1$04d/%%2$02d/%%3$02d/%%4$s' # => 2012/02/01/slug + db_driver: 'no_driver' comment: notification: - emails: [email@example.org, email2@example.org] - from: no-reply@sonata-project.org + emails: [email@example.org, email2@example.org] + from: no-reply@sonata-project.org template: '@SonataNews/Mail/comment_notification.txt.twig' class: - post: Application\Sonata\NewsBundle\Entity\Post - comment: Application\Sonata\NewsBundle\Entity\Comment - media: Application\Sonata\MediaBundle\Entity\Media - user: Application\Sonata\UserBundle\Entity\User - tag: Application\Sonata\ClassificationBundle\Entity\Tag - collection: Application\Sonata\ClassificationBundle\Entity\Collection + post: App\Entity\SonataNewsPost + comment: App\Entity\SonataNewsComment + media: App\Entity\SonataMediaMedia + user: App\Entity\SonataUserUser + tag: App\Entity\SonataClassificationTag + collection: App\Entity\SonataClassificationCollection admin: post: - class: Sonata\NewsBundle\Admin\PostAdmin - controller: SonataAdminBundle:CRUD + class: Sonata\NewsBundle\Admin\PostAdmin + controller: SonataAdminBundle:CRUD translation: SonataNewsBundle comment: - class: Sonata\NewsBundle\Admin\CommentAdmin - controller: SonataNewsBundle:CommentAdmin + class: Sonata\NewsBundle\Admin\CommentAdmin + controller: SonataNewsBundle:CommentAdmin translation: SonataNewsBundle .. code-block:: yaml @@ -45,8 +45,8 @@ Advanced Configuration sonata_classification: class: collection: Application\Sonata\ClassificationBundle\Entity\Collection - tag: Application\Sonata\ClassificationBundle\Entity\Tag - category: Application\Sonata\ClassificationBundle\Entity\Category + tag: Application\Sonata\ClassificationBundle\Entity\Tag + category: Application\Sonata\ClassificationBundle\Entity\Category .. code-block:: yaml diff --git a/docs/reference/installation.rst b/docs/reference/installation.rst index a57b9bc7..344f743b 100644 --- a/docs/reference/installation.rst +++ b/docs/reference/installation.rst @@ -1,78 +1,93 @@ +.. index:: + single: Installation + single: Configuration + Installation ============ -Download the Bundle(s) ----------------------- +Prerequisites +------------- -.. code-block:: bash +PHP ^7.2 and Symfony ^4.4 are needed to make this bundle work, there are +also some Sonata dependencies that need to be installed and configured beforehand. - composer require sonata-project/news-bundle +Required dependencies: + +* `SonataAdminBundle `_ +* `SonataBlockBundle `_ +* `SonataFormatterBundle `_ +* `SonataIntlBundle `_ +* `SonataClassificationBundle `_ +* `SonataMediaBundle `_ -.. code-block:: bash +And the persistence bundle (choose one): - composer require sonata-project/doctrine-orm-admin-bundle +* `SonataDoctrineOrmAdminBundle `_ +* `SonataDoctrineMongoDBAdminBundle `_ -If you want to use the API, you also need ``friendsofsymfony/rest-bundle`` and ``nelmio/api-doc-bundle``. +Follow also their configuration step; you will find everything you need in +their own installation chapter. -.. code-block:: bash +.. note:: - composer require nelmio/api-doc-bundle + If a dependency is already installed somewhere in your project or in + another dependency, you won't need to install it again. - composer require friendsofsymfony/rest-bundle +Enable the Bundle +----------------- -Enable the Bundle(s) --------------------- +Add ``SonataNewsBundle`` via composer:: -Then, enable the bundle by adding it to the list of registered bundles -in ``bundles.php`` file of your project:: + composer require sonata-project/news-bundle + +If you want to use the REST API, you also need ``friendsofsymfony/rest-bundle`` and ``nelmio/api-doc-bundle``:: + + composer require friendsofsymfony/rest-bundle nelmio/api-doc-bundle + +Next, be sure to enable the bundles in your ``config/bundles.php`` file if they +are not already enabled:: // config/bundles.php return [ // ... - Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true], - Ivory\CKEditorBundle\IvoryCKEditorBundle::class => ['all' => true], Sonata\NewsBundle\SonataNewsBundle::class => ['all' => true], - Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true], - Sonata\MediaBundle\SonataMediaBundle::class => ['all' => true], - Sonata\AdminBundle\SonataAdminBundle::class => ['all' => true], - Sonata\IntlBundle\SonataIntlBundle::class => ['all' => true], - Sonata\FormatterBundle\SonataFormatterBundle::class => ['all' => true], - Sonata\ClassificationBundle\SonataClassificationBundle::class => ['all' => true], - Knp\Bundle\MarkdownBundle\KnpMarkdownBundle::class => ['all' => true], - Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], - Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle::class => ['all' => true], - JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], - Sonata\TranslationBundle\SonataTranslationBundle::class => ['all' => true], - Sonata\EasyExtendsBundle\SonataEasyExtendsBundle::class => ['dev' => true], ]; -.. note:: - - `You need to setup SonataBlockBundle first. `_ +Configuration +============= -Default configuration ---------------------- +Sonata Configuration +-------------------- .. code-block:: yaml # config/packages/sonata_news.yaml sonata_news: - title: Sonata Project - link: https://sonata-project.org - description: Cool bundles on top of Symfony2 - salt: 'secureToken' + title: Sonata Project + link: https://sonata-project.org + description: Cool bundles on top of Symfony + salt: secureToken permalink_generator: sonata.news.permalink.date # sonata.news.permalink.collection - db_driver: 'no_driver' # doctrine_orm or doctrine_mongodb it is mandatory to choose one here - + db_driver: doctrine_orm + class: + post: App\Entity\SonataNewsPost + comment: App\Entity\SonataNewsComment + media: App\Entity\SonataMediaMedia + user: App\Entity\SonataUserUser + tag: App\Entity\SonataClassificationTag + collection: App\Entity\SonataClassificationCollection comment: notification: - emails: [email@example.org, email2@example.org] - from: no-reply@sonata-project.org + emails: [email@example.org, email2@example.org] + from: no-reply@sonata-project.org template: '@SonataNews/Mail/comment_notification.txt.twig' -.. code-block:: yaml +Doctrine ORM Configuration +-------------------------- + +Add the bundle in the config mapping definition (or enable `auto_mapping`_):: # config/packages/doctrine.yaml @@ -80,110 +95,107 @@ Default configuration orm: entity_managers: default: - #metadata_cache_driver: apc - #query_cache_driver: apc - #result_cache_driver: apc mappings: - #ApplicationSonataNewsBundle: ~ SonataNewsBundle: ~ -* Add a new context into your ``sonata_media.yaml`` configuration if you don't have go there https://sonata-project.org/bundles/media/master/doc/reference/installation.html: - -.. code-block:: yaml +And then create the corresponding entities, ``src/Entity/SonataNewsComment``:: + + // src/Entity/SonataNewsComment.php + + use Doctrine\ORM\Mapping as ORM; + use Sonata\NewsBundle\Entity\BaseComment; + + /** + * @ORM\Entity + * @ORM\Table(name="news__comment") + */ + class SonataNewsComment extends BaseComment + { + /** + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + protected $id; + } + +and ``src/Entity/SonataNewsPost``:: + + // src/Entity/SonataNewsPost.php + + use Doctrine\ORM\Mapping as ORM; + use Sonata\NewsBundle\Entity\BasePost; + + /** + * @ORM\Entity + * @ORM\Table(name="news__post") + */ + class SonataNewsPost extends BasePost + { + /** + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + protected $id; + } + +The only thing left is to update your schema:: - # config/packages/sonata_media.yaml + bin/console doctrine:schema:update --force - news: - providers: - - sonata.media.provider.dailymotion - - sonata.media.provider.youtube - - sonata.media.provider.image +Doctrine MongoDB Configuration +------------------------------ - formats: - small: { width: 150 , quality: 95} - big: { width: 500 , quality: 90} +You have to create the corresponding documents, ``src/Document/SonataNewsComment``:: -* Create configuration file ``sonata_formatter.yaml`` the text formatters available for your blog post: + // src/Document/SonataNewsComment.php -.. code-block:: yaml + use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; + use Sonata\NewsBundle\Document\BaseComment; - # config/packages/sonata_formatter.yaml - - sonata_formatter: - formatters: - markdown: - service: sonata.formatter.text.markdown - extensions: - - sonata.formatter.twig.control_flow - - sonata.formatter.twig.gist - - sonata.media.formatter.twig - - text: - service: sonata.formatter.text.text - extensions: - - sonata.formatter.twig.control_flow - - sonata.formatter.twig.gist - - sonata.media.formatter.twig - - rawhtml: - service: sonata.formatter.text.raw - extensions: - - sonata.formatter.twig.control_flow - - sonata.formatter.twig.gist - - sonata.media.formatter.twig - - richhtml: - service: sonata.formatter.text.raw - extensions: - - sonata.formatter.twig.control_flow - - sonata.formatter.twig.gist - - sonata.media.formatter.twig - -Generate the application bundles --------------------------------- - -.. code-block:: bash - - bin/console sonata:easy-extends:generate SonataNewsBundle -d src - bin/console sonata:easy-extends:generate SonataMediaBundle -d src - bin/console sonata:easy-extends:generate SonataClassificationBundle -d src - -Enable the application bundles ------------------------------- + /** + * @MongoDB\Document + */ + class SonataNewsComment extends BaseComment + { + /** + * @MongoDB\Id + */ + protected $id; + } -.. code-block:: php +and ``src/Document/SonataNewsPost``:: - // config/bundles.php + // src/Document/SonataNewsPost.php - return [ - // ... - App\Application\Sonata\NewsBundle\ApplicationSonataNewsBundle::class => ['all' => true], - App\Application\Sonata\MediaBundle\ApplicationSonataMediaBundle::class => ['all' => true], - App\Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle::class => ['all' => true], - ]; + use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; + use Sonata\NewsBundle\Document\BasePost; -Uncomment the ApplicationSonataNewsBundle mapping -------------------------------------------------- + /** + * @MongoDB\Document + */ + class SonataNewsPost extends BasePost + { + /** + * @MongoDB\Id + */ + protected $id; + } -.. code-block:: yaml +Then configure ``SonataNewsBundle`` to use the newly generated classes:: # config/packages/sonata_news.yaml - doctrine: - orm: - entity_managers: - default: - # ... - mappings: - ApplicationSonataNewsBundle: ~ - SonataNewsBundle: ~ - -Update Database Schema ----------------------- - -.. code-block:: bash - - bin/console doctrine:schema:update --force + sonata_news: + manager_type: doctrine_mongodb + class: + post: App\Document\SonataNewsPost + comment: App\Document\SonataNewsComment + media: App\Document\SonataMediaMedia + user: App\Document\SonataUserUser + tag: App\Document\SonataClassificationTag + collection: App\Document\SonataClassificationCollection Add SonataNewsBundle routes --------------------------- @@ -195,3 +207,18 @@ Add SonataNewsBundle routes news: resource: '@SonataNewsBundle/Resources/config/routing/news.xml' prefix: /news + +Next Steps +---------- + +At this point, your Symfony installation should be fully functional, without errors +showing up from SonataNewsBundle. If, at this point or during the installation, +you come across any errors, don't panic: + + - Read the error message carefully. Try to find out exactly which bundle is causing the error. + Is it SonataNewsBundle or one of the dependencies? + - Make sure you followed all the instructions correctly, for both SonataNewsBundle and its dependencies. + - Still no luck? Try checking the project's `open issues on GitHub`_. + +.. _`open issues on GitHub`: https://github.com/sonata-project/SonataNewsBundle/issues +.. _`auto_mapping`: http://symfony.com/doc/4.4/reference/configuration/doctrine.html#configuration-overviews diff --git a/src/DependencyInjection/SonataNewsExtension.php b/src/DependencyInjection/SonataNewsExtension.php index 9f7064ef..e895a8d0 100644 --- a/src/DependencyInjection/SonataNewsExtension.php +++ b/src/DependencyInjection/SonataNewsExtension.php @@ -13,7 +13,9 @@ namespace Sonata\NewsBundle\DependencyInjection; -use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector; +use Sonata\Doctrine\Mapper\Builder\OptionsBuilder; +use Sonata\Doctrine\Mapper\DoctrineCollector; +use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector as DeprecatedDoctrineCollector; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -98,7 +100,12 @@ public function load(array $configs, ContainerBuilder $container) ]); if ('doctrine_orm' === $config['db_driver']) { - $this->registerDoctrineMapping($config); + if (isset($bundles['SonataDoctrineBundle'])) { + $this->registerSonataDoctrineMapping($config); + } else { + // NEXT MAJOR: Remove next line and throw error when not registering SonataDoctrineBundle + $this->registerDoctrineMapping($config); + } } $this->configureClass($config, $container); @@ -133,9 +140,17 @@ public function configureAdmin($config, ContainerBuilder $container) $container->setParameter('sonata.news.admin.comment.translation_domain', $config['admin']['comment']['translation']); } + /** + * NEXT_MAJOR: Remove this method. + */ public function registerDoctrineMapping(array $config) { - $collector = DoctrineCollector::getInstance(); + @trigger_error( + 'Using SonataEasyExtendsBundle is deprecated since sonata-project/news-bundle 3.x. Please register SonataDoctrineBundle as a bundle instead.', + E_USER_DEPRECATED + ); + + $collector = DeprecatedDoctrineCollector::getInstance(); foreach ($config['class'] as $type => $class) { if (!class_exists($class)) { @@ -261,4 +276,84 @@ public function registerDoctrineMapping(array $config) 'orphanRemoval' => false, ]); } + + private function registerSonataDoctrineMapping(array $config): void + { + foreach ($config['class'] as $type => $class) { + if (!class_exists($class)) { + return; + } + } + + $collector = DoctrineCollector::getInstance(); + + $collector->addAssociation( + $config['class']['post'], + 'mapOneToMany', + OptionsBuilder::createOneToMany('comments', $config['class']['comment']) + ->cascade(['remove', 'persist']) + ->mappedBy('post') + ->orphanRemoval() + ->addOrder('createdAt', 'DESC') + ); + + $collector->addAssociation( + $config['class']['post'], + 'mapManyToOne', + OptionsBuilder::createManyToOne('image', $config['class']['media']) + ->cascade(['remove', 'persist', 'refresh', 'merge', 'detach']) + ->addJoin([ + 'name' => 'image_id', + 'referencedColumnName' => 'id', + ]) + ); + + $collector->addAssociation( + $config['class']['post'], + 'mapManyToOne', + OptionsBuilder::createManyToOne('author', $config['class']['user']) + ->cascade(['persist']) + ->addJoin([ + 'name' => 'author_id', + 'referencedColumnName' => 'id', + ]) + ); + + $collector->addAssociation( + $config['class']['post'], + 'mapManyToOne', + OptionsBuilder::createManyToOne('collection', $config['class']['collection']) + ->cascade(['persist']) + ->addJoin([ + 'name' => 'collection_id', + 'referencedColumnName' => 'id', + ]) + ); + + $collector->addAssociation( + $config['class']['post'], + 'mapManyToMany', + OptionsBuilder::createManyToMany('tags', $config['class']['tag']) + ->cascade(['persist']) + ->addJoinTable($config['table']['post_tag'], [[ + 'name' => 'post_id', + 'referencedColumnName' => 'id', + ]], [[ + 'name' => 'tag_id', + 'referencedColumnName' => 'id', + ]]) + ); + + $collector->addAssociation( + $config['class']['comment'], + 'mapManyToOne', + OptionsBuilder::createManyToOne('post', $config['class']['post']) + ->inversedBy('comments') + ->addJoin([ + 'name' => 'post_id', + 'referencedColumnName' => 'id', + 'nullable' => false, + ]) + ); + } } diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index 69a7dd9a..31ff9f6b 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -18,7 +18,7 @@ use Knp\Bundle\MenuBundle\KnpMenuBundle; use Sonata\BlockBundle\SonataBlockBundle; use Sonata\ClassificationBundle\SonataClassificationBundle; -use Sonata\Doctrine\Bridge\Symfony\Bundle\SonataDoctrineBundle; +use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle; use Sonata\Form\Bridge\Symfony\SonataFormBundle; use Sonata\IntlBundle\SonataIntlBundle; use Sonata\MediaBundle\SonataMediaBundle; diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 281c1d66..0958dbe5 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -11,25 +11,63 @@ * file that was distributed with this source code. */ -namespace Sonata\NewsBundle\Tests; +namespace Sonata\NewsBundle\Tests\DependencyInjection; -use PHPUnit\Framework\TestCase; +use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase; use Sonata\NewsBundle\DependencyInjection\Configuration; -use Symfony\Component\Config\Definition\Processor; +use Sonata\NewsBundle\DependencyInjection\SonataNewsExtension; +use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; -class ConfigurationTest extends TestCase +final class ConfigurationTest extends AbstractExtensionConfigurationTestCase { - public function testOptions() + public function testDefault(): void { - $processor = new Processor(); - - $config = $processor->processConfiguration(new Configuration(), [[ + $this->assertProcessedConfigurationEquals([ 'title' => 'Foo title', 'link' => '/foo/bar', 'description' => 'Foo description', 'salt' => 'pepper', - ]]); + 'permalink_generator' => 'sonata.news.permalink.date', + 'permalink' => [ + 'date' => '%%1$04d/%%2$d/%%3$d/%%4$s', + ], + 'db_driver' => 'doctrine_orm', + 'table' => [ + 'post_tag' => 'news__post_tag', + ], + 'class' => [ + 'tag' => 'Application\Sonata\ClassificationBundle\Entity\Tag', + 'collection' => 'Application\Sonata\ClassificationBundle\Entity\Collection', + 'post' => 'Application\Sonata\NewsBundle\Entity\Post', + 'comment' => 'Application\Sonata\NewsBundle\Entity\Comment', + 'media' => 'Application\Sonata\MediaBundle\Entity\Media', + 'user' => 'Application\Sonata\UserBundle\Entity\User', + ], + 'admin' => [ + 'post' => [ + 'class' => 'Sonata\NewsBundle\Admin\PostAdmin', + 'controller' => 'SonataAdminBundle:CRUD', + 'translation' => 'SonataNewsBundle', + ], + 'comment' => [ + 'class' => 'Sonata\NewsBundle\Admin\CommentAdmin', + 'controller' => 'SonataNewsBundle:CommentAdmin', + 'translation' => 'SonataNewsBundle', + ], + ], + ], [ + __DIR__.'/../Fixtures/configuration.yaml', + ]); + } + + protected function getContainerExtension(): ExtensionInterface + { + return new SonataNewsExtension(); + } - $this->assertSame('news__post_tag', $config['table']['post_tag']); + protected function getConfiguration(): ConfigurationInterface + { + return new Configuration(); } } diff --git a/tests/DependencyInjection/SonataNewsExtensionTest.php b/tests/DependencyInjection/SonataNewsExtensionTest.php index cc4180bf..e14d852e 100644 --- a/tests/DependencyInjection/SonataNewsExtensionTest.php +++ b/tests/DependencyInjection/SonataNewsExtensionTest.php @@ -16,7 +16,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Sonata\ClassificationBundle\Model\Collection; use Sonata\ClassificationBundle\Model\Tag; -use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector; +use Sonata\Doctrine\Mapper\DoctrineCollector; use Sonata\MediaBundle\Model\Media; use Sonata\NewsBundle\DependencyInjection\SonataNewsExtension; use Sonata\NewsBundle\Model\Comment; @@ -28,31 +28,9 @@ class SonataNewsExtensionTest extends AbstractExtensionTestCase protected function setUp(): void { parent::setUp(); - $this->container->setParameter('kernel.bundles', []); + $this->container->setParameter('kernel.bundles', ['SonataDoctrineBundle' => true]); } - /** - * Test if the deprecation notice is triggered when the tag (or collection) class declaration is missing. - * It should trigger a deprecation notice but doesn't break anything - * You should have 0 association. - * - * @group legacy - * @expectedDeprecation The %s class is not defined or does not exist. This is tolerated now but will be forbidden in 4.0 - */ - public function testLoadWithoutTagWithoutCollection(): void - { - $this->load($this->getMinimalConfiguration()); - $collector = DoctrineCollector::getInstance(); - - $this->assertEmpty($collector->getAssociations(), 'Our models should have 0 association'); - } - - /** - * Test if the deprecation notice is triggered when the tag (or collection) class declaration is present. - * It shouldn't trigger a deprecation notice but doesn't break anything - * You should have 2 associations (Post, Comment). - * The Post model should have an association with (Media, User, Collection, Tag). - */ public function testLoadWithTagWithCollection(): void { $this->load($this->getConfigurationWithTagWithCollection()); @@ -66,40 +44,29 @@ public function testLoadWithTagWithCollection(): void $this->assertCount(1, $postOneToManyAssociation, 'The post model should have 1 one to many association (comment)'); } - protected function getMinimalConfiguration(): array - { - return [ - 'title' => 'Foo title', - 'link' => '/foo/bar', - 'description' => 'Foo description', - 'salt' => 'pepper', - 'comment' => [ - 'notification' => [ - 'emails' => ['email@example.org', 'email2@example.org'], - 'from' => 'no-reply@sonata-project.org', - 'template' => '@SonataNews/Mail/comment_notification.txt.twig', - ], - ], - 'class' => [ - 'post' => Post::class, - 'comment' => Comment::class, - 'media' => Media::class, - 'user' => UserMock::class, - ], - ]; - } - protected function getConfigurationWithTagWithCollection(): array { - $minimalConfiguration = $this->getMinimalConfiguration(); - $tagAndCollectionDeclaration = [ - 'class' => [ - 'collection' => Collection::class, - 'tag' => Tag::class, + return [ + 'title' => 'Foo title', + 'link' => '/foo/bar', + 'description' => 'Foo description', + 'salt' => 'pepper', + 'comment' => [ + 'notification' => [ + 'emails' => ['email@example.org', 'email2@example.org'], + 'from' => 'no-reply@sonata-project.org', + 'template' => '@SonataNews/Mail/comment_notification.txt.twig', ], - ]; - - return array_merge($minimalConfiguration, $tagAndCollectionDeclaration); + ], + 'class' => [ + 'post' => Post::class, + 'comment' => Comment::class, + 'media' => Media::class, + 'user' => UserMock::class, + 'collection' => Collection::class, + 'tag' => Tag::class, + ], + ]; } protected function getContainerExtensions(): array diff --git a/tests/Fixtures/configuration.yaml b/tests/Fixtures/configuration.yaml new file mode 100644 index 00000000..6655c643 --- /dev/null +++ b/tests/Fixtures/configuration.yaml @@ -0,0 +1,5 @@ +sonata_news: + title: Foo title + link: /foo/bar + description: Foo description + salt: pepper