Skip to content

Commit

Permalink
Updated tests to native php attributes from doc-comment metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mani-hash committed Feb 28, 2025
1 parent beb9b27 commit 1305258
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 59 deletions.
11 changes: 6 additions & 5 deletions tests/Integration/TwilioProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioConfig;
use NotificationChannels\Twilio\TwilioProvider;
use PHPUnit\Framework\Attributes\Test;
use Twilio\Rest\Client;

class TwilioProviderTest extends IntegrationTestCase
{
/** @test */
#[Test]
public function it_cannot_create_the_application_without_config()
{
$this->expectException(InvalidConfigException::class);

$this->app->get(TwilioChannel::class);
}

/** @test */
#[Test]
public function it_cannot_create_the_application_without_sid()
{
$this->app['config']->set('twilio-notification-channel.username', 'test');
Expand All @@ -31,7 +32,7 @@ public function it_cannot_create_the_application_without_sid()
$this->app->get(TwilioChannel::class);
}

/** @test */
#[Test]
public function it_can_create_the_application_with_sid()
{
$this->app['config']->set('twilio-notification-channel.username', 'test');
Expand All @@ -41,7 +42,7 @@ public function it_can_create_the_application_with_sid()
$this->assertInstanceOf(TwilioChannel::class, $this->app->get(TwilioChannel::class));
}

/** @test */
#[Test]
public function it_can_create_the_application_with_token_auth()
{
$this->app['config']->set('twilio-notification-channel.auth_token', 'token');
Expand All @@ -50,7 +51,7 @@ public function it_can_create_the_application_with_token_auth()
$this->assertInstanceOf(TwilioChannel::class, $this->app->get(TwilioChannel::class));
}

/** @test */
#[Test]
public function it_provides_three_classes()
{
$provides = (new TwilioProvider($this->app))->provides();
Expand Down
13 changes: 7 additions & 6 deletions tests/Unit/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioConfig;
use NotificationChannels\Twilio\TwilioSmsMessage;
use PHPUnit\Framework\Attributes\Test;
use Twilio\Rest\Api\V2010\Account\CallInstance;
use Twilio\Rest\Api\V2010\Account\CallList;
use Twilio\Rest\Api\V2010\Account\MessageInstance;
Expand Down Expand Up @@ -42,7 +43,7 @@ protected function setUp(): void
$this->notification = Mockery::mock(Notification::class);
}

/** @test */
#[Test]
public function it_can_send_a_sms_message()
{
$message = TwilioSmsMessage::create('Message text');
Expand All @@ -62,7 +63,7 @@ public function it_can_send_a_sms_message()
$channel->send(new NotifiableWithAttribute, $this->notification);
}

/** @test */
#[Test]
public function it_can_send_a_sms_message_using_service()
{
$message = TwilioSmsMessage::create('Message text');
Expand All @@ -84,7 +85,7 @@ public function it_can_send_a_sms_message_using_service()
$channel->send(new NotifiableWithAttribute, $this->notification);
}

/** @test */
#[Test]
public function it_can_send_a_sms_message_using_url_shortener()
{
$message = TwilioSmsMessage::create('Message text');
Expand All @@ -106,7 +107,7 @@ public function it_can_send_a_sms_message_using_url_shortener()
$channel->send(new NotifiableWithAttribute, $this->notification);
}

/** @test */
#[Test]
public function it_can_send_a_sms_message_using_alphanumeric_sender()
{
$message = TwilioSmsMessage::create('Message text');
Expand All @@ -127,7 +128,7 @@ public function it_can_send_a_sms_message_using_alphanumeric_sender()
$channel->send(new NotifiableWithAlphanumericSender, $this->notification);
}

/** @test */
#[Test]
public function it_can_make_a_call()
{
$message = TwilioCallMessage::create('http://example.com');
Expand All @@ -146,7 +147,7 @@ public function it_can_make_a_call()
$channel->send(new NotifiableWithAttribute, $this->notification);
}

/** @test */
#[Test]
public function it_cant_make_a_call_when_the_from_config_is_missing()
{
$message = TwilioCallMessage::create('http://example.com');
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/TwilioCallMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NotificationChannels\Twilio\Tests\Unit;

use NotificationChannels\Twilio\TwilioCallMessage;
use PHPUnit\Framework\Attributes\Test;

class TwilioCallMessageTest extends TwilioMessageTestCase
{
Expand All @@ -16,31 +17,31 @@ protected function setUp(): void
$this->message = new TwilioCallMessage;
}

/** @test */
#[Test]
public function it_can_accept_a_message_when_constructing_a_message()
{
$message = new TwilioCallMessage('http://example.com');

$this->assertEquals('http://example.com', $message->content);
}

/** @test */
#[Test]
public function it_provides_a_create_method()
{
$message = TwilioCallMessage::create('http://example.com');

$this->assertEquals('http://example.com', $message->content);
}

/** @test */
#[Test]
public function it_can_set_the_url()
{
$this->message->url('http://example.com');

$this->assertEquals('http://example.com', $this->message->content);
}

/** @test */
#[Test]
public function it_can_set_optional_parameters()
{
$message = TwilioCallMessage::create('myMessage');
Expand Down
23 changes: 12 additions & 11 deletions tests/Unit/TwilioChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioConfig;
use NotificationChannels\Twilio\TwilioSmsMessage;
use PHPUnit\Framework\Attributes\Test;
use Twilio\Exceptions\RestException;

class TwilioChannelTest extends MockeryTestCase
Expand All @@ -37,7 +38,7 @@ protected function setUp(): void
$this->channel = new TwilioChannel($this->twilio, $this->dispatcher);
}

/** @test */
#[Test]
public function it_will_not_send_a_message_if_not_enabled()
{
$notifiable = new Notifiable;
Expand All @@ -54,7 +55,7 @@ public function it_will_not_send_a_message_if_not_enabled()
$this->assertNull($result);
}

/** @test */
#[Test]
public function it_will_not_send_a_message_without_known_receiver()
{
$notifiable = new Notifiable;
Expand All @@ -75,7 +76,7 @@ public function it_will_not_send_a_message_without_known_receiver()
$this->assertNull($result);
}

/** @test */
#[Test]
public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_the_notifiable()
{
$notifiable = new NotifiableWithMethod;
Expand All @@ -91,7 +92,7 @@ public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_the_notifiable_if_it_uses_the_twilio_channel_explicitly()
{
$notifiable = new NotifiableWithTwilioChannel;
Expand All @@ -107,7 +108,7 @@ public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifiable()
{
$notifiable = new NotifiableWithAttribute;
Expand All @@ -123,7 +124,7 @@ public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifia
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_convert_a_string_to_a_sms_message()
{
$notifiable = new NotifiableWithAttribute;
Expand All @@ -138,7 +139,7 @@ public function it_will_convert_a_string_to_a_sms_message()
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_fire_an_event_in_case_of_an_invalid_message()
{
$notifiable = new NotifiableWithAttribute;
Expand All @@ -160,7 +161,7 @@ public function it_will_fire_an_event_in_case_of_an_invalid_message()
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_ignore_specific_error_codes()
{
$notifiable = new NotifiableWithAttribute;
Expand All @@ -184,7 +185,7 @@ public function it_will_ignore_specific_error_codes()
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_rethrow_non_ignored_error_codes()
{
$notifiable = new NotifiableWithAttribute;
Expand All @@ -210,7 +211,7 @@ public function it_will_rethrow_non_ignored_error_codes()
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_ignore_all_error_codes()
{
$notifiable = new NotifiableWithAttribute;
Expand All @@ -232,7 +233,7 @@ public function it_will_ignore_all_error_codes()
$this->channel->send($notifiable, $notification);
}

/** @test */
#[Test]
public function it_will_send_using_alphanumeric_if_notifiable_can_receive()
{
$notifiable = new NotifiableWithAlphanumericSender;
Expand Down
17 changes: 9 additions & 8 deletions tests/Unit/TwilioConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NotificationChannels\Twilio\Tests\Unit;

use NotificationChannels\Twilio\TwilioConfig;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class TwilioConfigTest extends TestCase
Expand All @@ -12,15 +13,15 @@ private function config(array $config = []): TwilioConfig
return new TwilioConfig($config);
}

/** @test */
#[Test]
public function it_returns_a_boolean_wether_it_is_is_enabled_or_not()
{
$this->assertTrue($this->config()->enabled()); // defaults to true
$this->assertTrue($this->config(['enabled' => true])->enabled());
$this->assertFalse($this->config(['enabled' => false])->enabled());
}

/** @test */
#[Test]
public function it_defaults_to_null_for_config_keys_with_a_string_return_type()
{
$config = $this->config();
Expand All @@ -35,7 +36,7 @@ public function it_defaults_to_null_for_config_keys_with_a_string_return_type()
$this->assertNull($config->getDebugTo());
}

/** @test */
#[Test]
public function it_returns_a_string_for_config_keys_with_a_string_return_type()
{
$config = $this->config([
Expand All @@ -59,14 +60,14 @@ public function it_returns_a_string_for_config_keys_with_a_string_return_type()
$this->assertEquals('valid-debug-to', $config->getDebugTo());
}

/** @test */
#[Test]
public function it_returns_an_array_of_ignored_codes()
{
$this->assertEquals([], $this->config()->getIgnoredErrorCodes()); // defaults to empty array
$this->assertEquals([1, 2], $this->config(['ignored_error_codes' => [1, 2]])->getIgnoredErrorCodes());
}

/** @test */
#[Test]
public function it_returns_a_boolean_wether_the_error_code_is_ignored_or_not()
{
$config = $this->config(['ignored_error_codes' => [1, 2]]);
Expand All @@ -80,15 +81,15 @@ public function it_returns_a_boolean_wether_the_error_code_is_ignored_or_not()
$this->assertTrue($config->isIgnoredErrorCode(3));
}

/** @test */
#[Test]
public function it_returns_a_boolean_wether_shorten_urls_is_enabled_or_not()
{
$this->assertFalse($this->config()->isShortenUrlsEnabled()); // defaults to false
$this->assertTrue($this->config(['shorten_urls' => true])->isShortenUrlsEnabled());
$this->assertFalse($this->config(['shorten_urls' => false])->isShortenUrlsEnabled());
}

/** @test */
#[Test]
public function it_returns_a_boolean_wether_token_auth_is_used_or_not()
{
// No values set...
Expand All @@ -102,7 +103,7 @@ public function it_returns_a_boolean_wether_token_auth_is_used_or_not()
$this->assertTrue($this->config(['auth_token' => 'valid', 'account_sid' => 'valid'])->usingTokenAuth());
}

/** @test */
#[Test]
public function it_returns_a_boolean_wether_username_password_auth_is_used_or_not()
{
// No values set...
Expand Down
11 changes: 6 additions & 5 deletions tests/Unit/TwilioMessageTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@

use Mockery\Adapter\Phpunit\MockeryTestCase;
use NotificationChannels\Twilio\TwilioMessage;
use PHPUnit\Framework\Attributes\Test;

abstract class TwilioMessageTestCase extends MockeryTestCase
{
/** @var TwilioMessage */
protected $message;

/** @test */
#[Test]
abstract public function it_can_accept_a_message_when_constructing_a_message();

/** @test */
#[Test]
abstract public function it_provides_a_create_method();

/** @test */
#[Test]
public function it_can_set_the_content()
{
$this->message->content('myMessage');

$this->assertEquals('myMessage', $this->message->content);
}

/** @test */
#[Test]
public function it_can_set_the_from()
{
$this->message->from('+1234567890');

$this->assertEquals('+1234567890', $this->message->from);
}

/** @test */
#[Test]
public function it_can_return_the_from_using_getter()
{
$this->message->from('+1234567890');
Expand Down
Loading

0 comments on commit 1305258

Please sign in to comment.