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 authored Feb 22, 2025
2 parents cd1a5fe + d2d7fae commit edd9e02
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 111 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^1.1",
"sonata-project/admin-bundle": "^4.34",
"sonata-project/admin-bundle": "^4.35.4",
"sonata-project/block-bundle": "^4.11 || ^5.0",
"sonata-project/classification-bundle": "^4.0",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/Admin/BaseMediaAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function setUp(): void
$this->categoryManager = $this->createMock(CategoryManagerInterface::class);
$this->contextManager = $this->createMock(ContextManagerInterface::class);
$this->request = new Request();
$this->modelManager = $this->createStub(ModelManagerInterface::class);
$this->modelManager = static::createStub(ModelManagerInterface::class);

$this->mediaAdmin = new TestMediaAdmin(
$this->pool,
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testGetPersistentParametersWithMultipleProvidersInContext(): voi

$context = new Context();

$provider = $this->createStub(MediaProviderInterface::class);
$provider = static::createStub(MediaProviderInterface::class);

$this->request->setMethod('POST');
$this->request->query->set('filter', []);
Expand All @@ -122,7 +122,7 @@ public function testGetPersistentParametersWithMultipleProvidersInContext(): voi

private function configureGetPersistentParameters(): void
{
$provider = $this->createStub(MediaProviderInterface::class);
$provider = static::createStub(MediaProviderInterface::class);
$category = new Category();
$category->setId(1);

Expand Down
2 changes: 1 addition & 1 deletion tests/Admin/ORM/MediaAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void
{
$this->mediaAdmin = new MediaAdmin(
new Pool('default'),
$this->createStub(CategoryManagerInterface::class)
static::createStub(CategoryManagerInterface::class)
);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\UX\StimulusBundle\StimulusBundle;

final class AppKernel extends Kernel
{
Expand All @@ -44,6 +45,7 @@ public function registerBundles(): iterable
new DoctrineBundle(),
new DAMADoctrineTestBundle(),
new FrameworkBundle(),
new StimulusBundle(),
new KnpMenuBundle(),
new SecurityBundle(),
new SonataFormBundle(),
Expand Down
4 changes: 2 additions & 2 deletions tests/Block/FeatureMediaBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ protected function setUp(): void
parent::setUp();

/** @var AdminInterface<MediaInterface>&Stub $mediaAdmin */
$mediaAdmin = $this->createStub(AdminInterface::class);
$mediaAdmin = static::createStub(AdminInterface::class);

$this->blockService = new FeatureMediaBlockService(
$this->twig,
new Pool('default'),
$mediaAdmin,
$this->createStub(MediaManagerInterface::class)
static::createStub(MediaManagerInterface::class)
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Block/GalleryBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ protected function setUp(): void
parent::setUp();

/** @var AdminInterface<GalleryInterface<GalleryItemInterface>>&Stub $galleryAdmin */
$galleryAdmin = $this->createStub(AdminInterface::class);
$galleryAdmin = static::createStub(AdminInterface::class);

$this->blockService = new GalleryBlockService(
$this->twig,
new Pool('default'),
$galleryAdmin,
$this->createStub(GalleryManagerInterface::class)
static::createStub(GalleryManagerInterface::class)
);
}

public function testExecute(): void
{
$block = $this->createMock(Block::class);
$gallery = $this->createStub(GalleryInterface::class);
$blockContext = $this->createStub(BlockContextInterface::class);
$gallery = static::createStub(GalleryInterface::class);
$blockContext = static::createStub(BlockContextInterface::class);

$blockContext->method('getBlock')->willReturn($block);
$blockContext->method('getSettings')->willReturn(['settings']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Block/MediaBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ protected function setUp(): void
$this->pool = new Pool('default');

/** @var AdminInterface<MediaInterface>&Stub $mediaAdmin */
$mediaAdmin = $this->createStub(AdminInterface::class);
$mediaAdmin = static::createStub(AdminInterface::class);

$this->blockService = new MediaBlockService(
$this->twig,
$this->pool,
$mediaAdmin,
$this->createStub(MediaManagerInterface::class)
static::createStub(MediaManagerInterface::class)
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Command/CleanMediaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ protected function setUp(): void
$this->fileSystemLocal = new Local($this->workspace);
$this->provider = new FileProvider(
'fooprovider',
$this->createStub(Filesystem::class),
$this->createStub(CDNInterface::class),
$this->createStub(GeneratorInterface::class),
$this->createStub(ThumbnailInterface::class)
static::createStub(Filesystem::class),
static::createStub(CDNInterface::class),
static::createStub(GeneratorInterface::class),
static::createStub(ThumbnailInterface::class)
);

$this->command = new CleanMediaCommand($this->fileSystemLocal, $this->pool, $this->mediaManager);
Expand Down
14 changes: 7 additions & 7 deletions tests/Controller/GalleryAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected function setUp(): void
public function testListAction(): void
{
$datagrid = $this->createMock(DatagridInterface::class);
$form = $this->createStub(Form::class);
$formView = $this->createStub(FormView::class);
$form = static::createStub(Form::class);
$formView = static::createStub(FormView::class);
$pool = new Pool('default');

$this->configureSetFormTheme($formView, ['filterTheme']);
Expand All @@ -99,8 +99,8 @@ private function configureCRUDController(): void
'admin_code' => 'admin_code',
]);
$adminFetcher = new AdminFetcher($pool);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$mutableTemplateRegistry = $this->createStub(MutableTemplateRegistryInterface::class);
$templateRegistry = static::createStub(TemplateRegistryInterface::class);
$mutableTemplateRegistry = static::createStub(MutableTemplateRegistryInterface::class);

$mutableTemplateRegistry->method('getTemplate')->willReturnMap([
['layout', 'layout.html.twig'],
Expand All @@ -127,7 +127,7 @@ private function configureCRUDController(): void

private function configureGetCurrentRequest(Request $request): void
{
$requestStack = $this->createStub(RequestStack::class);
$requestStack = static::createStub(RequestStack::class);

$this->container->set('request_stack', $requestStack);
$requestStack->method('getCurrentRequest')->willReturn($request);
Expand All @@ -136,7 +136,7 @@ private function configureGetCurrentRequest(Request $request): void
private function configureSetCsrfToken(string $intention): void
{
$tokenManager = $this->createMock(CsrfTokenManagerInterface::class);
$token = $this->createStub(CsrfToken::class);
$token = static::createStub(CsrfToken::class);

$tokenManager->method('getToken')->with($intention)->willReturn($token);
$token->method('getValue')->willReturn('token');
Expand All @@ -156,7 +156,7 @@ private function configureSetFormTheme(FormView $formView, array $formTheme): vo

private function configureRender(string $template, string $rendered): void
{
$response = $this->createStub(Response::class);
$response = static::createStub(Response::class);
$pool = new Pool('default');

$this->admin->method('getPersistentParameters')->willReturn(['param' => 'param']);
Expand Down
20 changes: 10 additions & 10 deletions tests/Controller/MediaAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testCreateActionToSelectProvider(): void
'@SonataMedia/MediaAdmin/select_provider.html.twig',
'renderResponse'
);
$pool->addProvider('provider', $this->createStub(MediaProviderInterface::class));
$pool->addProvider('provider', static::createStub(MediaProviderInterface::class));
$pool->addContext('context', ['provider']);
$this->admin->expects(static::once())->method('checkAccess')->with('create');
$this->container->set('sonata.media.pool', $pool);
Expand Down Expand Up @@ -122,8 +122,8 @@ public function testListAction(): void
$category = new Category();
$category->setId(1);
$context = new Context();
$form = $this->createStub(Form::class);
$formView = $this->createStub(FormView::class);
$form = static::createStub(Form::class);
$formView = static::createStub(FormView::class);

$this->configureSetFormTheme($formView, ['filterTheme']);
$this->configureSetCsrfToken('sonata.batch');
Expand Down Expand Up @@ -182,8 +182,8 @@ private function configureCRUDController(): void
'admin_code' => 'admin_code',
]);
$adminFetcher = new AdminFetcher($pool);
$templateRegistry = $this->createStub(TemplateRegistryInterface::class);
$mutableTemplateRegistry = $this->createStub(MutableTemplateRegistryInterface::class);
$templateRegistry = static::createStub(TemplateRegistryInterface::class);
$mutableTemplateRegistry = static::createStub(MutableTemplateRegistryInterface::class);

$mutableTemplateRegistry->method('getTemplate')->willReturnMap([
['layout', 'layout.html.twig'],
Expand Down Expand Up @@ -213,9 +213,9 @@ private function configureCRUDController(): void
*/
private function configureCreateAction(string $class): void
{
$object = $this->createStub(Media::class);
$object = static::createStub(Media::class);
$form = $this->createMock(Form::class);
$formView = $this->createStub(FormView::class);
$formView = static::createStub(FormView::class);

$this->configureSetFormTheme($formView, ['formTheme']);
$this->admin->method('hasActiveSubClass')->willReturn(false);
Expand All @@ -233,7 +233,7 @@ private function configureCreateAction(string $class): void

private function configureGetCurrentRequest(Request $request): void
{
$requestStack = $this->createStub(RequestStack::class);
$requestStack = static::createStub(RequestStack::class);

$this->container->set('request_stack', $requestStack);
$requestStack->method('getCurrentRequest')->willReturn($request);
Expand All @@ -253,7 +253,7 @@ private function configureSetFormTheme(FormView $formView, array $formTheme): vo
private function configureSetCsrfToken(string $intention): void
{
$tokenManager = $this->createMock(CsrfTokenManagerInterface::class);
$token = $this->createStub(CsrfToken::class);
$token = static::createStub(CsrfToken::class);

$tokenManager->method('getToken')->with($intention)->willReturn($token);
$token->method('getValue')->willReturn('token');
Expand All @@ -262,7 +262,7 @@ private function configureSetCsrfToken(string $intention): void

private function configureRender(string $template, string $rendered): void
{
$response = $this->createStub(Response::class);
$response = static::createStub(Response::class);
$pool = new Pool('context');

$response->method('getContent')->willReturn($rendered);
Expand Down
4 changes: 2 additions & 2 deletions tests/Form/Type/MediaTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function setUp(): void
$this->mediaPool = new Pool('default');
$this->mediaType = new MediaType($this->mediaPool, Media::class);

$this->mediaPool->addProvider('provider_a', $this->createStub(MediaProviderInterface::class));
$this->mediaPool->addProvider('provider_b', $this->createStub(MediaProviderInterface::class));
$this->mediaPool->addProvider('provider_a', static::createStub(MediaProviderInterface::class));
$this->mediaPool->addProvider('provider_b', static::createStub(MediaProviderInterface::class));
$this->mediaPool->addContext('video');
$this->mediaPool->addContext('pic');

Expand Down
2 changes: 1 addition & 1 deletion tests/Messenger/GenerateThumbnailsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testGenerateThumbnails(int|string $id): void
$media = new Media();
$media->setProviderName('provider_name');

$provider = $this->createStub(MediaProviderInterface::class);
$provider = static::createStub(MediaProviderInterface::class);

$this->pool->addProvider('provider_name', $provider);
$this->mediaManager->method('find')->with($id)->willReturn($media);
Expand Down
4 changes: 2 additions & 2 deletions tests/Metadata/AmazonMetadataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ final class AmazonMetadataBuilderTest extends TestCase
*/
public function testAmazon(array $settings, array $mediaAttributes, array $expected): void
{
$mimeTypes = $this->createStub(MimeTypesInterface::class);
$mimeTypes = static::createStub(MimeTypesInterface::class);
$mimeTypes->method('getMimeTypes')->willReturnCallback(
static fn (string $ext): array => 'png' === $ext ? ['image/png'] : []
);

$media = $this->createStub(MediaInterface::class);
$media = static::createStub(MediaInterface::class);
foreach ($mediaAttributes as $attribute => $value) {
$media->method('get'.ucfirst($attribute))->willReturn($value);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Metadata/ProxyMetadataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ final class ProxyMetadataBuilderTest extends TestCase

protected function setUp(): void
{
$this->filesystem = $this->createStub(Filesystem::class);
$this->filesystem = static::createStub(Filesystem::class);
$this->noop = $this->createMock(MetadataBuilderInterface::class);
$this->amazon = $this->createMock(MetadataBuilderInterface::class);

$provider = $this->createStub(MediaProviderInterface::class);
$provider = static::createStub(MediaProviderInterface::class);
$provider->method('getFilesystem')->willReturn($this->filesystem);

$pool = new Pool('default_context');
Expand Down
8 changes: 4 additions & 4 deletions tests/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ protected function setUp(): void

$admin = new MediaAdmin(new Pool('default'));
$admin->setModelClass(Media::class);
$admin->setLabelTranslatorStrategy($this->createStub(LabelTranslatorStrategyInterface::class));
$admin->setFieldDescriptionFactory($this->createStub(FieldDescriptionFactoryInterface::class));
$admin->setLabelTranslatorStrategy(static::createStub(LabelTranslatorStrategyInterface::class));
$admin->setFieldDescriptionFactory(static::createStub(FieldDescriptionFactoryInterface::class));

$this->form = new FormMapper(
$this->createStub(FormContractorInterface::class),
static::createStub(FormContractorInterface::class),
$this->formBuilder,
$admin
);
Expand Down Expand Up @@ -105,7 +105,7 @@ public function testBuildMediaType(): void

final protected function createResponse(string $content): ResponseInterface
{
$stream = $this->createStub(StreamInterface::class);
$stream = static::createStub(StreamInterface::class);
$stream->method('getContents')->willReturn($content);

$response = $this->createMock(ResponseInterface::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/Provider/BaseProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function getProvider(): MediaProviderInterface

$filesystem->method('get')->willReturn(new File('my_file.txt', $filesystem));

$cdn = $this->createStub(CDNInterface::class);
$cdn = static::createStub(CDNInterface::class);
$cdn->method('flushPaths')->willReturn((string) random_int(0, mt_getrandmax()));
$cdn->method('getFlushStatus')->willReturnOnConsecutiveCalls(CDNInterface::STATUS_OK, CDNInterface::STATUS_TO_FLUSH, CDNInterface::STATUS_WAITING, CDNInterface::STATUS_OK);
$cdn->method('getPath')->willReturnCallback(static fn (string $path, bool $isFlushable): string => '/uploads/media/'.$path);

$generator = new IdGenerator();

$thumbnail = $this->createStub(ThumbnailInterface::class);
$thumbnail = static::createStub(ThumbnailInterface::class);

$provider = new TestProvider('test', $filesystem, $cdn, $generator, $thumbnail);
static::assertInstanceOf(BaseProvider::class, $provider);
Expand Down
10 changes: 5 additions & 5 deletions tests/Provider/DailyMotionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class DailyMotionProviderTest extends AbstractProviderTest
public function getProvider(?ClientInterface $client = null, ?RequestFactoryInterface $requestFactory = null): MediaProviderInterface
{
if (null === $client) {
$client = $this->createStub(ClientInterface::class);
$client = static::createStub(ClientInterface::class);
}

if (null === $requestFactory) {
$requestFactory = $this->createStub(RequestFactoryInterface::class);
$requestFactory = static::createStub(RequestFactoryInterface::class);
}

$resizer = $this->createMock(ResizerInterface::class);
Expand Down Expand Up @@ -92,7 +92,7 @@ public function testProvider(): void

public function testThumbnail(): void
{
$request = $this->createStub(RequestInterface::class);
$request = static::createStub(RequestInterface::class);

$requestFactory = $this->createMock(RequestFactoryInterface::class);
$requestFactory->expects(static::once())->method('createRequest')->willReturn($request);
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testThumbnail(): void

public function testTransformWithSig(): void
{
$request = $this->createStub(RequestInterface::class);
$request = static::createStub(RequestInterface::class);

$requestFactory = $this->createMock(RequestFactoryInterface::class);
$requestFactory->expects(static::once())->method('createRequest')->willReturn($request);
Expand Down Expand Up @@ -174,7 +174,7 @@ public function testTransformWithSig(): void
*/
public function testTransformWithUrl(string $url): void
{
$request = $this->createStub(RequestInterface::class);
$request = static::createStub(RequestInterface::class);

$messageFactory = $this->createMock(RequestFactoryInterface::class);
$messageFactory->expects(static::once())->method('createRequest')->willReturn($request);
Expand Down
Loading

0 comments on commit edd9e02

Please sign in to comment.