Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Nov 28, 2021
2 parents 7f70ae5 + b7c8483 commit 4617b60
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ jobs:
allowed-to-fail: false
symfony-require: 5.4.*
variant: symfony/symfony:"5.4.*"
- php-version: '8.0'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.0.*
variant: symfony/symfony:"6.0.*"

steps:
- name: Checkout
Expand Down
50 changes: 25 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@
"sonata-project/doctrine-extensions": "^1.13",
"sonata-project/form-extensions": "^1.4",
"sonata-project/twig-extensions": "^1.3",
"symfony/asset": "^4.4 || ^5.3",
"symfony/config": "^4.4.11 || ^5.3",
"symfony/console": "^4.4 || ^5.3",
"symfony/dependency-injection": "^4.4.8 || ^5.3",
"symfony/event-dispatcher": "^4.4 || ^5.3",
"symfony/filesystem": "^4.4 || ^5.3",
"symfony/finder": "^4.4 || ^5.3",
"symfony/form": "^4.4.12 || ^5.3",
"symfony/framework-bundle": "^4.4.6 || ^5.3",
"symfony/http-client": "^4.4 || ^5.3",
"symfony/http-foundation": "^4.4 || ^5.3",
"symfony/http-kernel": "^4.4 || ^5.3",
"symfony/mime": "^4.4 || ^5.3",
"symfony/options-resolver": "^4.4 || ^5.3",
"symfony/routing": "^4.4 || ^5.3",
"symfony/security-bundle": "^4.4 || ^5.3",
"symfony/security-core": "^4.4.24 || ^5.3",
"symfony/translation": "^4.4 || ^5.3",
"symfony/asset": "^4.4 || ^5.3 || ^6.0",
"symfony/config": "^4.4.11 || ^5.3 || ^6.0",
"symfony/console": "^4.4 || ^5.3 || ^6.0",
"symfony/dependency-injection": "^4.4.8 || ^5.3 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.3 || ^6.0",
"symfony/filesystem": "^4.4 || ^5.3 || ^6.0",
"symfony/finder": "^4.4 || ^5.3 || ^6.0",
"symfony/form": "^4.4.12 || ^5.3 || ^6.0",
"symfony/framework-bundle": "^4.4.6 || ^5.3 || ^6.0",
"symfony/http-client": "^4.4 || ^5.3 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.3 || ^6.0",
"symfony/mime": "^4.4 || ^5.3 || ^6.0",
"symfony/options-resolver": "^4.4 || ^5.3 || ^6.0",
"symfony/routing": "^4.4 || ^5.3 || ^6.0",
"symfony/security-bundle": "^4.4 || ^5.3 || ^6.0",
"symfony/security-core": "^4.4.24 || ^5.3 || ^6.0",
"symfony/translation": "^4.4 || ^5.3 || ^6.0",
"symfony/translation-contracts": "^1.1 || ^2.0",
"symfony/twig-bridge": "^4.4 || ^5.3",
"symfony/twig-bundle": "^4.4 || ^5.3",
"symfony/validator": "^4.4 || ^5.3",
"symfony/twig-bridge": "^4.4 || ^5.3 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.3 || ^6.0",
"symfony/validator": "^4.4 || ^5.3 || ^6.0",
"twig/string-extra": "^3.0",
"twig/twig": "^2.14 || ^3.0"
},
Expand Down Expand Up @@ -96,10 +96,10 @@
"sonata-project/block-bundle": "^4.0",
"sonata-project/classification-bundle": "^4.0.0-RC1",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.3",
"symfony/messenger": "^4.4 || ^5.3",
"symfony/phpunit-bridge": "^5.3",
"symfony/security-csrf": "^4.4 || ^5.3",
"symfony/browser-kit": "^4.4 || ^5.3 || ^6.0",
"symfony/messenger": "^4.4 || ^5.3 || ^6.0",
"symfony/phpunit-bridge": "^5.3 || ^6.0",
"symfony/security-csrf": "^4.4 || ^5.3 || ^6.0",
"vimeo/psalm": "^4.7.2"
},
"suggest": {
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ private function addModelSection(ArrayNodeDefinition $node): void
->arrayNode('class')
->addDefaultsIfNotSet()
->children()
->scalarNode('media')->defaultValue('Application\\Sonata\\MediaBundle\\Entity\\Media')->end()
->scalarNode('gallery')->defaultValue('Application\\Sonata\\MediaBundle\\Entity\\Gallery')->end()
->scalarNode('gallery_item')->defaultValue('Application\\Sonata\\MediaBundle\\Entity\\GalleryItem')->end()
->scalarNode('category')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Category')->end()
->scalarNode('media')->defaultValue('App\\Entity\\SonataMediaMedia')->end()
->scalarNode('gallery')->defaultValue('App\\Entity\\SonataMediaGallery')->end()
->scalarNode('gallery_item')->defaultValue('App\\Entity\\SonataMediaGalleryItem')->end()
->scalarNode('category')->defaultValue('App\\Entity\\SonataClassificationCategory')->end()
->end()
->end()
->end();
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ final public function getDefaultFormat(): string
return $this->defaultFormat;
}

