-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Turbo] Add support for providing multiple mercure topics to `turbo_s…
…tream_listen`
- Loading branch information
Showing
8 changed files
with
153 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Turbo\Bridge\Mercure; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TopicSet | ||
{ | ||
/** | ||
* @param array<string|object> $topics | ||
*/ | ||
public function __construct( | ||
private array $topics, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array<string|object> | ||
*/ | ||
public function getTopics(): array | ||
{ | ||
return $this->topics; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Turbo/tests/Bridge/Mercure/TurboStreamListenRendererTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Turbo\Tests\Bridge\Mercure; | ||
|
||
use App\Entity\Book; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
final class TurboStreamListenRendererTest extends KernelTestCase | ||
{ | ||
/** | ||
* @dataProvider provideTestCases | ||
*/ | ||
public function testRenderTurboStreamListen(string $template, array $context, string $expectedResult) | ||
{ | ||
$this->assertSame($expectedResult, self::getContainer()->get('twig')->createTemplate($template)->render($context)); | ||
} | ||
|
||
public static function provideTestCases(): iterable | ||
{ | ||
$book = new Book(); | ||
$book->id = 123; | ||
|
||
yield [ | ||
"{{ turbo_stream_listen('a_topic') }}", | ||
[], | ||
'data-controller="symfony--ux-turbo--mercure-turbo-stream" data-symfony--ux-turbo--mercure-turbo-stream-hub-value="http://127.0.0.1:3000/.well-known/mercure" data-symfony--ux-turbo--mercure-turbo-stream-topic-value="a_topic"', | ||
]; | ||
|
||
yield [ | ||
"{{ turbo_stream_listen('App\\Entity\\Book') }}", | ||
[], | ||
'data-controller="symfony--ux-turbo--mercure-turbo-stream" data-symfony--ux-turbo--mercure-turbo-stream-hub-value="http://127.0.0.1:3000/.well-known/mercure" data-symfony--ux-turbo--mercure-turbo-stream-topic-value="AppEntityBook"', | ||
]; | ||
|
||
yield [ | ||
'{{ turbo_stream_listen(book) }}', | ||
['book' => $book], | ||
'data-controller="symfony--ux-turbo--mercure-turbo-stream" data-symfony--ux-turbo--mercure-turbo-stream-hub-value="http://127.0.0.1:3000/.well-known/mercure" data-symfony--ux-turbo--mercure-turbo-stream-topic-value="https://symfony.com/ux-turbo/App%5CEntity%5CBook/123"', | ||
]; | ||
|
||
yield [ | ||
"{{ turbo_stream_listen(['a_topic', 'App\\Entity\\Book', book]) }}", | ||
['book' => $book], | ||
'data-controller="symfony--ux-turbo--mercure-turbo-stream" data-symfony--ux-turbo--mercure-turbo-stream-hub-value="http://127.0.0.1:3000/.well-known/mercure" data-symfony--ux-turbo--mercure-turbo-stream-topics-value="["a_topic","AppEntityBook","https:\/\/symfony.com\/ux-turbo\/App%5CEntity%5CBook\/123"]"', | ||
]; | ||
} | ||
} |