Skip to content

Commit d9db37a

Browse files
authored
fix: better tests + bugfixes (#93)
* fix: better tests + bugfixes * fix: method name change for dispatch
1 parent d0189ba commit d9db37a

15 files changed

+96
-134
lines changed

.github/workflows/php.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: PHP
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
66
run:
@@ -28,4 +28,9 @@ jobs:
2828
- name: Lint composer.json
2929
run: composer validate
3030
- name: Run Tests
31-
run: composer test:ci
31+
run: composer test:unit
32+
- name: Run Integration Tests
33+
if: matrix.laravel-version == '^7.0'
34+
run: |
35+
composer require --dev --no-interaction "orchestra/testbench:^5.1"
36+
composer test:integration

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
},
4141
"autoload-dev": {
4242
"psr-4": {
43-
"NotificationChannels\\Twilio\\Test\\": "tests"
43+
"NotificationChannels\\Twilio\\Tests\\": "tests"
4444
}
4545
},
4646
"scripts": {
4747
"test": "vendor/bin/phpunit",
48-
"test:ci": "phpunit --verbose --coverage-clover=coverage.xml"
48+
"test:unit": "phpunit --verbose --testsuite Unit",
49+
"test:integration": "phpunit --verbose --testsuite Integration"
4950
},
5051
"config": {
5152
"sort-packages": true

phpunit.xml.dist

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
processIsolation="false"
1111
stopOnFailure="false">
1212
<testsuites>
13-
<testsuite name="Test Suite">
14-
<directory>tests</directory>
13+
<testsuite name="Unit">
14+
<directory>tests/Unit</directory>
15+
</testsuite>
16+
<testsuite name="Integration">
17+
<directory>tests/Integration</directory>
1518
</testsuite>
1619
</testsuites>
1720
<filter>

src/TwilioChannel.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ public function send($notifiable, Notification $notification)
6565
['message' => $exception->getMessage(), 'exception' => $exception]
6666
);
6767

68-
if (function_exists('event')) { // Use event helper when possible to add Lumen support
69-
event($event);
70-
} else {
71-
$this->events->fire($event);
72-
}
68+
$this->events->dispatch($event);
7369

7470
if ($this->twilio->config->isIgnoredErrorCode($exception->getCode())) {
7571
return;

src/TwilioProvider.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace NotificationChannels\Twilio;
44

5+
use Illuminate\Contracts\Events\Dispatcher;
56
use Illuminate\Contracts\Foundation\Application;
67
use Illuminate\Contracts\Support\DeferrableProvider;
78
use Illuminate\Support\ServiceProvider;
@@ -22,7 +23,7 @@ public function boot()
2223
*/
2324
public function register()
2425
{
25-
$this->mergeConfigFrom(__DIR__.'/../config/twilio-notification-channel.php', '');
26+
$this->mergeConfigFrom(__DIR__.'/../config/twilio-notification-channel.php', 'twilio-notification-channel');
2627

2728
$this->publishes([
2829
__DIR__.'/../config/twilio-notification-channel.php' => config_path('twilio-notification-channel.php'),
@@ -32,13 +33,6 @@ public function register()
3233
return new TwilioConfig($this->app['config']['twilio-notification-channel']);
3334
});
3435

35-
$this->app->singleton(TwilioChannel::class, function (Application $app) {
36-
return new Twilio(
37-
$this->app->make(TwilioService::class),
38-
$this->app->make(TwilioConfig::class)
39-
);
40-
});
41-
4236
$this->app->singleton(TwilioService::class, function (Application $app) {
4337
/** @var TwilioConfig $config */
4438
$config = $app->make(TwilioConfig::class);
@@ -53,6 +47,20 @@ public function register()
5347

5448
throw InvalidConfigException::missingConfig();
5549
});
50+
51+
$this->app->singleton(Twilio::class, function (Application $app) {
52+
return new Twilio(
53+
$app->make(TwilioService::class),
54+
$app->make(TwilioConfig::class)
55+
);
56+
});
57+
58+
$this->app->singleton(TwilioChannel::class, function (Application $app) {
59+
return new TwilioChannel(
60+
$app->make(Twilio::class),
61+
$app->make(Dispatcher::class)
62+
);
63+
});
5664
}
5765

5866
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NotificationChannels\Twilio\Tests\Integration;
6+
7+
use NotificationChannels\Twilio\TwilioProvider;
8+
use Orchestra\Testbench\TestCase;
9+
10+
abstract class BaseIntegrationTest extends TestCase
11+
{
12+
protected function getPackageProviders($app)
13+
{
14+
return [TwilioProvider::class];
15+
}
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NotificationChannels\Twilio\Tests\Integration;
6+
7+
use NotificationChannels\Twilio\Exceptions\InvalidConfigException;
8+
use NotificationChannels\Twilio\TwilioChannel;
9+
10+
class TwilioProviderTest extends BaseIntegrationTest
11+
{
12+
public function testThatApplicationCannotCreateChannelWithoutConfig()
13+
{
14+
$this->expectException(InvalidConfigException::class);
15+
16+
$this->app->get(TwilioChannel::class);
17+
}
18+
19+
public function testThatApplicationCannotCreateChannelWithoutSid()
20+
{
21+
$this->app['config']->set('twilio-notification-channel.username', 'test');
22+
$this->app['config']->set('twilio-notification-channel.username', 'password');
23+
24+
$this->expectException(InvalidConfigException::class);
25+
$this->app->get(TwilioChannel::class);
26+
}
27+
28+
public function testThatApplicationCreatesChannelWithConfig()
29+
{
30+
$this->app['config']->set('twilio-notification-channel.username', 'test');
31+
$this->app['config']->set('twilio-notification-channel.password', 'password');
32+
$this->app['config']->set('twilio-notification-channel.account_sid', '1234');
33+
34+
$this->assertInstanceOf(TwilioChannel::class, $this->app->get(TwilioChannel::class));
35+
}
36+
}

tests/TwilioProviderTest.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

tests/IntegrationTest.php renamed to tests/Unit/IntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace NotificationChannels\Twilio\Test;
3+
namespace NotificationChannels\Twilio\Tests\Unit;
44

55
use Illuminate\Contracts\Events\Dispatcher;
66
use Illuminate\Notifications\Notification;

tests/TwilioCallMessageTest.php renamed to tests/Unit/TwilioCallMessageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace NotificationChannels\Twilio\Test;
3+
namespace NotificationChannels\Twilio\Tests\Unit;
44

55
use NotificationChannels\Twilio\TwilioCallMessage;
66

0 commit comments

Comments
 (0)