Skip to content

Commit b74ac9c

Browse files
committed
Added test for TwilioConfig class
1 parent 983b372 commit b74ac9c

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

tests/Unit/TwilioConfigTest.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
namespace NotificationChannels\Twilio\Tests\Unit;
4+
5+
use NotificationChannels\Twilio\TwilioConfig;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class TwilioConfigTest extends TestCase
9+
{
10+
private function config(array $config = []): TwilioConfig
11+
{
12+
return new TwilioConfig($config);
13+
}
14+
15+
/** @test */
16+
public function it_returns_a_boolean_wether_it_is_is_enabled_or_not()
17+
{
18+
$this->assertTrue($this->config()->enabled()); // defaults to true
19+
$this->assertTrue($this->config(['enabled' => true])->enabled());
20+
$this->assertFalse($this->config(['enabled' => false])->enabled());
21+
}
22+
23+
/** @test */
24+
public function it_defaults_to_null_for_config_keys_with_a_string_return_type()
25+
{
26+
$config = $this->config();
27+
28+
$this->assertNull($config->getAuthToken());
29+
$this->assertNull($config->getUsername());
30+
$this->assertNull($config->getPassword());
31+
$this->assertNull($config->getAccountSid());
32+
$this->assertNull($config->getFrom());
33+
$this->assertNull($config->getAlphanumericSender());
34+
$this->assertNull($config->getServiceSid());
35+
$this->assertNull($config->getDebugTo());
36+
}
37+
38+
/** @test */
39+
public function it_returns_a_string_for_config_keys_with_a_string_return_type()
40+
{
41+
$config = $this->config([
42+
'auth_token' => 'valid-auth-token',
43+
'username' => 'valid-username',
44+
'password' => 'valid-password',
45+
'account_sid' => 'valid-account-sid',
46+
'from' => 'valid-from',
47+
'alphanumeric_sender' => 'valid-alphanumeric-sender',
48+
'sms_service_sid' => 'valid-sms-service-sid',
49+
'debug_to' => 'valid-debug-to',
50+
]);
51+
52+
$this->assertEquals('valid-auth-token', $config->getAuthToken());
53+
$this->assertEquals('valid-username', $config->getUsername());
54+
$this->assertEquals('valid-password', $config->getPassword());
55+
$this->assertEquals('valid-account-sid', $config->getAccountSid());
56+
$this->assertEquals('valid-from', $config->getFrom());
57+
$this->assertEquals('valid-alphanumeric-sender', $config->getAlphanumericSender());
58+
$this->assertEquals('valid-sms-service-sid', $config->getServiceSid());
59+
$this->assertEquals('valid-debug-to', $config->getDebugTo());
60+
}
61+
62+
/** @test */
63+
public function it_returns_an_array_of_ignored_codes()
64+
{
65+
$this->assertEquals([], $this->config()->getIgnoredErrorCodes()); // defaults to empty array
66+
$this->assertEquals([1, 2], $this->config(['ignored_error_codes' => [1, 2]])->getIgnoredErrorCodes());
67+
}
68+
69+
/** @test */
70+
public function it_returns_a_boolean_wether_the_error_code_is_ignored_or_not()
71+
{
72+
$config = $this->config(['ignored_error_codes' => [1, 2]]);
73+
$this->assertTrue($config->isIgnoredErrorCode(1));
74+
$this->assertTrue($config->isIgnoredErrorCode(2));
75+
$this->assertFalse($config->isIgnoredErrorCode(3));
76+
77+
$config = $this->config(['ignored_error_codes' => ['*']]);
78+
$this->assertTrue($config->isIgnoredErrorCode(1));
79+
$this->assertTrue($config->isIgnoredErrorCode(2));
80+
$this->assertTrue($config->isIgnoredErrorCode(3));
81+
}
82+
83+
/** @test */
84+
public function it_returns_a_boolean_wether_shorten_urls_is_enabled_or_not()
85+
{
86+
$this->assertFalse($this->config()->isShortenUrlsEnabled()); // defaults to false
87+
$this->assertTrue($this->config(['shorten_urls' => true])->isShortenUrlsEnabled());
88+
$this->assertFalse($this->config(['shorten_urls' => false])->isShortenUrlsEnabled());
89+
}
90+
91+
/** @test */
92+
public function it_returns_a_boolean_wether_token_auth_is_used_or_not()
93+
{
94+
// No values set...
95+
$this->assertFalse($this->config()->usingTokenAuth());
96+
97+
// One value set...
98+
$this->assertFalse($this->config(['auth_token' => 'valid'])->usingTokenAuth());
99+
$this->assertFalse($this->config(['account_sid' => 'valid'])->usingTokenAuth());
100+
101+
// Both values set...
102+
$this->assertTrue($this->config(['auth_token' => 'valid', 'account_sid' => 'valid'])->usingTokenAuth());
103+
}
104+
105+
/** @test */
106+
public function it_returns_a_boolean_wether_username_password_auth_is_used_or_not()
107+
{
108+
// No values set...
109+
$this->assertFalse($this->config()->usingUsernamePasswordAuth());
110+
111+
// One value set...
112+
$this->assertFalse($this->config(['username' => 'valid'])->usingUsernamePasswordAuth());
113+
$this->assertFalse($this->config(['password' => 'valid'])->usingUsernamePasswordAuth());
114+
$this->assertFalse($this->config(['account_sid' => 'valid'])->usingUsernamePasswordAuth());
115+
116+
// Two values set...
117+
$this->assertFalse($this->config(['username' => 'valid', 'password' => 'valid'])->usingUsernamePasswordAuth());
118+
$this->assertFalse($this->config(['username' => 'valid', 'account_sid' => 'valid'])->usingUsernamePasswordAuth());
119+
$this->assertFalse($this->config(['password' => 'valid', 'account_sid' => 'valid'])->usingUsernamePasswordAuth());
120+
121+
// All values set...
122+
$this->assertTrue($this->config(['username' => 'valid', 'password' => 'valid', 'account_sid' => 'valid'])->usingUsernamePasswordAuth());
123+
}
124+
}

0 commit comments

Comments
 (0)