Skip to content
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

[Turbo] Fix Doctrine Proxy are not Broadcasted #1929

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Turbo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.19.0

- Fix Doctrine proxies are not Broadcasted #3139

## 2.15.0

- Add Turbo 8 support #1476
Expand Down
9 changes: 4 additions & 5 deletions src/Turbo/src/Doctrine/ClassUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\UX\Turbo\Doctrine;

use Doctrine\Common\Util\ClassUtils as LegacyClassUtils;
use Symfony\Component\VarExporter\LazyObjectInterface;

/**
Expand All @@ -24,13 +23,13 @@ final class ClassUtil
*/
public static function getEntityClass(object $entity): string
{
if ($entity instanceof LazyObjectInterface) {
// Doctrine proxies (old versions)
if (str_contains($entity::class, 'Proxies\\__CG__')) {
return get_parent_class($entity) ?: $entity::class;
}

// @legacy for old versions of Doctrine
if (class_exists(LegacyClassUtils::class)) {
return LegacyClassUtils::getClass($entity);
if ($entity instanceof LazyObjectInterface) {
return get_parent_class($entity) ?: $entity::class;
}

return $entity::class;
Expand Down
11 changes: 6 additions & 5 deletions src/Turbo/tests/BroadcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BroadcastTest extends PantherTestCase
protected function setUp(): void
{
if (!file_exists(__DIR__.'/app/public/build')) {
throw new \Exception(\sprintf('Move into %s and execute Encore before running this test.', realpath(__DIR__.'/app')));
throw new \Exception(\sprintf('Move into "%s" and execute Encore before running this test.', realpath(__DIR__.'/app')));
}

parent::setUp();
Expand All @@ -38,7 +38,7 @@ public function testBroadcastBasic(): void
($client = self::createPantherClient())->request('GET', '/books');

$crawler = $client->submitForm('Submit', ['title' => self::BOOK_TITLE]);
$client->waitForElementToContain('#books div', self::BOOK_TITLE);
// $client->waitForElementToContain('#books div', self::BOOK_TITLE);

$this->assertSelectorWillContain('#books', self::BOOK_TITLE);
if (!preg_match('/\(#(\d+)\)/', $crawler->filter('#books div')->text(), $matches)) {
Expand All @@ -57,9 +57,10 @@ public function testExpressionLanguageBroadcast(): void
($client = self::createPantherClient())->request('GET', '/artists');

$client->submitForm('Submit', ['name' => self::ARTIST_NAME_1]);
$client->waitForElementToContain('#artists div:nth-child(1)', self::ARTIST_NAME_1);
$client->waitForElementToContain('#artists div:nth-child(1)', self::ARTIST_NAME_1, 5);

$client->submitForm('Submit', ['name' => self::ARTIST_NAME_2]);
$client->waitForElementToContain('#artists div:nth-child(2)', self::ARTIST_NAME_2);
$client->waitForElementToContain('#artists div:nth-child(2)', self::ARTIST_NAME_2, 5);

$crawlerArtist = $client->getCrawler();

Expand All @@ -78,7 +79,7 @@ public function testExpressionLanguageBroadcast(): void

$client->submitForm('Submit', ['title' => self::SONG_TITLE, 'artistId' => $artist1Id]);

$clientArtist1->waitForElementToContain('#songs div', self::SONG_TITLE);
$clientArtist1->waitForElementToContain('#songs div', self::SONG_TITLE, 5);

$songsElement = $clientArtist2->findElement(WebDriverBy::cssSelector('#songs'));

Expand Down
Loading