Skip to content

Commit

Permalink
bug #134 Fix ThemeCollector Symfony 7 compatibility (alexander-schranz)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.4 branch.

Discussion
----------

>  PHP Fatal error:  Type of Sylius\Bundle\ThemeBundle\Collector\ThemeCollector::$data must be Symfony\Component\VarDumper\Cloner\Data|array (as in class Symfony\Component\HttpKernel\DataCollector\DataCollector) in /home/runner/work/SyliusThemeBundle/SyliusThemeBundle/src/Collector/ThemeCollector.php on line 24

I added a very simple test case which just init the ThemeCollector to catch this.

Commits
-------

fc93513 Fix ThemeCollector Symfony 7 compatibility
cbdfa38 Add test case with ThemeCollector
bcf4eaf Fix PHPDoc for getUsedThemes
288b7bb Lint building of container
f143501 Apply suggestions from code review
  • Loading branch information
GSadee authored Jul 18, 2024
2 parents 0567073 + f143501 commit df263ac
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
"@composer validate --strict",
"vendor/bin/ecs check spec src tests || true",
"vendor/bin/psalm",
"vendor/bin/rector process --dry-run"
"vendor/bin/rector process --dry-run",
"tests/Application/bin/console lint:container --env dev",
"tests/Application/bin/console lint:container --env prod"
],
"fix": [
"vendor/bin/rector process",
Expand Down
14 changes: 4 additions & 10 deletions src/Collector/ThemeCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;

/**
* @property $data array{used_theme: ?ThemeInterface, used_themes: ThemeInterface[], themes: ThemeInterface[]}
*/
final class ThemeCollector extends DataCollector
{
private ThemeRepositoryInterface $themeRepository;
Expand All @@ -29,15 +32,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;

public function __construct(
ThemeRepositoryInterface $themeRepository,
ThemeContextInterface $themeContext,
Expand All @@ -60,7 +54,7 @@ public function getUsedTheme(): ?ThemeInterface
}

/**
* @return array|ThemeInterface[]
* @return ThemeInterface[]
*/
public function getUsedThemes(): array
{
Expand Down
54 changes: 54 additions & 0 deletions tests/Collector/ThemeCollectorTest.php
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,
);
}
}

0 comments on commit df263ac

Please sign in to comment.