Skip to content

Commit 07c6c43

Browse files
minor #39736 [Notifier] Use abstract test cases in 5.2 (OskarStark)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [Notifier] Use abstract test cases in 5.2 | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Follows #39495 | License | MIT | Doc PR | --- Same as #39495, but for `5.2` cc @derrabus Commits ------- 8f6b08c [Notifier] Use abstract test cases in 5.2
2 parents 18002e2 + 8f6b08c commit 07c6c43

34 files changed

+510
-646
lines changed

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportFactoryTest.php

+22-53
Original file line numberDiff line numberDiff line change
@@ -11,74 +11,43 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord\Tests;
1313

14-
use PHPUnit\Framework\TestCase;
1514
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransportFactory;
16-
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
17-
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
18-
use Symfony\Component\Notifier\Transport\Dsn;
15+
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
16+
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
1917

20-
final class DiscordTransportFactoryTest extends TestCase
18+
final class DiscordTransportFactoryTest extends TransportFactoryTestCase
2119
{
22-
public function testCreateWithDsn()
20+
/**
21+
* @return DiscordTransportFactory
22+
*/
23+
public function createFactory(): TransportFactoryInterface
2324
{
24-
$factory = $this->createFactory();
25-
26-
$transport = $factory->create(Dsn::fromString('discord://token@host.test?webhook_id=testWebhookId'));
27-
28-
$this->assertSame('discord://host.test?webhook_id=testWebhookId', (string) $transport);
29-
}
30-
31-
public function testCreateWithMissingOptionWebhookIdThrowsIncompleteDsnException()
32-
{
33-
$factory = $this->createFactory();
34-
35-
$this->expectException(IncompleteDsnException::class);
36-
37-
$factory->create(Dsn::fromString('discord://token@host'));
38-
}
39-
40-
public function testCreateWithNoTokenThrowsIncompleteDsnException()
41-
{
42-
$factory = $this->createFactory();
43-
44-
$this->expectException(IncompleteDsnException::class);
45-
$factory->create(Dsn::fromString('discord://host.test?webhook_id=testWebhookId'));
46-
}
47-
48-
public function testSupportsReturnsTrueWithSupportedScheme()
49-
{
50-
$factory = $this->createFactory();
51-
52-
$this->assertTrue($factory->supports(Dsn::fromString('discord://host?webhook_id=testWebhookId')));
25+
return new DiscordTransportFactory();
5326
}
5427

55-
public function testSupportsReturnsFalseWithUnsupportedScheme()
28+
public function createProvider(): iterable
5629
{
57-
$factory = $this->createFactory();
58-
59-
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?webhook_id=testWebhookId')));
30+
yield [
31+
'discord://host.test?webhook_id=testWebhookId',
32+
'discord://token@host.test?webhook_id=testWebhookId',
33+
];
6034
}
6135

62-
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
36+
public function supportsProvider(): iterable
6337
{
64-
$factory = $this->createFactory();
65-
66-
$this->expectException(UnsupportedSchemeException::class);
67-
$factory->create(Dsn::fromString('somethingElse://token@host?webhook_id=testWebhookId'));
38+
yield [true, 'discord://host?webhook_id=testWebhookId'];
39+
yield [false, 'somethingElse://host?webhook_id=testWebhookId'];
6840
}
6941

70-
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
42+
public function incompleteDsnProvider(): iterable
7143
{
72-
$factory = $this->createFactory();
73-
74-
$this->expectException(UnsupportedSchemeException::class);
75-
76-
// unsupported scheme and missing "webhook_id" option
77-
$factory->create(Dsn::fromString('somethingElse://token@host'));
44+
yield 'missing token' => ['discord://host.test?webhook_id=testWebhookId'];
45+
yield 'missing option: webhook_id' => ['discord://token@host'];
7846
}
7947

80-
private function createFactory(): DiscordTransportFactory
48+
public function unsupportedSchemeProvider(): iterable
8149
{
82-
return new DiscordTransportFactory();
50+
yield ['somethingElse://token@host?webhook_id=testWebhookId'];
51+
yield ['somethingElse://token@host']; // missing "webhook_id" option
8352
}
8453
}

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php

+18-21
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,42 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord\Tests;
1313

14-
use PHPUnit\Framework\TestCase;
1514
use Symfony\Component\HttpClient\MockHttpClient;
1615
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport;
1716
use Symfony\Component\Notifier\Exception\LogicException;
1817
use Symfony\Component\Notifier\Exception\TransportException;
1918
use Symfony\Component\Notifier\Message\ChatMessage;
2019
use Symfony\Component\Notifier\Message\MessageInterface;
20+
use Symfony\Component\Notifier\Message\SmsMessage;
21+
use Symfony\Component\Notifier\Tests\TransportTestCase;
22+
use Symfony\Component\Notifier\Transport\TransportInterface;
2123
use Symfony\Contracts\HttpClient\HttpClientInterface;
2224
use Symfony\Contracts\HttpClient\ResponseInterface;
2325

