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 Sep 4, 2022
2 parents 4aee6c9 + 9946d8a commit ee93382
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 63 deletions.
7 changes: 6 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'ordered_class_elements' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha', 'imports_order' => ['class', 'function', 'const']],
'phpdoc_order' => ['order' => ['var', 'param', 'throws', 'return', 'phpstan-var', 'psalm-var', 'phpstan-param', 'psalm-param', 'phpstan-return', 'psalm-return']],
'phpdoc_separation' => ['groups' => [
['phpstan-template', 'phpstan-template-covariant', 'phpstan-extends', 'phpstan-implements', 'phpstan-var', 'psalm-var', 'phpstan-param', 'psalm-param', 'phpstan-return', 'psalm-return'],
['psalm-suppress', 'phpstan-ignore-next-line'],
]],
'php_unit_strict' => true,
'php_unit_test_case_static_method_calls' => true,
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress']],
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress', 'phpstan-var']],
'single_line_throw' => false,
'static_lambda' => true,
'strict_comparison' => true,
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.5.1](https://github.com/sonata-project/SonataMediaBundle/compare/4.5.0...4.5.1) - 2022-08-31
### Fixed
- [[#2333](https://github.com/sonata-project/SonataMediaBundle/pull/2333)] Allow CloudFront to compress files passing ContentLength in the headers. ([@dmitryuk](https://github.com/dmitryuk))

## [4.5.0](https://github.com/sonata-project/SonataMediaBundle/compare/4.4.0...4.5.0) - 2022-08-04
### Added
- [[#2326](https://github.com/sonata-project/SonataMediaBundle/pull/2326)] Support for sonata-project/doctrine-extensions ^2 ([@VincentLanglet](https://github.com/VincentLanglet))
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ set_time_limit(0);

require dirname(__DIR__) . '/vendor/autoload.php';

$kernel = new AppKernel();
$kernel = new AppKernel('test', false);
$application = new Application($kernel);
$application->run(new ArgvInput());
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"sonata-project/classification-bundle": "^4.0",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.0",
"symfony/filesystem": "^4.4 || ^5.4 || ^6.0",
"symfony/messenger": "^4.4 || ^5.4 || ^6.0",
"symfony/phpunit-bridge": "^6.1",
"symfony/security-csrf": "^4.4 || ^5.4 || ^6.0",
Expand Down
2 changes: 1 addition & 1 deletion phpstan-console-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

require __DIR__.'/vendor/autoload.php';

$kernel = new AppKernel();
$kernel = new AppKernel('test', false);

return new Application($kernel);
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ It's auto-generated by sonata-project/dev-kit package.
<php>
<ini name="precision" value="8" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
<env name="KERNEL_CLASS" value="\Sonata\MediaBundle\Tests\App\AppKernel" />
<server name="APP_ENV" value="test" force="true" />
<server name="APP_DEBUG" value="false" />
</php>
</phpunit>
1 change: 0 additions & 1 deletion src/Block/GalleryBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ private function getGalleryBuilder(): FormBuilderInterface
* @return array<string, MediaInterface|string|null>
*
* @phpstan-param GalleryInterface<GalleryItemInterface> $gallery
*
* @phpstan-return array{
* title: string|null,
* caption: string|null,
Expand Down
18 changes: 17 additions & 1 deletion src/Metadata/AmazonMetadataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function get(MediaInterface $media, string $filename): array
{
return array_replace_recursive(
$this->getDefaultMetadata(),
$this->getContentType($filename)
$this->getContentType($filename),
$this->getContentLength($media)
);
}

Expand Down Expand Up @@ -124,4 +125,19 @@ private function getContentType(string $filename): array

return ['contentType' => $mimeType];
}

/**
* @return array<string, int>
*
* @phpstan-return array{contentLength?: int}
*/
private function getContentLength(MediaInterface $media): array
{
$size = $media->getSize();
if ($size > 0) {
return ['contentLength' => $size];
}

return [];
}
}
10 changes: 0 additions & 10 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,10 @@
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Security\Http\Authentication\AuthenticatorManager;

/**
* @psalm-suppress PropertyNotSetInConstructor
*
* @see https://github.com/psalm/psalm-plugin-symfony/pull/220
*/
final class AppKernel extends Kernel
{
use MicroKernelTrait;

public function __construct()
{
parent::__construct('test', false);
}

public function registerBundles(): iterable
{
return [
Expand Down
10 changes: 0 additions & 10 deletions tests/Functional/Admin/GalleryAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

use Doctrine\ORM\EntityManagerInterface;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Tests\App\AppKernel;
use Sonata\MediaBundle\Tests\App\Entity\Gallery;
use Sonata\MediaBundle\Tests\App\Entity\GalleryItem;
use Sonata\MediaBundle\Tests\App\Entity\Media;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class GalleryAdminTest extends WebTestCase
{
Expand Down Expand Up @@ -87,14 +85,6 @@ public static function provideFormUrlsCases(): iterable
yield 'Remove Gallery' => ['/admin/tests/app/gallery/1/delete', [], 'btn_delete'];
}

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

/**
* @psalm-suppress UndefinedPropertyFetch
*/
Expand Down
10 changes: 0 additions & 10 deletions tests/Functional/Admin/GalleryItemAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

use Doctrine\ORM\EntityManagerInterface;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Tests\App\AppKernel;
use Sonata\MediaBundle\Tests\App\Entity\Gallery;
use Sonata\MediaBundle\Tests\App\Entity\GalleryItem;
use Sonata\MediaBundle\Tests\App\Entity\Media;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class GalleryItemAdminTest extends WebTestCase
{
Expand Down Expand Up @@ -87,14 +85,6 @@ public static function provideFormUrlsCases(): iterable
yield 'Remove Gallery Item' => ['/admin/tests/app/galleryitem/1/delete', [], 'btn_delete'];
}

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

/**
* @psalm-suppress UndefinedPropertyFetch
*/
Expand Down
10 changes: 0 additions & 10 deletions tests/Functional/Admin/MediaAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@

use Doctrine\ORM\EntityManagerInterface;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Tests\App\AppKernel;
use Sonata\MediaBundle\Tests\App\Entity\Media;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class MediaAdminTest extends WebTestCase
{
Expand Down Expand Up @@ -138,14 +136,6 @@ public static function provideFormUrlsCases(): iterable
yield 'Remove Media' => ['/admin/tests/app/media/1/delete', [], 'btn_delete'];
}

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

/**
* @psalm-suppress UndefinedPropertyFetch
*/
Expand Down
10 changes: 0 additions & 10 deletions tests/Functional/Command/AddMediaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

namespace Sonata\MediaBundle\Tests\Functional\Command;

use Sonata\MediaBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

final class AddMediaCommandTest extends KernelTestCase
{
Expand All @@ -42,12 +40,4 @@ public function testAddsMedia(): void

static::assertStringContainsString('done!', $this->commandTester->getDisplay());
}

/**
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
return AppKernel::class;
}
}
8 changes: 3 additions & 5 deletions tests/Functional/Controller/TruncateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@

namespace Sonata\MediaBundle\Tests\Functional\Controller;

use PHPUnit\Framework\TestCase;
use Sonata\MediaBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class TruncateControllerTest extends TestCase
final class TruncateControllerTest extends WebTestCase
{
/**
* @requires extension gd
*/
public function testTruncate(): void
{
$client = new KernelBrowser(new AppKernel());
$client = static::createClient();
$client->request(Request::METHOD_GET, '/u_truncate_test');

static::assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());
Expand Down
22 changes: 20 additions & 2 deletions tests/Metadata/AmazonMetadataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ final class AmazonMetadataBuilderTest extends TestCase
/**
* @dataProvider provider
*
* @param array<string, mixed> $expected
* @param array<string, string|int> $mediaAttributes
* @param array<string, mixed> $expected
*
* @phpstan-param AmazonSettings $settings
*/
public function testAmazon(array $settings, array $expected): void
public function testAmazon(array $settings, array $mediaAttributes, array $expected): void
{
$mimeTypes = $this->createStub(MimeTypesInterface::class);
$mimeTypes->method('getMimeTypes')->willReturnCallback(
static fn (string $ext): array => 'png' === $ext ? ['image/png'] : []
);

$media = $this->createStub(MediaInterface::class);
foreach ($mediaAttributes as $attribute => $value) {
$media->method('get'.ucfirst($attribute))->willReturn($value);
}
$filename = '/test/folder/testfile.png';

$amazonmetadatabuilder = new AmazonMetadataBuilder($settings, $mimeTypes);
Expand All @@ -57,13 +61,17 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => [],
],
[
'size' => 3000,
],
[
'ACL' => AmazonMetadataBuilder::PRIVATE_ACCESS,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
'meta' => [],
'CacheControl' => '',
'encryption' => 'AES256',
'contentType' => 'image/png',
'contentLength' => 3000,
],
];

Expand All @@ -75,6 +83,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ_WRITE,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -93,6 +102,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::AUTHENTICATED_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -111,6 +121,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::BUCKET_OWNER_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -129,6 +140,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::BUCKET_OWNER_FULL_CONTROL,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -147,6 +159,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ,
'storage' => AmazonMetadataBuilder::STORAGE_REDUCED,
Expand All @@ -165,6 +178,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -183,6 +197,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -201,6 +216,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -219,6 +235,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand All @@ -237,6 +254,7 @@ public function provider(): iterable
'encryption' => 'aes256',
'meta' => ['key' => 'value'],
],
[],
[
'ACL' => AmazonMetadataBuilder::PUBLIC_READ,
'storage' => AmazonMetadataBuilder::STORAGE_STANDARD,
Expand Down
6 changes: 5 additions & 1 deletion tests/custom_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Filesystem\Filesystem;

$application = new Application(new AppKernel());
$kernel = new AppKernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->setAutoExit(false);

$input = new ArrayInput([
Expand All @@ -35,3 +37,5 @@
'command' => 'doctrine:schema:create',
]);
$application->run($input, new NullOutput());

(new Filesystem())->remove([$kernel->getCacheDir()]);

0 comments on commit ee93382

Please sign in to comment.