final public function setGalleryItems(Collection $galleryItems): void
final public function setGalleryItems(iterable $galleryItems): void
{
$this->galleryItems = new ArrayCollection();
$this->galleryItems->clear();

foreach ($galleryItems as $galleryItem) {
$this->addGalleryItem($galleryItem);
Expand Down Expand Up @@ -150,6 +150,6 @@ final public function reorderGalleryItems(): void
return $a->getPosition() <=> $b->getPosition();
});

$this->setGalleryItems(new ArrayCollection(iterator_to_array($iterator)));
$this->setGalleryItems($iterator);
}
}
4 changes: 2 additions & 2 deletions src/Model/GalleryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function setDefaultFormat(string $defaultFormat): void;
public function getDefaultFormat(): string;

/**
* @param Collection<int, GalleryItemInterface> $galleryItems
* @param iterable<int, GalleryItemInterface> $galleryItems
*/
public function setGalleryItems(Collection $galleryItems): void;
public function setGalleryItems(iterable $galleryItems): void;

/**
* @return Collection<int, GalleryItemInterface>
Expand Down
8 changes: 6 additions & 2 deletions src/Model/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ final public function setCategory(?object $category = null): void
$this->category = $category;
}

final public function setGalleryItems(Collection $galleryItems): void
final public function setGalleryItems(iterable $galleryItems): void
{
$this->galleryItems = $galleryItems;
$this->galleryItems->clear();

foreach ($galleryItems as $galleryItem) {
$this->galleryItems->add($galleryItem);
}
}

final public function getGalleryItems(): Collection
Expand Down
4 changes: 2 additions & 2 deletions src/Model/MediaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public function getCategory(): ?object;
public function setCategory(?object $category = null): void;

/**
* @param Collection<int, GalleryItemInterface> $galleryItems
* @param iterable<int, GalleryItemInterface> $galleryItems
*/
public function setGalleryItems(Collection $galleryItems): void;
public function setGalleryItems(iterable $galleryItems): void;

/**
* @return Collection<int, GalleryItemInterface>
Expand Down
3 changes: 1 addition & 2 deletions src/Resources/config/doctrine_mongodb_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* file that was distributed with this source code.
*/

use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\MediaBundle\Admin\GalleryAdmin;
use Sonata\MediaBundle\Admin\GalleryItemAdmin;
use Sonata\MediaBundle\Admin\ODM\MediaAdmin;
Expand Down Expand Up @@ -84,7 +83,7 @@
->args([
'',
'%sonata.media.admin.gallery_item.entity%',
CRUDController::class,
'%sonata.admin.configuration.default_controller%',
])
->call('setTranslationDomain', ['SonataMediaBundle']);
};
3 changes: 1 addition & 2 deletions src/Resources/config/doctrine_orm_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* file that was distributed with this source code.
*/

