Skip to content

Commit

Permalink
Merge pull request #2 from io-digital/upgrade-to-latest-clickatell-api
Browse files Browse the repository at this point in the history
Upgrade to latest clickatell api
  • Loading branch information
garethnic authored Feb 11, 2021
2 parents 6fa64ec + fefdb9f commit 948257e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build
composer.phar
composer.lock
.phpunit.result.cache
.php_cs.cache
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This package makes it easy to send notifications using [clickatell.com](https://
You can install the package via composer:

```bash
composer require laravel-notification-channels/clickatell
composer require io-digital/clickatell
```

### Setting up the clickatell service
Expand All @@ -42,9 +42,7 @@ Add your Clickatell user, password and api identifier to your `config/services.
// config/services.php
...
'clickatell' => [
'user' => env('CLICKATELL_USER'),
'pass' => env('CLICKATELL_PASS'),
'api_id' => env('CLICKATELL_API_ID'),
'api_key' => env('CLICKATELL_API_KEY'),
],
...
```
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
},
"require-dev": {
"mockery/mockery": "~1.2",
"phpunit/phpunit": "~8.3"
"phpunit/phpunit": "~8.3",
"friendsofphp/php-cs-fixer": "^2.16",
"phpmd/phpmd": "^2.9",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions src/ClickatellClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NotificationChannels\Clickatell;

use Clickatell\Api\ClickatellHttp;
use Clickatell\Rest;
use NotificationChannels\Clickatell\Exceptions\CouldNotSendNotification;
use stdClass;

Expand All @@ -20,14 +20,14 @@ class ClickatellClient
const INTERNAL_ERROR = 901;

/**
* @var ClickatellHttp
* @var Rest
*/
private $clickatell;

/**
* @param ClickatellHttp $clickatellHttp
* @param Rest $clickatellHttp
*/
public function __construct(ClickatellHttp $clickatellHttp)
public function __construct(Rest $clickatellHttp)
{
$this->clickatell = $clickatellHttp;
}
Expand Down
10 changes: 2 additions & 8 deletions src/ClickatellServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NotificationChannels\Clickatell;

use Clickatell\Api\ClickatellHttp;
use Clickatell\Rest;
use Illuminate\Support\ServiceProvider;

class ClickatellServiceProvider extends ServiceProvider
Expand All @@ -17,13 +17,7 @@ public function register()
->give(function () {
$config = config('services.clickatell');

return new ClickatellClient(
new ClickatellHttp(
$config['user'],
$config['pass'],
$config['api_id']
)
);
return new Rest($config['api_key']);
});
}
}
17 changes: 8 additions & 9 deletions tests/ClickatellClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace NotificationChannels\Clickatell\Test;

use Clickatell\Api\ClickatellHttp;
use Clickatell\Rest;
use Mockery;
use NotificationChannels\Clickatell\ClickatellClient;
use NotificationChannels\Clickatell\Exceptions\CouldNotSendNotification;
Expand All @@ -13,15 +13,14 @@ class ClickatellClientTest extends TestCase
/** @var ClickatellClient */
private $clickatellClient;

/** @var ClickatellHttp */
private $httpClient;
/** @var Rest */
private $rest;

public function setUp(): void
{
parent::setUp();

$this->httpClient = Mockery::mock(ClickatellHttp::class);
$this->clickatellClient = new ClickatellClient($this->httpClient);
$this->rest = \Mockery::mock(Rest::class);
$this->clickatellClient = new ClickatellClient($this->rest);
}

public function tearDown(): void
Expand Down Expand Up @@ -71,7 +70,7 @@ public function it_sends_a_message_to_a_single_number()
$to = ['27848118111'];
$message = 'Hi there I am a message';

$this->httpClient->shouldReceive('sendMessage')
$this->rest->shouldReceive('sendMessage')
->once()
->with($to, $message)
->andReturn($this->getStubSuccessResponse($to));
Expand All @@ -88,7 +87,7 @@ public function it_sends_a_message_to_multiple_numbers()

$message = 'Hi there I am a message to multiple receivers';

$this->httpClient->shouldReceive('sendMessage')
$this->rest->shouldReceive('sendMessage')
->once()
->with($to, $message)
->andReturn($this->getStubSuccessResponse($to));
Expand All @@ -105,7 +104,7 @@ public function throws_an_exception_on_failed_response_code()
$to = ['27848118']; // Bad number
$message = 'Hi there I am a message that is bound to fail';

$this->httpClient->shouldReceive('sendMessage')
$this->rest->shouldReceive('sendMessage')
->once()
->with($to, $message)
->andReturn($this->getStubErrorResponse($to));
Expand Down
8 changes: 4 additions & 4 deletions tests/ClickatellMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace NotificationChannels\Clickatell\Test;

use Clickatell\Api\ClickatellHttp;
use Clickatell\Rest;
use NotificationChannels\Clickatell\ClickatellMessage;
use PHPUnit\Framework\TestCase;

class ClickatellMessageTest extends TestCase
{
protected $clickatellMessage;
private $httpClient;
private $rest;

public function setUp(): void
{
parent::setUp();
$this->httpClient = \Mockery::mock(ClickatellHttp::class);
$this->clickatellMessage = new ClickatellMessage($this->httpClient);
$this->rest = \Mockery::mock(Rest::class);
$this->clickatellMessage = new ClickatellMessage($this->rest);
}

/** @test */
Expand Down

0 comments on commit 948257e

Please sign in to comment.