2
2
3
3
namespace Symfony \Component \Notifier \Bridge \LinkedIn \Tests ;
4
4
5
- use PHPUnit \Framework \TestCase ;
6
5
use Symfony \Component \HttpClient \MockHttpClient ;
7
6
use Symfony \Component \Notifier \Bridge \LinkedIn \LinkedInTransport ;
8
7
use Symfony \Component \Notifier \Exception \LogicException ;
9
8
use Symfony \Component \Notifier \Exception \TransportException ;
10
- use Symfony \Component \Notifier \Exception \UnsupportedMessageTypeException ;
11
9
use Symfony \Component \Notifier \Message \ChatMessage ;
12
10
use Symfony \Component \Notifier \Message \MessageInterface ;
13
11
use Symfony \Component \Notifier \Message \MessageOptionsInterface ;
12
+ use Symfony \Component \Notifier \Message \SmsMessage ;
14
13
use Symfony \Component \Notifier \Notification \Notification ;
14
+ use Symfony \Component \Notifier \Tests \TransportTestCase ;
15
+ use Symfony \Component \Notifier \Transport \TransportInterface ;
15
16
use Symfony \Contracts \HttpClient \HttpClientInterface ;
16
17
use Symfony \Contracts \HttpClient \ResponseInterface ;
17
18
18
- final class LinkedInTransportTest extends TestCase
19
+ final class LinkedInTransportTest extends TransportTestCase
19
20
{
20
- public function testToStringContainsProperties ()
21
+ /**
22
+ * @return LinkedInTransport
23
+ */
24
+ public function createTransport (?HttpClientInterface $ client = null ): TransportInterface
21
25
{
22
- $ transport = $ this ->createTransport ();
23
-
24
- $ this ->assertSame ('linkedin://host.test ' , (string ) $ transport );
26
+ return (new LinkedInTransport ('AuthToken ' , 'AccountId ' , $ client ?: $ this ->createMock (HttpClientInterface::class)))->setHost ('host.test ' );
25
27
}
26
28
27
- public function testSupportsChatMessage ()
29
+ public function toStringProvider (): iterable
28
30
{
29
- $ transport = $ this ->createTransport ();
30
-
31
- $ this ->assertTrue ($ transport ->supports (new ChatMessage ('testChatMessage ' )));
32
- $ this ->assertFalse ($ transport ->supports ($ this ->createMock (MessageInterface::class)));
31
+ yield ['linkedin://host.test ' , $ this ->createTransport ()];
33
32
}
34
33
35
- public function testSendNonChatMessageThrows ()
34
+ public function supportedMessagesProvider (): iterable
36
35
{
37
- $ transport = $ this ->createTransport ();
38
-
39
- $ this ->expectException (UnsupportedMessageTypeException::class);
40
-
41
- $ transport ->send ($ this ->createMock (MessageInterface::class));
36
+ yield [new ChatMessage ('Hello! ' )];
42
37
}
43
38
44
- public function testSendWithEmptyArrayResponseThrows ()
39
+ public function unsupportedMessagesProvider (): iterable
45
40
{
46
- $ this ->expectException (TransportException::class);
41
+ yield [new SmsMessage ('0611223344 ' , 'Hello! ' )];
42
+ yield [$ this ->createMock (MessageInterface::class)];
43
+ }
47
44
45
+ public function testSendWithEmptyArrayResponseThrowsTransportException ()
46
+ {
48
47
$ response = $ this ->createMock (ResponseInterface::class);
49
48
$ response ->expects ($ this ->exactly (2 ))
50
49
->method ('getStatusCode ' )
@@ -59,10 +58,12 @@ public function testSendWithEmptyArrayResponseThrows()
59
58
60
59
$ transport = $ this ->createTransport ($ client );
61
60
61
+ $ this ->expectException (TransportException::class);
62
+
62
63
$ transport ->send (new ChatMessage ('testMessage ' ));
63
64
}
64
65
65
- public function testSendWithErrorResponseThrows ()
66
+ public function testSendWithErrorResponseThrowsTransportException ()
66
67
{
67
68
$ this ->expectException (TransportException::class);
68
69
$ this ->expectExceptionMessage ('testErrorCode ' );
@@ -189,9 +190,4 @@ public function testSendWithInvalidOptions()
189
190
190
191
$ transport ->send (new ChatMessage ('testMessage ' , $ this ->createMock (MessageOptionsInterface::class)));
191
192
}
192
-
193
- private function createTransport (?HttpClientInterface $ client = null ): LinkedInTransport
194
- {
195
- return (new LinkedInTransport ('AuthToken ' , 'AccountId ' , $ client ?? $ this ->createMock (HttpClientInterface::class)))->setHost ('host.test ' );
196
- }
197
193
}
0 commit comments