Skip to content

Commit c4fca76

Browse files
OskarStarkderrabus
authored andcommitted
[Notifier] Use abstract test cases in 5.x
1 parent 3df8b97 commit c4fca76

File tree

2 files changed

+46
-94
lines changed

2 files changed

+46
-94
lines changed

Tests/EsendexTransportFactoryTest.php

Lines changed: 26 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,94 +11,50 @@
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\MissingRequiredOptionException;
18-
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
19-
use Symfony\Component\Notifier\Transport\Dsn;
15+
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
16+
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
2017

21-
final class EsendexTransportFactoryTest extends TestCase
18+
final class EsendexTransportFactoryTest extends TransportFactoryTestCase
2219
{
23-
public function testCreateWithDsn()
20+
/**
21+
* @return EsendexTransportFactory
22+
*/
23+
public function createFactory(): TransportFactoryInterface
2424
{
25-
$factory = $this->createFactory();
26-
27-
$transport = $factory->create(Dsn::fromString('esendex://email:password@host.test?accountreference=testAccountreference&from=testFrom'));
28-
29-
$this->assertSame('esendex://host.test?accountreference=testAccountreference&from=testFrom', (string) $transport);
30-
}
31-
32-
public function testCreateWithMissingEmailThrowsIncompleteDsnException()
33-
{
34-
$factory = $this->createFactory();
35-
36-
$this->expectException(IncompleteDsnException::class);
37-
38-
$factory->create(Dsn::fromString('esendex://:password@host?accountreference=testAccountreference&from=FROM'));
39-
}
40-
41-
public function testCreateWithMissingPasswordThrowsIncompleteDsnException()
42-
{
43-
$factory = $this->createFactory();
44-
45-
$this->expectException(IncompleteDsnException::class);
46-
47-
$factory->create(Dsn::fromString('esendex://email:@host?accountreference=testAccountreference&from=FROM'));
48-
}
49-
50-
public function testCreateWithMissingOptionAccountreferenceThrowsMissingRequiredOptionException()
51-
{
52-
$factory = $this->createFactory();
53-
54-
$this->expectException(MissingRequiredOptionException::class);
55-
56-
$factory->create(Dsn::fromString('esendex://email:password@host?from=FROM'));
57-
}
58-
59-
public function testCreateWithMissingOptionFromThrowsMissingRequiredOptionException()
60-
{
61-
$factory = $this->createFactory();
62-
63-
$this->expectException(MissingRequiredOptionException::class);
64-
65-
$factory->create(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE'));
25+
return new EsendexTransportFactory();
6626
}
6727

68-
public function testSupportsReturnsTrueWithSupportedScheme()
28+
public function createProvider(): iterable
6929
{
70-
$factory = $this->createFactory();
71-
72-
$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+
];
7334
}
7435

75-
public function testSupportsReturnsFalseWithUnsupportedScheme()
36+
public function supportsProvider(): iterable
7637
{
77-
$factory = $this->createFactory();
78-
79-
$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'];
8040
}
8141

82-
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
42+
public function incompleteDsnProvider(): iterable
8343
{
84-
$factory = $this->createFactory();
85-
86-
$this->expectException(UnsupportedSchemeException::class);
87-
$factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE&from=FROM'));
44+
yield 'missing credentials' => ['esendex://host?accountreference=ACCOUNTREFERENCE&from=FROM'];
45+
yield 'missing email' => ['esendex://:password@host?accountreference=ACCOUNTREFERENCE&from=FROM'];
46+
yield 'missing password' => ['esendex://email:@host?accountreference=ACCOUNTREFERENCE&from=FROM'];
8847
}
8948

90-
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
49+
public function missingRequiredOptionProvider(): iterable
9150
{
92-
$factory = $this->createFactory();
93-
94-
$this->expectException(UnsupportedSchemeException::class);
95-
96-
// unsupported scheme and missing "from" option
97-
$factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE'));
51+
yield 'missing option: from' => ['esendex://email:password@host?accountreference=ACCOUNTREFERENCE'];
52+
yield 'missing option: accountreference' => ['esendex://email:password@host?from=FROM'];
9853
}
9954

100-
private function createFactory(): EsendexTransportFactory
55+
public function unsupportedSchemeProvider(): iterable
10156
{
102-
return new EsendexTransportFactory();
57+
yield ['somethingElse://email:password@default?accountreference=ACCOUNTREFERENCE&from=FROM'];
58+
yield ['somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE']; // missing "from" option
10359
}
10460
}

Tests/EsendexTransportTest.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +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;
1716
use Symfony\Component\Notifier\Exception\TransportException;
18-
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
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?accountreference=testAccountReference&from=testFrom', (string) $transport);
32+
return (new EsendexTransport('email', 'password', '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();
44-
45-
$this->expectException(UnsupportedMessageTypeException::class);
42+
yield [new SmsMessage('0611223344', 'Hello!')];
43+
}
4644

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

50-
public function testSendWithErrorResponseThrows()
51+
public function testSendWithErrorResponseThrowsTransportException()
5152
{
5253
$response = $this->createMock(ResponseInterface::class);
5354
$response->expects($this->exactly(2))
@@ -66,7 +67,7 @@ public function testSendWithErrorResponseThrows()
6667
$transport->send(new SmsMessage('phone', 'testMessage'));
6768
}
6869

69-
public function testSendWithErrorResponseContainingDetailsThrows()
70+
public function testSendWithErrorResponseContainingDetailsThrowsTransportException()
7071
{
7172
$response = $this->createMock(ResponseInterface::class);
7273
$response->expects($this->exactly(2))
@@ -87,9 +88,4 @@ public function testSendWithErrorResponseContainingDetailsThrows()
8788

8889
$transport->send(new SmsMessage('phone', 'testMessage'));
8990
}
90-
91-
private function createTransport(?HttpClientInterface $client = null): EsendexTransport
92-
{
93-
return (new EsendexTransport('testEmail', 'testPassword', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
94-
}
9591
}

0 commit comments

Comments
 (0)