1010use PHPUnit \Framework \MockObject \MockObject ;
1111use PHPUnit \Framework \TestCase ;
1212use Psr \Log \LoggerInterface ;
13+ use Symfony \Component \Routing \RouterInterface ;
1314
1415#[Small]
1516class SseTransportTest extends TestCase
@@ -18,14 +19,17 @@ class SseTransportTest extends TestCase
1819
1920 private SseAdapterInterface |MockObject $ adapterMock ;
2021
22+ private RouterInterface |MockObject $ routerMock ;
23+
2124 private SseTransport $ instance ;
2225
2326 protected function setUp (): void
2427 {
2528 parent ::setUp ();
2629 $ this ->loggerMock = $ this ->createMock (LoggerInterface::class);
2730 $ this ->adapterMock = $ this ->createMock (SseAdapterInterface::class);
28- $ this ->instance = new SseTransport ('/default-path ' , $ this ->adapterMock , $ this ->loggerMock );
31+ $ this ->routerMock = $ this ->createMock (RouterInterface::class);
32+ $ this ->instance = new SseTransport ($ this ->routerMock , $ this ->adapterMock , $ this ->loggerMock );
2933 }
3034
3135 /**
@@ -58,6 +62,17 @@ public function test_send_string_message(): void
5862 */
5963 public function test_initialize_generates_client_id_and_sends_endpoint (): void
6064 {
65+ // Arrange
66+ $ this ->routerMock
67+ ->expects ($ this ->once ())
68+ ->method ('generate ' )
69+ ->willReturnCallback (function (string $ name , array $ parameters = []): string {
70+ $ this ->assertEquals ('message_route ' , $ name );
71+ $ this ->assertArrayHasKey ('sessionId ' , $ parameters );
72+
73+ return '/default-path/messages?sessionId= ' .$ parameters ['sessionId ' ];
74+ })
75+ ;
6176 // Act
6277 ob_start ();
6378 try {
@@ -84,6 +99,11 @@ public function test_initialize_does_not_overwrite_existing_client_id(): void
8499 // Arrange
85100 $ existingClientId = 'predefined-client-id ' ;
86101 $ this ->setProtectedProperty ($ this ->instance , 'clientId ' , $ existingClientId );
102+ $ this ->routerMock
103+ ->expects ($ this ->once ())
104+ ->method ('generate ' )
105+ ->with ('message_route ' , ['sessionId ' => $ existingClientId ])
106+ ->willReturn ('/default-path/messages?sessionId= ' . $ existingClientId );
87107
88108 // Act
89109 ob_start ();
0 commit comments