Skip to content

Commit

Permalink
Add support for BlockBundle 5.0 (#2396)
Browse files Browse the repository at this point in the history
* Add support for BlockBundle 5.0

* Add test for 5.0

* Actualizar FeatureMediaBlockServiceTest.php

* Actualizar FeatureMediaBlockServiceTest.php

* Actualizar MediaBlockServiceTest.php

* Actualizar GalleryBlockServiceTest.php

* Actualizar GalleryBlockServiceTest.php

* Actualizar MediaBlockServiceTest.php

* Actualizar FeatureMediaBlockServiceTest.php
  • Loading branch information
jordisala1991 authored Jun 4, 2023
1 parent 1de90e4 commit 2c1f433
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ jobs:
dependencies: highest
allowed-to-fail: false
variant: sonata-project/form-extensions:"2.0.0-alpha-1"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
variant: sonata-project/block-bundle:"5.0.0-alpha-1"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
Expand Down
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-symfony": "^5.0",
"rector/rector": "^0.16",
"sonata-project/admin-bundle": "^4.9",
"sonata-project/block-bundle": "^4.11",
"sonata-project/block-bundle": "^4.11 || ^5.0",
"sonata-project/classification-bundle": "^4.0",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^5.4 || ^6.2",
Expand Down
20 changes: 15 additions & 5 deletions tests/Block/FeatureMediaBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use PHPUnit\Framework\MockObject\Stub;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\BlockBundle\Cache\HttpCacheHandler;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
use Sonata\MediaBundle\Block\FeatureMediaBlockService;
use Sonata\MediaBundle\Model\MediaInterface;
Expand All @@ -40,15 +41,17 @@ protected function setUp(): void
);
}

/**
* @psalm-suppress DeprecatedClass
*/
public function testDefaultSettings(): void
{
$blockContext = $this->getBlockContext($this->blockService);

$this->assertSettings([
$settings = [
'attr' => [],
'content' => false,
'context' => false,
'extra_cache_keys' => [],
'format' => false,
'media' => false,
'mediaId' => null,
Expand All @@ -58,8 +61,15 @@ public function testDefaultSettings(): void
'translation_domain' => null,
'icon' => null,
'class' => null,
'ttl' => 0,
'use_cache' => true,
], $blockContext);
];

// TODO: Remove if when dropping support for sonata-project/block-bundle < 5.0
if (class_exists(HttpCacheHandler::class)) {
$settings['extra_cache_keys'] = [];
$settings['ttl'] = 0;
$settings['use_cache'] = true;
}

$this->assertSettings($settings, $blockContext);
}
}
20 changes: 15 additions & 5 deletions tests/Block/GalleryBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\MockObject\Stub;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Cache\HttpCacheHandler;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
use Sonata\MediaBundle\Block\GalleryBlockService;
Expand Down Expand Up @@ -69,14 +70,16 @@ public function testExecute(): void
$this->blockService->execute($blockContext);
}

/**
* @psalm-suppress DeprecatedClass
*/
public function testDefaultSettings(): void
{
$blockContext = $this->getBlockContext($this->blockService);

$this->assertSettings([
$settings = [
'attr' => [],
'context' => false,
'extra_cache_keys' => [],
'format' => false,
'gallery' => false,
'galleryId' => null,
Expand All @@ -87,8 +90,15 @@ public function testDefaultSettings(): void
'translation_domain' => null,
'icon' => null,
'class' => null,
'ttl' => 0,
'use_cache' => true,
], $blockContext);
];

// TODO: Remove if when dropping support for sonata-project/block-bundle < 5.0
if (class_exists(HttpCacheHandler::class)) {
$settings['extra_cache_keys'] = [];
$settings['ttl'] = 0;
$settings['use_cache'] = true;
}

$this->assertSettings($settings, $blockContext);
}
}
20 changes: 15 additions & 5 deletions tests/Block/MediaBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Framework\MockObject\Stub;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Cache\HttpCacheHandler;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
use Sonata\MediaBundle\Block\MediaBlockService;
Expand Down Expand Up @@ -76,14 +77,16 @@ public function testExecute(): void
$this->blockService->execute($blockContext);
}

/**
* @psalm-suppress DeprecatedClass
*/
public function testDefaultSettings(): void
{
$blockContext = $this->getBlockContext($this->blockService);

$this->assertSettings([
$settings = [
'attr' => [],
'context' => false,
'extra_cache_keys' => [],
'format' => false,
'media' => false,
'mediaId' => null,
Expand All @@ -92,9 +95,16 @@ public function testDefaultSettings(): void
'translation_domain' => null,
'icon' => null,
'class' => null,
'ttl' => 0,
'use_cache' => true,
], $blockContext);
];

// TODO: Remove if when dropping support for sonata-project/block-bundle < 5.0
if (class_exists(HttpCacheHandler::class)) {
$settings['extra_cache_keys'] = [];
$settings['ttl'] = 0;
$settings['use_cache'] = true;
}

$this->assertSettings($settings, $blockContext);
}

private function configureFormat(MockObject $media, string $format): void
Expand Down

0 comments on commit 2c1f433

Please sign in to comment.