Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cc3dead

Browse filesBrowse files
add iqsms tests
1 parent 4412bd6 commit cc3dead
Copy full SHA for cc3dead

File tree

2 files changed

+134
-0
lines changed
Filter options

2 files changed

+134
-0
lines changed
+83Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\Iqsms\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
16+
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
17+
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
18+
use Symfony\Component\Notifier\Transport\Dsn;
19+
20+
final class IqsmsTransportFactoryTest extends TestCase
21+
{
22+
public function testCreateWithDsn()
23+
{
24+
$factory = $this->createFactory();
25+
26+
$dsn = 'iqsms://login:password@defaultf?from=some';
27+
$transport = $factory->create(Dsn::fromString($dsn));
28+
$transport->setHost('host.test');
29+
30+
$this->assertSame('iqsms://host.test?from=some', (string) $transport);
31+
}
32+
33+
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
34+
{
35+
$factory = $this->createFactory();
36+
37+
$this->expectException(IncompleteDsnException::class);
38+
39+
$dsnIncomplete = 'iqsms://login:password@default';
40+
$factory->create(Dsn::fromString($dsnIncomplete));
41+
}
42+
43+
public function testSupportsReturnsTrueWithSupportedScheme()
44+
{
45+
$factory = $this->createFactory();
46+
47+
$dsn = 'iqsms://login:password@default?from=some';
48+
$this->assertTrue($factory->supports(Dsn::fromString($dsn)));
49+
}
50+
51+
public function testSupportsReturnsFalseWithUnsupportedScheme()
52+
{
53+
$factory = $this->createFactory();
54+
55+
$dsnUnsupported = 'iiqsms://login:password@default?from=some';
56+
$this->assertFalse($factory->supports(Dsn::fromString($dsnUnsupported)));
57+
}
58+
59+
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
60+
{
61+
$factory = $this->createFactory();
62+
63+
$this->expectException(UnsupportedSchemeException::class);
64+
65+
$dsnUnsupported = 'iiqsms://login:password@default?from=some';
66+
$factory->create(Dsn::fromString($dsnUnsupported));
67+
}
68+
69+
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
70+
{
71+
$factory = $this->createFactory();
72+
73+
$this->expectException(UnsupportedSchemeException::class);
74+
75+
// unsupported scheme and missing "from" option
76+
$factory->create(Dsn::fromString('iiqsms://login:password@default'));
77+
}
78+
79+
private function createFactory(): IqsmsTransportFactory
80+
{
81+
return new IqsmsTransportFactory();
82+
}
83+
}
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Iqsms\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransport;
16+
use Symfony\Component\Notifier\Exception\LogicException;
17+
use Symfony\Component\Notifier\Message\MessageInterface;
18+
use Symfony\Component\Notifier\Message\SmsMessage;
19+
use Symfony\Contracts\HttpClient\HttpClientInterface;
20+
21+
final class IqsmsTransportTest extends TestCase
22+
{
23+
public function testToStringContainsProperties()
24+
{
25+
$transport = $this->createTransport();
26+
27+
$this->assertSame('iqsms://host.test?from=sender', (string) $transport);
28+
}
29+
30+
public function testSupportsMessageInterface()
31+
{
32+
$transport = $this->createTransport();
33+
34+
$this->assertTrue($transport->supports(new SmsMessage('9031223344', 'Hello!')));
35+
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
36+
}
37+
38+
public function testSendNonSmsMessageThrowsException()
39+
{
40+
$transport = $this->createTransport();
41+
42+
$this->expectException(LogicException::class);
43+
44+
$transport->send($this->createMock(MessageInterface::class));
45+
}
46+
47+
private function createTransport(): IqsmsTransport
48+
{
49+
return (new IqsmsTransport('login', 'password', 'sender', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
50+
}
51+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.