Skip to content

Commit

Permalink
minor symfony#2079 [LiveComponent] Fix PHP8.4 errors + deprecations (…
Browse files Browse the repository at this point in the history
…smnandre)

This PR was merged into the 2.x branch.

Discussion
----------

[LiveComponent] Fix PHP8.4 errors + deprecations

First patch of fixes (thanks to the PHP 8.4 tesst)

Commits
-------

0a862d7 [LiveComponent] Fix PHP8.4 errors + deprecations
  • Loading branch information
smnandre committed Aug 25, 2024
2 parents b083b76 + 0a862d7 commit 211ee5b
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 151 deletions.
13 changes: 7 additions & 6 deletions src/Icons/tests/Integration/Command/SearchIconCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ final class SearchIconCommandTest extends KernelTestCase

public function testSearchWithPrefix(): void
{
$this->consoleCommand('ux:icons:search lucide')
$this->consoleCommand('ux:icons:search iconoir')
->execute()
->assertSuccessful()
->assertOutputContains('Icon set')
->assertOutputContains('Lucide')
->assertOutputContains('Iconoir')
->assertOutputContains('Icons')
->assertOutputContains('License')
->assertOutputContains('ISC')
->assertOutputContains('MIT')
->assertOutputContains('Prefix')
->assertOutputContains('lucide')
->assertOutputContains('iconoir')
->assertOutputContains('Example')
->assertOutputContains('lucide:')
->assertOutputContains('php bin/console ux:icons:search lucide');
->assertOutputContains('iconoir:')
->assertOutputContains('php bin/console ux:icons:search iconoir')
->assertStatusCode(0);
}