use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\MediaBundle\Admin\GalleryAdmin;
use Sonata\MediaBundle\Admin\GalleryItemAdmin;
use Sonata\MediaBundle\Admin\ORM\MediaAdmin;
Expand Down Expand Up @@ -85,7 +84,7 @@
->args([
'',
'%sonata.media.admin.gallery_item.entity%',
CRUDController::class,
'%sonata.admin.configuration.default_controller%',
])
->call('setTranslationDomain', ['SonataMediaBundle']);
};
4 changes: 4 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
use Sonata\MediaBundle\SonataMediaBundle;
use Sonata\Twig\Bridge\Symfony\SonataTwigBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
Expand Down Expand Up @@ -52,6 +53,7 @@ public function registerBundles(): iterable
new FrameworkBundle(),
new KnpMenuBundle(),
new SecurityBundle(),
new SonataTwigBundle(),
new SonataAdminBundle(),
new SonataBlockBundle(),
new SonataDoctrineBundle(),
Expand Down Expand Up @@ -100,6 +102,8 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa

if (class_exists(AuthenticatorManager::class)) {
$loader->load(__DIR__.'/Resources/config/config_symfony_v5.yml');
} else {
$loader->load(__DIR__.'/Resources/config/config_symfony_v4.yml');
}

$loader->load(__DIR__.'/Resources/config/services.php');
Expand Down
3 changes: 3 additions & 0 deletions tests/App/Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ sonata_media:
default_context: default
contexts:
default:
download:
strategy: sonata.media.security.public_strategy
mode: X-Sendfile
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
Expand Down
3 changes: 3 additions & 0 deletions tests/App/Resources/config/config_symfony_v4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
session:
storage_id: session.storage.mock_file
4 changes: 4 additions & 0 deletions tests/App/Resources/config/config_symfony_v5.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
security:
enable_authenticator_manager: true

framework:
session:
storage_factory_id: session.storage.factory.mock_file
13 changes: 13 additions & 0 deletions tests/App/Resources/config/routing/routes.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
test_page:
path: /u_truncate_test
controller: Sonata\MediaBundle\Tests\App\Controller\TruncateController::test

admin_area:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin

_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin

media:
resource: '@SonataMediaBundle/Resources/config/routing/media.xml'
prefix: /media
72 changes: 72 additions & 0 deletions tests/Functional/Admin/GalleryAdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\ClassificationBundle\Tests\App\Action;

use Doctrine\ORM\EntityManagerInterface;
use Sonata\MediaBundle\Tests\App\AppKernel;
use Sonata\MediaBundle\Tests\App\Entity\Gallery;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class GalleryAdminTest extends WebTestCase
{
/**
* @dataProvider provideCrudUrlsCases
*/
public function testCrudUrls(string $url): void
{
$client = self::createClient();

$this->prepareData();

$client->request('GET', $url);

self::assertResponseIsSuccessful();
}

/**
* @return iterable<string[]>
*
* @phpstan-return iterable<array{string}>
*/
public static function provideCrudUrlsCases(): iterable
{
yield 'List Gallery' => ['/admin/tests/app/gallery/list'];
yield 'Create Gallery' => ['/admin/tests/app/gallery/create'];
yield 'Edit Gallery' => ['/admin/tests/app/gallery/1/edit'];
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
*/
protected static function getKernelClass(): string
{
return AppKernel::class;
}

private function prepareData(): void
{
// TODO: Simplify this when dropping support for Symfony 4.
// @phpstan-ignore-next-line
$container = method_exists($this, 'getContainer') ? self::getContainer() : self::$container;
$manager = $container->get('doctrine.orm.entity_manager');
\assert($manager instanceof EntityManagerInterface);

$gallery = new Gallery();
$gallery->setName('name');
$gallery->setContext('default');

$manager->persist($gallery);
$manager->flush();
}
}

0 comments on commit 4617b60

Please sign in to comment.