Skip to content

Commit ca004a5

Browse files
OskarStarkderrabus
authored andcommitted
[Notifier] Use abstract test cases in 5.x
1 parent 9fd66aa commit ca004a5

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

Tests/LinkedInTransportTest.php

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,48 @@
22

33
namespace Symfony\Component\Notifier\Bridge\LinkedIn\Tests;
44

5-
use PHPUnit\Framework\TestCase;
65
use Symfony\Component\HttpClient\MockHttpClient;
76
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransport;
87
use Symfony\Component\Notifier\Exception\LogicException;
98
use Symfony\Component\Notifier\Exception\TransportException;
10-
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
119
use Symfony\Component\Notifier\Message\ChatMessage;
1210
use Symfony\Component\Notifier\Message\MessageInterface;
1311
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
12+
use Symfony\Component\Notifier\Message\SmsMessage;
1413
use Symfony\Component\Notifier\Notification\Notification;
14+
use Symfony\Component\Notifier\Tests\TransportTestCase;
15+
use Symfony\Component\Notifier\Transport\TransportInterface;
1516
use Symfony\Contracts\HttpClient\HttpClientInterface;
1617
use Symfony\Contracts\HttpClient\ResponseInterface;
1718

18-
final class LinkedInTransportTest extends TestCase
19+
final class LinkedInTransportTest extends TransportTestCase
1920
{
20-
public function testToStringContainsProperties()
21+
/**
22+
* @return LinkedInTransport
23+
*/
24+
public function createTransport(?HttpClientInterface $client = null): TransportInterface
2125
{
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');
2527
}
2628

27-
public function testSupportsChatMessage()
29+
public function toStringProvider(): iterable
2830
{
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()];
3332
}
3433

35-
public function testSendNonChatMessageThrows()
34+
public function supportedMessagesProvider(): iterable
3635
{
37-
$transport = $this->createTransport();
38-
39-
$this->expectException(UnsupportedMessageTypeException::class);
40-
41-
$transport->send($this->createMock(MessageInterface::class));
36+
yield [new ChatMessage('Hello!')];
4237
}
4338

44-
public function testSendWithEmptyArrayResponseThrows()
39+
public function unsupportedMessagesProvider(): iterable
4540
{
46-
$this->expectException(TransportException::class);
41+
yield [new SmsMessage('0611223344', 'Hello!')];
42+
yield [$this->createMock(MessageInterface::class)];
43+
}
4744

45+
public function testSendWithEmptyArrayResponseThrowsTransportException()
46+
{
4847
$response = $this->createMock(ResponseInterface::class);
4948
$response->expects($this->exactly(2))
5049
->method('getStatusCode')
@@ -59,10 +58,12 @@ public function testSendWithEmptyArrayResponseThrows()
5958

6059
$transport = $this->createTransport($client);
6160

61+
$this->expectException(TransportException::class);
62+
6263
$transport->send(new ChatMessage('testMessage'));
6364
}
6465

65-
public function testSendWithErrorResponseThrows()
66+
public function testSendWithErrorResponseThrowsTransportException()
6667
{
6768
$this->expectException(TransportException::class);
6869
$this->expectExceptionMessage('testErrorCode');
@@ -189,9 +190,4 @@ public function testSendWithInvalidOptions()
189190

190191
$transport->send(new ChatMessage('testMessage', $this->createMock(MessageOptionsInterface::class)));
191192
}
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-
}
197193
}

0 commit comments

Comments
 (0)