public function testSearchWithPrefixMatchingMultipleSet(): void
Expand Down
2 changes: 1 addition & 1 deletion src/LiveComponent/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"symfony/twig-bundle": "^5.4|^6.0|^7.0",
"symfony/validator": "^5.4|^6.0|^7.0",
"zenstruck/browser": "^1.2.0",
"zenstruck/foundry": "1.37.*"
"zenstruck/foundry": "^2.0"
},
"conflict": {
"symfony/config": "<5.4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/LiveComponent/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<server name="KERNEL_CLASS" value="Symfony\UX\LiveComponent\Tests\Fixtures\Kernel"/>
<server name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db"/>
<env name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0&amp;ignoreFile=./tests/baseline-ignore"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0&amp;quiet[]=indirect&amp;quiet[]=other"/>
</php>

<testsuites>
Expand Down
11 changes: 10 additions & 1 deletion src/LiveComponent/tests/Fixtures/Dto/HoldsArrayOfDtos.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent\Tests\Fixtures\Dto;

final class HoldsArrayOfDtos
{
/**
* @var Address[] $addresses
* @var Address[]
*/
public array $addresses;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ class TodoItemFixtureEntity
public $id;

#[ORM\Column(type: 'string')]
private ?string $name = null;
private ?string $name;

#[ORM\ManyToOne(targetEntity: TodoListFixtureEntity::class, inversedBy: 'todoItems')]
private TodoListFixtureEntity $todoList;

/**
* @param string $name
*/
public function __construct(string $name = null)
public function __construct(?string $name = null)
{
$this->name = $name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,20 @@

namespace Symfony\UX\LiveComponent\Tests\Fixtures\Factory;

use Doctrine\ORM\EntityRepository;
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\CompositeIdEntity;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends ModelFactory<CompositeIdEntity>
*
* @method static CompositeIdEntity|Proxy createOne(array $attributes = [])
* @method static CompositeIdEntity[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static CompositeIdEntity|Proxy find(object|array|mixed $criteria)
* @method static CompositeIdEntity|Proxy findOrCreate(array $attributes)
* @method static CompositeIdEntity|Proxy first(string $sortedField = 'id')
* @method static CompositeIdEntity|Proxy last(string $sortedField = 'id')
* @method static CompositeIdEntity|Proxy random(array $attributes = [])
* @method static CompositeIdEntity|Proxy randomOrCreate(array $attributes = []))
* @method static CompositeIdEntity[]|Proxy[] all()
* @method static CompositeIdEntity[]|Proxy[] findBy(array $attributes)
* @method static CompositeIdEntity[]|Proxy[] randomSet(int $number, array $attributes = []))
* @method static CompositeIdEntity[]|Proxy[] randomRange(int $min, int $max, array $attributes = []))
* @method static EntityRepository|RepositoryProxy repository()
* @method CompositeIdEntity|Proxy create(array|callable $attributes = [])
* @extends PersistentProxyObjectFactory<CompositeIdEntity>
*/
class CompositeIdEntityFactory extends ModelFactory
class CompositeIdEntityFactory extends PersistentProxyObjectFactory
{
protected static function getClass(): string
public static function class(): string
{
return CompositeIdEntity::class;
}

protected function getDefaults(): array
protected function defaults(): array
{
return [
'firstIdPart' => rand(1, \PHP_INT_MAX),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,23 @@

namespace Symfony\UX\LiveComponent\Tests\Fixtures\Factory;

use Doctrine\ORM\EntityRepository;
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\Entity1;
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ForeignKeyIdEntity;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Proxy;
use Zenstruck\Foundry\RepositoryProxy;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

use function Zenstruck\Foundry\lazy;

/**
* @extends ModelFactory<ForeignKeyIdEntity>
*
* @method static ForeignKeyIdEntity|Proxy createOne(array $attributes = [])
* @method static ForeignKeyIdEntity[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static ForeignKeyIdEntity|Proxy find(object|array|mixed $criteria)
* @method static ForeignKeyIdEntity|Proxy findOrCreate(array $attributes)
* @method static ForeignKeyIdEntity|Proxy first(string $sortedField = 'id')
* @method static ForeignKeyIdEntity|Proxy last(string $sortedField = 'id')
* @method static ForeignKeyIdEntity|Proxy random(array $attributes = [])
* @method static ForeignKeyIdEntity|Proxy randomOrCreate(array $attributes = []))
* @method static ForeignKeyIdEntity[]|Proxy[] all()
* @method static ForeignKeyIdEntity[]|Proxy[] findBy(array $attributes)
* @method static ForeignKeyIdEntity[]|Proxy[] randomSet(int $number, array $attributes = []))
* @method static ForeignKeyIdEntity[]|Proxy[] randomRange(int $min, int $max, array $attributes = []))
* @method static EntityRepository|RepositoryProxy repository()
* @method ForeignKeyIdEntity|Proxy create(array|callable $attributes = [])
* @extends PersistentProxyObjectFactory<ForeignKeyIdEntity>
*/
class ForeignKeyIdEntityFactory extends ModelFactory
class ForeignKeyIdEntityFactory extends PersistentProxyObjectFactory
{
protected static function getClass(): string
public static function class(): string
{
return ForeignKeyIdEntity::class;
}

protected function getDefaults(): array
protected function defaults(): array
{
return ['id' => lazy(static fn () => new Entity1())];
}
Expand Down
12 changes: 6 additions & 6 deletions src/LiveComponent/tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public function index(): Response
return new Response('index');
}

public function renderTemplate(string $template, Environment $twig = null): Response
public function renderTemplate(string $template, ?Environment $twig = null): Response
{
$twig ??= $this->container->get('twig');

return new Response($twig->render("{$template}.html.twig"));
}

public function renderNamespacedTemplate(string $template, Environment $twig = null): Response
public function renderNamespacedTemplate(string $template, ?Environment $twig = null): Response
{
$twig ??= $this->container->get('twig');

Expand Down Expand Up @@ -171,6 +171,7 @@ protected function configureContainer(ContainerConfigurator $c): void
],
],
];

if (null !== $doctrineBundleVersion = InstalledVersions::getVersion('doctrine/doctrine-bundle')) {
if (version_compare($doctrineBundleVersion, '2.8.0', '>=')) {
$doctrineConfig['orm']['enable_lazy_ghost_objects'] = true;
Expand All @@ -181,14 +182,13 @@ protected function configureContainer(ContainerConfigurator $c): void
$doctrineConfig['orm']['validate_xml_mapping'] = true;
$doctrineConfig['dbal']['schema_manager_factory'] = 'doctrine.dbal.default_schema_manager_factory';
}
if (version_compare($doctrineBundleVersion, '2.12.0', '>=')) {
$doctrineConfig['orm']['controller_resolver']['auto_mapping'] = false;
}
}

$c->extension('doctrine', $doctrineConfig);

$c->extension('zenstruck_foundry', [
'auto_refresh_proxies' => false,
]);

$c->services()
->defaults()
->autowire()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function supportsNormalization(mixed $data, string $format = null, array
return $data instanceof Entity2;
}

public function getSupportedTypes(?string $format): array
public function getSupportedTypes(?string $format = null): array
{
return [Entity2::class => true];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function supportsNormalization(mixed $data, string $format = null, array
return $data instanceof Money;
}

public function getSupportedTypes(?string $format): array
public function getSupportedTypes(string $format = null): array
{
return [Money::class => true];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

use function Zenstruck\Foundry\create;
use function Zenstruck\Foundry\Persistence\persist;

/**
* @author Kevin Bond <[email protected]>
Expand All @@ -48,7 +48,7 @@ final class LiveComponentSubscriberTest extends KernelTestCase
public function testCanRenderComponentAsHtml(): void
{
$component = $this->mountComponent('component1', [
'prop1' => $entity = create(Entity1::class)->object(),
'prop1' => $entity = persist(Entity1::class),
'prop2' => $date = new \DateTime('2021-03-05 9:23'),
'prop3' => 'value3',
'prop4' => 'value4',
Expand Down
2 changes: 1 addition & 1 deletion src/LiveComponent/tests/Functional/LiveResponderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent\Tests\Functional\EventListener;
namespace Symfony\UX\LiveComponent\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent\Tests\Functional\Form;
namespace Symfony\UX\LiveComponent\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent\Tests\Integration;
namespace Symfony\UX\LiveComponent\Tests\Integration\EventListener;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent\Tests\Unit\Hydration;
namespace Symfony\UX\LiveComponent\Tests\Integration\Hydration;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\UX\LiveComponent\Hydration\DoctrineEntityHydrationExtension;
Expand All @@ -27,7 +27,7 @@ class DoctrineEntityHydrationExtensionTest extends KernelTestCase

public function testCompositeId(): void
{
$compositeIdEntity = CompositeIdEntityFactory::createOne()->save()->object();
$compositeIdEntity = CompositeIdEntityFactory::createOne()->_real();

/** @var DoctrineEntityHydrationExtension $extension */
$extension = self::getContainer()->get('ux.live_component.doctrine_entity_hydration_extension');
Expand All @@ -40,7 +40,7 @@ public function testCompositeId(): void

public function testForeignKeyId(): void
{
$foreignKeyIdEntity = ForeignKeyIdEntityFactory::createOne()->save()->object();
$foreignKeyIdEntity = ForeignKeyIdEntityFactory::createOne()->_real();

/** @var DoctrineEntityHydrationExtension $extension */
$extension = self::getContainer()->get('ux.live_component.doctrine_entity_hydration_extension');
Expand Down
Loading

0 comments on commit 211ee5b

Please sign in to comment.