8000 minor #48569 [Notifier] Add SMS options unit tests (gnito-org) · symfony/symfony@34f81b9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 34f81b9

Browse files
minor #48569 [Notifier] Add SMS options unit tests (gnito-org)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Notifier] Add SMS options unit tests | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | | License | MIT | Doc PR | Add SMS options unit tests to the notifiers that I've previously contributed. Commits ------- f62e9be [Notifier] Add SMS options unit tests
2 parents f4659f8 + f62e9be commit 34f81b9

16 files changed

+167
-8
lines changed

src/Symfony/Component/Notifier/Bridge/Bandwidth/BandwidthOptions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public function setTo(array $to): self
135135

136136
public function toArray(): array
137137
{
138-
return $this->options;
138+
$options = $this->options;
139+
if (isset($options['recipient_id'])) {
140+
unset($options['recipient_id']);
141+
}
142+
143+
return $options;
139144
}
140145
}

src/Symfony/Component/Notifier/Bridge/Bandwidth/BandwidthTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __toString(): string
4949

5050
public function supports(MessageInterface $message): bool
5151
{
52-
return $message instanceof SmsMessage;
52+
return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof BandwidthOptions);
5353
}
5454

5555
/**
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Bandwidth\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Bandwidth\BandwidthOptions;
16+
17+
class BandwidthOptionsTest extends TestCase
18+
{
19+
public function testBandwidthOptions()
20+
{
21+
$bandwidthOptions = (new BandwidthOptions())->setFrom('test_from')->setRecipientId('test_recipient')->setMedia(['foo'])->setTo(['test_too'])->setTag('test_tag')->setAccountId('test_account_id')->setApplicationId('test_application_id')->setExpiration('test_expiration')->setPriority('test_priority');
22+
23+
self::assertSame([
24+
'from' => 'test_from',
25+
'media' => ['foo'],
26+
'to' => ['test_too'],
27+
'tag' => 'test_tag',
28+
'account_id' => 'test_account_id',
29+
'application_id' => 'test_application_id',
30+
'expiration' => 'test_expiration',
31+
'priority' => 'test_priority',
32+
], $bandwidthOptions->toArray());
33+
}
34+
}

src/Symfony/Component/Notifier/Bridge/Bandwidth/Tests/BandwidthTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Notifier\Bridge\Bandwidth\Tests;
1313

1414
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\Notifier\Bridge\Bandwidth\BandwidthOptions;
1516
use Symfony\Component\Notifier\Bridge\Bandwidth\BandwidthTransport;
1617
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1718
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -37,6 +38,7 @@ public function invalidFromProvider(): iterable
3738
public static function supportedMessagesProvider(): iterable
3839
{
3940
yield [new SmsMessage('0611223344', 'Hello!')];
41+
yield [new SmsMessage('0611223344', 'Hello!', 'from', new BandwidthOptions(['from' => 'from']))];
4042
}
4143

4244
/**

src/Symfony/Component/Notifier/Bridge/Plivo/PlivoOptions.php

Copy file name to clipboard
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public function setUrl(string $url): self
135135

136136
public function toArray(): array
137137
{
138-
return $this->options;
138+
$options = $this->options;
139+
if (isset($options['recipient_id'])) {
140+
unset($options['recipient_id']);
141+
}
142+
143+
return $options;
139144
}
140145
}

src/Symfony/Component/Notifier/Bridge/Plivo/PlivoTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __toString(): string
4747

4848
public function supports(MessageInterface $message): bool
4949
{
50-
return $message instanceof SmsMessage;
50+
return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof PlivoOptions);
5151
}
5252

5353
protected function doSend(MessageInterface $message): SentMessage
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Plivo\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Plivo\PlivoOptions;
16+
17+
class PlivoOptionsTest extends TestCase
18+
{
19+
public function testPlivoOptions()
20+
{
21+
$plivoOptions = (new PlivoOptions())->setRecipientId('test_recipient')->setLog(true)->setSrc('test_src')->setMethod('test_method')->setUrl('test_url')->setMediaUrls('test_media_urls')->setPowerpackUuid('test_powerpack_uuid')->setTrackable(true)->setType('test_type');
22+
23+
self::assertSame([
24+
'log' => true,
25+
'src' => 'test_src',
26+
'method' => 'test_method',
27+
'url' => 'test_url',
28+
'media_urls' => 'test_media_urls',
29+
'powerpack_uuid' => 'test_powerpack_uuid',
30+
'trackable' => true,
31+
'type' => 'test_type',
32+
], $plivoOptions->toArray());
33+
}
34+
}

src/Symfony/Component/Notifier/Bridge/Plivo/Tests/PlivoTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Notifier\Bridge\Plivo\Tests;
1313

1414
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\Notifier\Bridge\Plivo\PlivoOptions;
1516
use Symfony\Component\Notifier\Bridge\Plivo\PlivoTransport;
1617
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1718
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -39,6 +40,7 @@ public function invalidFromProvider(): iterable
3940
public static function supportedMessagesProvider(): iterable
4041
{
4142
yield [new SmsMessage('0611223344', 'Hello!')];
43+
yield [new SmsMessage('0611223344', 'Hello!', 'from', new PlivoOptions(['src' => 'foo']))];
4244
}
4345

4446
/**

src/Symfony/Component/Notifier/Bridge/RingCentral/RingCentralOptions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public function setRecipientId(string $id): self
111111

112112
public function toArray(): array
113113
{
114-
return $this->options;
114+
$options = $this->options;
115+
if (isset($options['recipient_id'])) {
116+
unset($options['recipient_id']);
117+
}
118+
119+
return $options;
115120
}
116121
}

src/Symfony/Component/Notifier/Bridge/RingCentral/RingCentralTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __toString(): string
4545

4646
public function supports(MessageInterface $message): bool
4747
{
48-
return $message instanceof SmsMessage;
48+
return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof RingCentralOptions);
4949
}
5050

5151
protected function doSend(MessageInterface $message): SentMessage
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier F438 \Bridge\RingCentral\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\RingCentral\RingCentralOptions;
16+
17+
class RingCentralOptionsTest extends TestCase
18+
{
19+
public function testRingCentralOptions()
20+
{
21+
$ringCentralOptions = (new RingCentralOptions())->setFrom('test_from')->setRecipientId('test_recipient')->setCountryId('test_country_id')->setCountryName('test_country_name')->setCountryUri('test_country_uri')->setCountryCallingCode('test_country_calling_code')->setCountryIsoCode('test_country_iso_code');
22+
23+
self::assertSame([
24+
'from' => 'test_from',
25+
'country_id' => 'test_country_id',
26+
'country_name' => 'test_country_name',
27+
'country_uri' => 'test_country_uri',
28+
'country_calling_code' => 'test_country_calling_code',
29+
'country_iso_code' => 'test_country_iso_code',
30+
], $ringCentralOptions->toArray());
31+
}
32+
}

src/Symfony/Component/Notifier/Bridge/RingCentral/Tests/RingCentralTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Notifier\Bridge\RingCentral\Tests;
1313

1414
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\Notifier\Bridge\RingCentral\RingCentralOptions;
1516
use Symfony\Component\Notifier\Bridge\RingCentral\RingCentralTransport;
1617
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1718
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -37,6 +38,7 @@ public static function invalidFromProvider(): iterable
3738
public static function supportedMessagesProvider(): iterable
3839
{
3940
yield [new SmsMessage('0611223344', 'Hello!')];
41+
yield [new SmsMessage('0611223344', 'Hello!', 'from', new RingCentralOptions(['from' => 'foo']))];
4042
}
4143

4244
/**

src/Symfony/Component/Notifier/Bridge/Termii/TermiiOptions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function setType(string $type): self
9999

100100
public function toArray(): array
101101
{
102-
return $this->options;
102+
$options = $this->options;
103+
if (isset($options['recipient_id'])) {
104+
unset($options['recipient_id']);
105+
}
106+
107+
return $options;
103108
}
104109
}

src/Symfony/Component/Notifier/Bridge/Termii/TermiiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __toString(): string
4747

4848
public function supports(MessageInterface $message): bool
4949
{
50-
return $message instanceof SmsMessage;
50+
return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof TermiiOptions);
5151
}
5252

5353
protected function doSend(MessageInterface $message): SentMessage
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Termii\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Termii\TermiiOptions;
16+
17+
class TermiiOptionsTest extends TestCase
18+
{
19+
public function testTermiiOptions()
20+
{
21+
$termiiOptions = (new TermiiOptions())->setFrom('test_from')->setRecipientId('test_recipient')->setType('test_type')->setChannel('test_channel')->setMediaCaption('test_media_caption')->setMediaUrl('test_media_url');
22+
23+
self::assertSame([
24+
'from' => 'test_from',
25+
'type' => 'test_type',
26+
'channel' => 'test_channel',
27+
'media_caption' => 'test_media_caption',
28+
'media_url' => 'test_media_url',
29+
], $termiiOptions->toArray());
30+
}
31+
}

src/Symfony/Component/Notifier/Bridge/Termii/Tests/TermiiTransportTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Notifier\Bridge\Termii\Tests;
1313

1414
use Symfony\Component\HttpClient\MockHttpClient;
15+
use Symfony\Component\Notifier\Bridge\Termii\TermiiOptions;
1516
use Symfony\Component\Notifier\Bridge\Termii\TermiiTransport;
1617
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1718
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -39,6 +40,7 @@ public static function invalidFromProvider(): iterable
3940
public static function supportedMessagesProvider(): iterable
4041
{
4142
yield [new SmsMessage('0611223344', 'Hello!')];
43+
yield [new SmsMessage('0611223344', 'Hello!', 'from', new TermiiOptions(['from' => 'foo']))];
4244
}
4345

4446
/**

0 commit comments

Comments
 (0)
0