diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bebab8d..421f798 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: matrix: ${{ steps.matrix.outputs.matrix }} steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Get Shopware Version id: shopware-constraint @@ -55,7 +55,7 @@ jobs: composer -V - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} @@ -65,7 +65,7 @@ jobs: composer create-placeholders php -d pcov.enabled=1 ${{ github.workspace }}/vendor/bin/phpunit --coverage-clover clover.xml --testsuite Unit - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: @@ -102,7 +102,7 @@ jobs: composer -V - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{ github.workspace }}/custom/plugins/${{ env.PLUGIN_NAME }} @@ -112,7 +112,7 @@ jobs: composer create-placeholders php -d pcov.enabled=1 ${{ github.workspace }}/vendor/bin/phpunit --testsuite Integration - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: diff --git a/phpstan.baseline-generated-files.neon b/phpstan.baseline-generated-files.neon index b0d0ccd..c4e78fa 100644 --- a/phpstan.baseline-generated-files.neon +++ b/phpstan.baseline-generated-files.neon @@ -11,6 +11,19 @@ parameters: count: 1 path: src/DependencyInjection/ThumbnailService.php reportUnmatched: false + + - + message: '#^Call to deprecated method#' + count: 3 + path: src/DependencyInjection/ThumbnailService.php + reportUnmatched: false + + - + message: '#^Only booleans are allowed in &&#' + count: 1 + path: src/DependencyInjection/ThumbnailService.php + reportUnmatched: false + - message: "#^Call to an undefined method Shopware\\\\Core\\\\Content\\\\Media\\\\Message\\\\GenerateThumbnailsMessage\\:\\:setContext\\(\\)\\.$#" count: 1 diff --git a/src/Controller/Api/TestController.php b/src/Controller/Api/TestController.php index 0e23451..9aa1c5a 100644 --- a/src/Controller/Api/TestController.php +++ b/src/Controller/Api/TestController.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; +use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderCollection; #[Route(defaults: ['_routeScope' => ['api']])] class TestController @@ -26,6 +27,10 @@ class TestController public const REQUEST_ATTRIBUTE_TEST_ACTIVE = 'FroshPlatformThumbnailProcessorTestActive'; public const TEST_FILE_PATH = __DIR__ . '/../../Resources/data/froshthumbnailprocessortestimage.jpg'; + /** + * @param EntityRepository $mediaRepository + * @param EntityRepository $mediaFolderRepository + */ public function __construct( private readonly AbstractMediaUrlGenerator $urlGenerator, private readonly EntityRepository $mediaRepository, @@ -143,7 +148,6 @@ private function getMediaById(string $fileName, Context $context): ?MediaEntity // we use the fileName filter to add backward compatibility $criteria->addFilter(new EqualsFilter('fileName', $fileName)); - /** @var MediaCollection $entities */ $entities = $this->mediaRepository->search($criteria, $context)->getEntities(); return $entities->first(); diff --git a/src/DependencyInjection/GeneratorCompilerPass.php b/src/DependencyInjection/GeneratorCompilerPass.php index f7ba3ea..7c8c6c9 100644 --- a/src/DependencyInjection/GeneratorCompilerPass.php +++ b/src/DependencyInjection/GeneratorCompilerPass.php @@ -113,7 +113,19 @@ private function handleThumbnailService(NodeFinder $nodeFinder, array $ast): voi } catch (\RuntimeException $e) { if ($e->getMessage() === 'Method createThumbnailsForSizes in class Shopware\Core\Content\Media\Thumbnail\ThumbnailService is missing') { $generateAndSaveNode = $this->getClassMethod($nodeFinder, 'generateAndSave', $ast); - $this->handleGenerateAndSaveNode($generateAndSaveNode); + + // when the internal 'isSameDimension' method is no longer available, we need to add the 'mediaThumbnailSizeId' field + $addMediaThumbnailSizeId = true; + try { + $this->getClassMethod($nodeFinder, 'isSameDimension', $ast); + $addMediaThumbnailSizeId = false; + } catch (\RuntimeException $e) { + if ($e->getMessage() !== 'Method isSameDimension in class Shopware\Core\Content\Media\Thumbnail\ThumbnailService is missing') { + throw $e; + } + } + + $this->handleGenerateAndSaveNode($generateAndSaveNode, $addMediaThumbnailSizeId); } else { throw $e; } @@ -269,7 +281,7 @@ private function handleCreateThumbnailsForSizes(ClassMethod $createThumbnailsFor return $savedThumbnails;'); } - private function handleGenerateAndSaveNode(ClassMethod $generateAndSaveNode): void + private function handleGenerateAndSaveNode(ClassMethod $generateAndSaveNode, bool $addMediaThumbnailSizeId): void { // we don't need to generate the files, so we just return the array $generateAndSaveNode->stmts = $this->getPhpParser() @@ -284,15 +296,13 @@ private function handleGenerateAndSaveNode(ClassMethod $generateAndSaveNode): vo throw MediaException::mediaTypeNotLoaded($media->getId()); } - $mapped = []; foreach ($sizes as $size) { $id = Uuid::randomHex(); - $mapped[$size->getId()] = $id; - $records[] = [ \'id\' => $id, \'mediaId\' => $media->getId(), + ' . ($addMediaThumbnailSizeId ? '\'mediaThumbnailSizeId\' => $size->getId(),' : '') . ' \'width\' => $size->getWidth(), \'height\' => $size->getHeight(), ]; diff --git a/src/EventListener/ThumbnailSizesChangedListener.php b/src/EventListener/ThumbnailSizesChangedListener.php index 98f92a1..0ed7282 100644 --- a/src/EventListener/ThumbnailSizesChangedListener.php +++ b/src/EventListener/ThumbnailSizesChangedListener.php @@ -2,7 +2,6 @@ namespace Frosh\ThumbnailProcessor\EventListener; -use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderEntity; use Shopware\Core\Content\Media\Aggregate\MediaFolderConfigurationMediaThumbnailSize\MediaFolderConfigurationMediaThumbnailSizeDefinition; use Shopware\Core\Content\Media\Commands\GenerateThumbnailsCommand; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -12,9 +11,13 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderCollection; class ThumbnailSizesChangedListener implements EventSubscriberInterface { + /** + * @param EntityRepository $mediaFolderRepository + */ public function __construct( private readonly GenerateThumbnailsCommand $generateThumbnailsCommand, private readonly EntityRepository $mediaFolderRepository, @@ -52,7 +55,6 @@ public function onThumbnailSizeChanged(EntityWrittenEvent $event): void $result = $this->mediaFolderRepository->search($criteria, $event->getContext()); - /** @var MediaFolderEntity $entity */ foreach ($result->getEntities() as $entity) { $parameters = []; diff --git a/src/Service/SalesChannelIdDetector.php b/src/Service/SalesChannelIdDetector.php index f1ab14d..85e62fc 100644 --- a/src/Service/SalesChannelIdDetector.php +++ b/src/Service/SalesChannelIdDetector.php @@ -10,9 +10,13 @@ use Shopware\Core\PlatformRequest; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Shopware\Core\Content\ProductExport\ProductExportCollection; class SalesChannelIdDetector { + /** + * @param EntityRepository $productExportRepository + */ public function __construct( private readonly RequestStack $requestStack, private readonly EntityRepository $productExportRepository diff --git a/tests/integration/MediaUrlTest.php b/tests/integration/MediaUrlTest.php index 2bab839..18518ac 100644 --- a/tests/integration/MediaUrlTest.php +++ b/tests/integration/MediaUrlTest.php @@ -7,6 +7,7 @@ use Shopware\Core\Content\Media\Aggregate\MediaThumbnail\MediaThumbnailCollection; use Shopware\Core\Content\Media\Commands\GenerateThumbnailsCommand; use Shopware\Core\Content\Media\Core\Application\AbstractMediaUrlGenerator; +use Shopware\Core\Content\Media\MediaCollection; use Shopware\Core\Content\Media\MediaEntity; use Shopware\Core\Content\Test\Media\MediaFixtures; use Shopware\Core\Framework\Context; @@ -18,7 +19,6 @@ use Shopware\Core\System\SystemConfig\SystemConfigService; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -use Symfony\Component\DependencyInjection\ContainerInterface; class MediaUrlTest extends TestCase { @@ -26,6 +26,9 @@ class MediaUrlTest extends TestCase use MediaFixtures; use QueueTestBehaviour; + /** + * @var EntityRepository + */ private EntityRepository $mediaRepository; private GenerateThumbnailsCommand $generateThumbnailsCommand; @@ -90,8 +93,8 @@ public function testMediaUrlWithInactiveConfigResultsInOriginalMedia(): void $mediaResult = $this->mediaRepository->search($searchCriteria, $this->context); - /** @var MediaEntity $updatedMedia */ $updatedMedia = $mediaResult->getEntities()->first(); + static::assertInstanceOf(MediaEntity::class, $updatedMedia); $thumbnails = $updatedMedia->getThumbnails(); static::assertInstanceOf(MediaThumbnailCollection::class, $thumbnails); @@ -150,8 +153,8 @@ public function testMediaUrlWithActiveConfig(): void $mediaResult = $this->mediaRepository->search($searchCriteria, $this->context); - /** @var MediaEntity $updatedMedia */ $updatedMedia = $mediaResult->getEntities()->first(); + static::assertInstanceOf(MediaEntity::class, $updatedMedia); $thumbnails = $updatedMedia->getThumbnails(); static::assertInstanceOf(MediaThumbnailCollection::class, $thumbnails); diff --git a/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php b/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php index 98029b4..cbb8de2 100644 --- a/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php +++ b/tests/unit/EventListener/ThumbnailSizesChangedListenerTest.php @@ -48,6 +48,7 @@ public function testOnThumbnailSizeChanged(): void $mediaFolderCollection = new MediaFolderCollection(); $mediaFolderCollection->add($mediaFolderEntity); + /** @var StaticEntityRepository */ $mediaFolderRepository = new StaticEntityRepository([$mediaFolderCollection]); $thumbnailSizesChangedListener = new ThumbnailSizesChangedListener( diff --git a/tests/unit/Service/SalesChannelIdDetectorTest.php b/tests/unit/Service/SalesChannelIdDetectorTest.php index 84d4fb3..5558ba3 100644 --- a/tests/unit/Service/SalesChannelIdDetectorTest.php +++ b/tests/unit/Service/SalesChannelIdDetectorTest.php @@ -3,6 +3,7 @@ namespace Frosh\ThumbnailProcessor\Tests\Unit\Service; use Frosh\ThumbnailProcessor\Service\SalesChannelIdDetector; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shopware\Core\Content\ProductExport\ProductExportCollection; use Shopware\Core\Content\ProductExport\ProductExportEntity; @@ -90,6 +91,7 @@ public function testGetSalesChannelIdProductExport(): void $productExportCollection = new ProductExportCollection(); $productExportCollection->add($productExportEntity); + /** @var StaticEntityRepository */ $productExportRepository = new StaticEntityRepository([$productExportCollection]); $class = new SalesChannelIdDetector($requestStack, $productExportRepository); @@ -106,6 +108,7 @@ public function testGetSalesChannelIdProductExportWithoutFileNameAndAccessKey(): ], )); + /** @var StaticEntityRepository&MockObject */ $productExportRepository = $this->createMock(StaticEntityRepository::class); $productExportRepository->expects(static::never())->method('search');