24-
final class DiscordTransportTest extends TestCase
26+
final class DiscordTransportTest extends TransportTestCase
2527
{
26-
public function testToStringContainsProperties()
28+
/**
29+
* @return DiscordTransport
30+
*/
31+
public function createTransport(?HttpClientInterface $client = null): TransportInterface
2732
{
28-
$transport = $this->createTransport();
29-
30-
$this->assertSame('discord://host.test?webhook_id=testWebhookId', (string) $transport);
33+
return (new DiscordTransport('testToken', 'testWebhookId', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
3134
}
3235

33-
public function testSupportsChatMessage()
36+
public function toStringProvider(): iterable
3437
{
35-
$transport = $this->createTransport();
36-
37-
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
38-
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
38+
yield ['discord://host.test?webhook_id=testWebhookId', $this->createTransport()];
3939
}
4040

41-
public function testSendNonChatMessageThrowsLogicException()
41+
public function supportedMessagesProvider(): iterable
4242
{
43-
$transport = $this->createTransport();
44-
45-
$this->expectException(LogicException::class);
43+
yield [new ChatMessage('Hello!')];
44+
}
4645

47-
$transport->send($this->createMock(MessageInterface::class));
46+
public function unsupportedMessagesProvider(): iterable
47+
{
48+
yield [new SmsMessage('0611223344', 'Hello!')];
49+
yield [$this->createMock(MessageInterface::class)];
4850
}
4951

5052
public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
@@ -78,9 +80,4 @@ public function testSendWithErrorResponseThrows()
7880

7981
$transport->send(new ChatMessage('testMessage'));
8082
}
81-
82-
private function createTransport(?HttpClientInterface $client = null): DiscordTransport
83-
{
84-
return (new DiscordTransport('testToken', 'testWebhookId', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
85-
}
8683
}

src/Symfony/Component/Notifier/Bridge/Discord/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.3|^5.0",
21-
"symfony/notifier": "~5.2.0",
21+
"symfony/notifier": "~5.2.2",
2222
"symfony/polyfill-mbstring": "^1.0"
2323
},
2424
"require-dev": {

src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(string $token, string $accountReference, string $fro
4444

4545
public function __toString(): string
4646
{
47-
return sprintf('esendex://%s', $this->getEndpoint());
47+
return sprintf('esendex://%s?accountreference=%s&from=%s', $this->getEndpoint(), $this->accountReference, $this->from);
4848
}
4949

5050
public function supports(MessageInterface $message): bool

src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportFactoryTest.php

+22-54
Original file line numberDiff line numberDiff line change
@@ -11,75 +11,43 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Esendex\Tests;
1313

14-
use PHPUnit\Framework\TestCase;
1514
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
16-
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
17-
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
18-
use Symfony\Component\Notifier\Transport\Dsn;
15+
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
16+
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
1917

20-
final class EsendexTransportFactoryTest extends TestCase
18+
final class EsendexTransportFactoryTest extends TransportFactoryTestCase
2119
{
22-
public function testCreateWithDsn()
20+
/**
21+
* @return EsendexTransportFactory
22+
*/
23+
public function createFactory(): TransportFactoryInterface
2324
{
24-
$factory = $this->createFactory();
25-
26-
$transport = $factory->create(Dsn::fromString('esendex://email:password@host.test?accountreference=testAccountreference&from=testFrom'));
27-
28-
$this->assertSame('esendex://host.test', (string) $transport);
29-
}
30-
31-
public function testCreateWithMissingOptionAccountreferenceThrowsIncompleteDsnException()
32-
{
33-
$factory = $this->createFactory();
34-
35-
$this->expectException(IncompleteDsnException::class);
36-
37-
$factory->create(Dsn::fromString('esendex://email:password@host?from=FROM'));
38-
}
39-
40-
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
41-
{
42-
$factory = $this->createFactory();
43-
44-
$this->expectException(IncompleteDsnException::class);
45-
46-
$factory->create(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE'));
25+
return new EsendexTransportFactory();
4726
}
4827

49-
public function testSupportsReturnsTrueWithSupportedScheme()
28+
public function createProvider(): iterable
5029
{
51-
$factory = $this->createFactory();
52-
53-
$this->assertTrue($factory->supports(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM')));
30+
yield [
31+
'esendex://host.test?accountreference=ACCOUNTREFERENCE&from=FROM',
32+
'esendex://email:password@host.test?accountreference=ACCOUNTREFERENCE&from=FROM',
33+
];
5434
}
5535

56-
public function testSupportsReturnsFalseWithUnsupportedScheme()
36+
public function supportsProvider(): iterable
5737
{
58-
$factory = $this->createFactory();
59-
60-
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM')));
38+
yield [true, 'esendex://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM'];
39+
yield [false, 'somethingElse://email:password@default'];
6140
}
6241

63-
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
42+
public function incompleteDsnProvider(): iterable
6443
{
65-
$factory = $this->createFactory();
66-
67-
$this->expectException(UnsupportedSchemeException::class);
68-
$factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE&from=FROM'));
44+
yield 'missing option: from' => ['esendex://email:password@host?accountreference=ACCOUNTREFERENCE'];
45+
yield 'missing option: accountreference' => ['esendex://email:password@host?from=FROM'];
6946
}
7047

71-
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
48+
public function unsupportedSchemeProvider(): iterable
7249
{
73-
$factory = $this->createFactory();
74-
75-
$this->expectException(UnsupportedSchemeException::class);
76-
77-
// unsupported scheme and missing "from" option
78-
$factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE'));
79-
}
80-
81-
private function createFactory(): EsendexTransportFactory
82-
{
83-
return new EsendexTransportFactory();
50+
yield ['somethingElse://email:password@default?accountreference=ACCOUNTREFERENCE&from=FROM'];
51+
yield ['somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE']; // missing "from" option
8452
}
8553
}

src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php

+20-23
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,44 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Esendex\Tests;
1313

14-
use PHPUnit\Framework\TestCase;
1514
use Symfony\Component\HttpClient\MockHttpClient;
1615
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
17-
use Symfony\Component\Notifier\Exception\LogicException;
1816
use Symfony\Component\Notifier\Exception\TransportException;
17+
use Symfony\Component\Notifier\Message\ChatMessage;
1918
use Symfony\Component\Notifier\Message\MessageInterface;
2019
use Symfony\Component\Notifier\Message\SmsMessage;
20+
use Symfony\Component\Notifier\Tests\TransportTestCase;
21+
use Symfony\Component\Notifier\Transport\TransportInterface;
2122
use Symfony\Contracts\HttpClient\HttpClientInterface;
2223
use Symfony\Contracts\HttpClient\ResponseInterface;
2324

24-
final class EsendexTransportTest extends TestCase
25+
final class EsendexTransportTest extends TransportTestCase
2526
{
26-
public function testToString()
27+
/**
28+
* @return EsendexTransport
29+
*/
30+
public function createTransport(?HttpClientInterface $client = null): TransportInterface
2731
{
28-
$transport = $this->createTransport();
29-
30-
$this->assertSame('esendex://host.test', (string) $transport);
32+
return (new EsendexTransport('testToken', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
3133
}
3234

33-
public function testSupportsSmsMessage()
35+
public function toStringProvider(): iterable
3436
{
35-
$transport = $this->createTransport();
36-
37-
$this->assertTrue($transport->supports(new SmsMessage('phone', 'testSmsMessage')));
38-
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
37+
yield ['esendex://host.test?accountreference=testAccountReference&from=testFrom', $this->createTransport()];
3938
}
4039

41-
public function testSendNonSmsMessageThrowsLogicException()
40+
public function supportedMessagesProvider(): iterable
4241
{
43-
$transport = $this->createTransport();
42+
yield [new SmsMessage('0611223344', 'Hello!')];
43+
}
4444

45-
$this->expectException(LogicException::class);
46-
$transport->send($this->createMock(MessageInterface::class));
45+
public function unsupportedMessagesProvider(): iterable
46+
{
47+
yield [new ChatMessage('Hello!')];
48+
yield [$this->createMock(MessageInterface::class)];
4749
}
4850

49-
public function testSendWithErrorResponseThrows()
51+
public function testSendWithErrorResponseThrowsTransportException()
5052
{
5153
$response = $this->createMock(ResponseInterface::class);
5254
$response->expects($this->exactly(2))
@@ -65,7 +67,7 @@ public function testSendWithErrorResponseThrows()
6567
$transport->send(new SmsMessage('phone', 'testMessage'));
6668
}
6769

68-
public function testSendWithErrorResponseContainingDetailsThrows()
70+
public function testSendWithErrorResponseContainingDetailsThrowsTransportException()
6971
{
7072
$response = $this->createMock(ResponseInterface::class);
7173
$response->expects($this->exactly(2))
@@ -86,9 +88,4 @@ public function testSendWithErrorResponseContainingDetailsThrows()
8688

8789
$transport->send(new SmsMessage('phone', 'testMessage'));
8890
}
89-
90-
private function createTransport(?HttpClientInterface $client = null): EsendexTransport
91-
{
92-
return (new EsendexTransport('testToken', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
93-
}
9491
}

src/Symfony/Component/Notifier/Bridge/Esendex/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.4|^5.0",
21-
"symfony/notifier": "~5.2.0"
21+
"symfony/notifier": "~5.2.2"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Esendex\\": "" },

src/Symfony/Component/Notifier/Bridge/GoogleChat/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ where:
1414
- `ACCESS_KEY` is your Google Chat access key
1515
- `ACCESS_TOKEN` is your Google Chat access token
1616
- `SPACE` is the Google Chat space
17-
- `THREAD_KEY` is the the Google Chat message thread to group messages into a single thread (optional)
17+
- `THREAD_KEY` is the Google Chat message thread to group messages into a single thread (optional)
1818

1919
Resources
2020
---------

src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatOptionsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
1616

17-
class GoogleChatOptionsTest extends TestCase
17+
final class GoogleChatOptionsTest extends TestCase
1818
{
1919
public function testToArray()
2020
{

0 commit comments

Comments
 (0)