Skip to content

Commit

Permalink
minor #48569 [Notifier] Add SMS options unit tests (gnito-org)
Browse files Browse the repository at this point in the history
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
-------

f62e9be16f [Notifier] Add SMS options unit tests
  • Loading branch information
nicolas-grekas committed May 12, 2023
2 parents ef316c2 + f59e96f commit 6ae5906
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
7 changes: 6 additions & 1 deletion PlivoOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public function setUrl(string $url): self

public function toArray(): array
{
return $this->options;
$options = $this->options;
if (isset($options['recipient_id'])) {
unset($options['recipient_id']);
}

return $options;
}
}
2 changes: 1 addition & 1 deletion PlivoTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __toString(): string

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

protected function doSend(MessageInterface $message): SentMessage
Expand Down
34 changes: 34 additions & 0 deletions Tests/PlivoOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Bridge\Plivo\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Plivo\PlivoOptions;

class PlivoOptionsTest extends TestCase
{
public function testPlivoOptions()
{
$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');

self::assertSame([
'log' => true,
'src' => 'test_src',
'method' => 'test_method',
'url' => 'test_url',
'media_urls' => 'test_media_urls',
'powerpack_uuid' => 'test_powerpack_uuid',
'trackable' => true,
'type' => 'test_type',
], $plivoOptions->toArray());
}
}
2 changes: 2 additions & 0 deletions Tests/PlivoTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Notifier\Bridge\Plivo\Tests;

use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Plivo\PlivoOptions;
use Symfony\Component\Notifier\Bridge\Plivo\PlivoTransport;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Message\ChatMessage;
Expand Down Expand Up @@ -39,6 +40,7 @@ public function invalidFromProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
yield [new SmsMessage('0611223344', 'Hello!', 'from', new PlivoOptions(['src' => 'foo']))];
}

/**
Expand Down

0 comments on commit 6ae5906

Please sign in to comment.