Skip to content

Commit

Permalink
bug #1369 [LiveComponent] Fix test Kernel deprecations (smnandre)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x branch.

Discussion
----------

[LiveComponent] Fix test Kernel deprecations

Fix some Kernel deprecation.

But the CS remains, because (and it's kinda weird) PhpCSFixer says

```diff
 --- /home/runner/work/ux/ux/src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php
+++ /home/runner/work/ux/ux/src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php
@@ -752,7 +752,7 @@

             return HydrationTest::create(new class() {
                 #[LiveProp()]
-                /** `@var` \Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity[] */
+                /** `@var` ProductFixtureEntity[] */
                 public array $products = [];
             })
                 ->mountWith(['products' => [$prod1, $prod2, $prod3]])
```

But if we do that ....

```
1) Symfony\UX\LiveComponent\Tests\Integration\LiveComponentHydratorTest::testCanDehydrateAndHydrateComponentWithTestCases with data set "Array with objects: (de)hydrates correctly" (Closure Object (...))
LogicException: The LiveProp "products" on component "class@anonymous[...]src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php:753$4c" is an array. We determined the array is full of \ProductFixtureEntity objects, but at least on key had a different value of Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity
```

Commits
-------

203f5e1 [LiveComponent] Fix test Kernel deprecations
  • Loading branch information
kbond committed Jan 2, 2024
2 parents d109f66 + 203f5e1 commit 9c0efe4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/LiveComponent/tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\UX\LiveComponent\Tests\Fixtures;

use Composer\InstalledVersions;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
Expand Down Expand Up @@ -125,8 +126,10 @@ protected function configureContainer(ContainerConfigurator $c): void
'auto_refresh_proxies' => false,
]);

$c->extension('doctrine', [
'dbal' => ['url' => '%env(resolve:DATABASE_URL)%'],
$doctrineConfig = [
'dbal' => [
'url' => '%env(resolve:DATABASE_URL)%',
],
'orm' => [
'auto_generate_proxy_classes' => true,
'auto_mapping' => true,
Expand All @@ -147,7 +150,20 @@ 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;
}
// https://github.com/doctrine/DoctrineBundle/pull/1661
if (version_compare($doctrineBundleVersion, '2.9.0', '>=')) {
$doctrineConfig['orm']['report_fields_where_declared'] = true;
$doctrineConfig['orm']['validate_xml_mapping'] = true;
$doctrineConfig['dbal']['schema_manager_factory'] = 'doctrine.dbal.default_schema_manager_factory';
}
}

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

$c->extension('zenstruck_foundry', [
'auto_refresh_proxies' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ public function onEntireEntityUpdated($oldValue)
'invoice.lineItems.2' => ['name' => 'item3_updated', 'quantity' => 2, 'price' => 2000],
])
->assertObjectAfterHydration(function (object $object) {
self::assertSame([
self::assertSame(
[
'number' => '456',
'lineItems' => [
['name' => 'item1', 'quantity' => 5, 'price' => 100],
Expand Down Expand Up @@ -752,7 +753,7 @@ public function onEntireEntityUpdated($oldValue)
return HydrationTest::create(new class() {
#[LiveProp()]
/** @var \Symfony\UX\LiveComponent\Tests\Fixtures\Entity\ProductFixtureEntity[] */
public $products = [];
public array $products = [];
})
->mountWith(['products' => [$prod1, $prod2, $prod3]])
->assertDehydratesTo([
Expand Down

0 comments on commit 9c0efe4

Please sign in to comment.