-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ThemeCollector Symfony 7 compatibility #134
Changes from 4 commits
fc93513
cbdfa38
bcf4eaf
288b7bb
f143501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,10 @@ | |
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
|
||
/** | ||
* @property $data array{used_theme: ?ThemeInterface, used_themes: ThemeInterface[], themes: ThemeInterface[]} | ||
|
||
alexander-schranz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
final class ThemeCollector extends DataCollector | ||
{ | ||
private ThemeRepositoryInterface $themeRepository; | ||
|
@@ -29,15 +33,6 @@ final class ThemeCollector extends DataCollector | |
|
||
private ThemeHierarchyProviderInterface $themeHierarchyProvider; | ||
|
||
/** | ||
* @var array | ||
* | ||
* @psalm-var array{used_theme: ?ThemeInterface, used_themes: ThemeInterface[], themes: ThemeInterface[]} | ||
* | ||
* @psalm-suppress NonInvariantDocblockPropertyType | ||
*/ | ||
protected $data; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is defined by DataCollector itself. With beginning of Symfony 7 it has a Union Type here: https://github.com/symfony/symfony/blob/1a16ebc32598faada074e0af12a6a698d2964a5e/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php#L31 For BC reasons best is to move this variable to PHPDoc definition. So we can support Symfony 7 and previous versions of the parent collector class. |
||
|
||
public function __construct( | ||
ThemeRepositoryInterface $themeRepository, | ||
ThemeContextInterface $themeContext, | ||
|
@@ -60,7 +55,7 @@ public function getUsedTheme(): ?ThemeInterface | |
} | ||
|
||
/** | ||
* @return array|ThemeInterface[] | ||
* @return ThemeInterface[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see phpdoc above |
||
*/ | ||
public function getUsedThemes(): array | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ThemeBundle\Tests\Collector; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sylius\Bundle\ThemeBundle\Collector\ThemeCollector; | ||
use Sylius\Bundle\ThemeBundle\Context\EmptyThemeContext; | ||
use Sylius\Bundle\ThemeBundle\HierarchyProvider\NoopThemeHierarchyProvider; | ||
use Sylius\Bundle\ThemeBundle\Loader\ThemeLoaderInterface; | ||
use Sylius\Bundle\ThemeBundle\Repository\InMemoryThemeRepository; | ||
|
||
class ThemeCollectorTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_has_no_used_theme(): void | ||
{ | ||
$themeCollector = $this->createThemeCollector(); | ||
|
||
$this->assertNull($themeCollector->getUsedTheme()); | ||
} | ||
|
||
private function createThemeCollector(): ThemeCollector | ||
{ | ||
$themeLoader = new class () implements ThemeLoaderInterface { | ||
public function load(): array | ||
{ | ||
return []; | ||
} | ||
}; | ||
|
||
$themeRepository = new InMemoryThemeRepository($themeLoader); | ||
$themeContext = new EmptyThemeContext(); | ||
$themeHierarchyProvider = new NoopThemeHierarchyProvider(); | ||
|
||
return new ThemeCollector( | ||
$themeRepository, | ||
$themeContext, | ||
$themeHierarchyProvider, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stumbled now over that you also have a working console the lint:container would also catch such errors. I recommend always lint for dev and prod container as they may have different set of services.