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