Skip to content

Commit e3ebaae

Browse files
Merge pull request #7 from mbardelmeijer/master
Require PHP 7, cleanup code, add support for Laravel 5.4 and 5.5
2 parents 6db3637 + dad3c3f commit e3ebaae

13 files changed

+83
-85
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
language: php
22

33
php:
4-
- 5.6
54
- 7.0
65
- 7.1
76

7+
sudo: false
8+
89
env:
910
matrix:
1011
- COMPOSER_FLAGS="--prefer-lowest"

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to `CMSMS` will be documented in this file
44

5+
## [1.0.0] - 2016-09-29
6+
#### Changed
7+
- Added support for Laravel 5.4 and 5.5
8+
- Dropped support for PHP 5.6
9+
- Added support for Laravel 5.5 package autoloader
10+
511
## [0.0.5] - 2016-09-29
612
#### Fixed
713
- Allow an empty `tariff` to be set.

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You can install the package via composer:
3838
composer require laravel-notification-channels/cmsms
3939
```
4040

41-
You must install the service provider:
41+
You must install the service provider for Laravel 5.4 and below:
4242

4343
```php
4444
// config/app.php
@@ -48,6 +48,8 @@ You must install the service provider:
4848
],
4949
```
5050

51+
Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
52+
5153
## Setting up your CMSMS account
5254

5355
Add your CMSMS Product Token and default originator (name or number of sender) to your `config/services.php`:

composer.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laravel-notification-channels/cmsms",
3-
"description": "Cmsms notification channel for Laravel 5.3",
3+
"description": "Cmsms notification channel for Laravel 5",
44
"homepage": "https://github.com/laravel-notification-channels/cmsms",
55
"license": "MIT",
66
"authors": [
@@ -12,15 +12,15 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.6.4",
16-
"illuminate/notifications": "^5.3",
17-
"illuminate/support": "^5.1|^5.2|^5.3",
15+
"php": "^7.0",
16+
"illuminate/notifications": "~5.3",
17+
"illuminate/support": "~5.3",
1818
"guzzlehttp/guzzle": "^6.2"
1919
},
2020
"require-dev": {
21-
"mockery/mockery": "^0.9.5",
22-
"phpunit/phpunit": "4.*",
23-
"orchestra/testbench": "^3.3"
21+
"mockery/mockery": "~0.9.9",
22+
"phpunit/phpunit": "^6.1",
23+
"orchestra/testbench": "~3.4.6"
2424
},
2525
"autoload": {
2626
"psr-4": {
@@ -37,5 +37,12 @@
3737
},
3838
"config": {
3939
"sort-packages": true
40+
},
41+
"extra": {
42+
"laravel": {
43+
"providers": [
44+
"NotificationChannels\\Cmsms\\CmsmsServiceProvider"
45+
]
46+
}
4047
}
4148
}

src/CmsmsChannel.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Cmsms;
46

57
use Illuminate\Notifications\Notification;

src/CmsmsClient.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Cmsms;
46

5-
use GuzzleHttp\Client as GuzzleClient;
7+
use SimpleXMLElement;
68
use Illuminate\Support\Arr;
9+
use GuzzleHttp\Client as GuzzleClient;
710
use NotificationChannels\Cmsms\Exceptions\CouldNotSendNotification;
8-
use SimpleXMLElement;
911

1012
class CmsmsClient
1113
{
@@ -21,7 +23,7 @@ class CmsmsClient
2123
* @param GuzzleClient $client
2224
* @param string $productToken
2325
*/
24-
public function __construct(GuzzleClient $client, $productToken)
26+
public function __construct(GuzzleClient $client, string $productToken)
2527
{
2628
$this->client = $client;
2729
$this->productToken = $productToken;
@@ -32,7 +34,7 @@ public function __construct(GuzzleClient $client, $productToken)
3234
* @param string $recipient
3335
* @throws CouldNotSendNotification
3436
*/
35-
public function send(CmsmsMessage $message, $recipient)
37+
public function send(CmsmsMessage $message, string $recipient)
3638
{
3739
if (is_null(Arr::get($message->toXmlArray(), 'FROM'))) {
3840
$message->originator(config('services.cmsms.originator'));
@@ -58,20 +60,20 @@ public function send(CmsmsMessage $message, $recipient)
5860
* @param string $recipient
5961
* @return string
6062
*/
61-
public function buildMessageXml(CmsmsMessage $message, $recipient)
63+
public function buildMessageXml(CmsmsMessage $message, string $recipient): string
6264
{
6365
$xml = new SimpleXMLElement('<MESSAGES/>');
6466

6567
$xml->addChild('AUTHENTICATION')
6668
->addChild('PRODUCTTOKEN', $this->productToken);
6769

6870
if ($tariff = $message->getTariff()) {
69-
$xml->addChild('TARIFF', $tariff);
71+
$xml->addChild('TARIFF', (string) $tariff);
7072
}
7173

7274
$msg = $xml->addChild('MSG');
7375
foreach ($message->toXmlArray() as $name => $value) {
74-
$msg->addChild($name, $value);
76+
$msg->addChild($name, (string) $value);
7577
}
7678
$msg->addChild('TO', $recipient);
7779

src/CmsmsMessage.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Cmsms;
46

57
use NotificationChannels\Cmsms\Exceptions\InvalidMessage;
@@ -27,7 +29,7 @@ class CmsmsMessage
2729
/**
2830
* @param string $body
2931
*/
30-
public function __construct($body = '')
32+
public function __construct(string $body = '')
3133
{
3234
$this->body($body);
3335
}
@@ -36,7 +38,7 @@ public function __construct($body = '')
3638
* @param string $body
3739
* @return $this
3840
*/
39-
public function body($body)
41+
public function body(string $body)
4042
{
4143
$this->body = trim($body);
4244

@@ -64,7 +66,7 @@ public function originator($originator)
6466
* @return $this
6567
* @throws InvalidMessage
6668
*/
67-
public function reference($reference)
69+
public function reference(string $reference)
6870
{
6971
if (empty($reference) || strlen($reference) > 32 || ! ctype_alnum($reference)) {
7072
throw InvalidMessage::invalidReference($reference);
@@ -80,12 +82,8 @@ public function reference($reference)
8082
* @return $this
8183
* @throws InvalidMessage
8284
*/
83-
public function tariff($tariff)
85+
public function tariff(int $tariff)
8486
{
85-
if (! is_int($tariff)) {
86-
throw InvalidMessage::invalidTariff($tariff);
87-
}
88-
8987
$this->tariff = $tariff;
9088

9189
return $this;
@@ -94,7 +92,7 @@ public function tariff($tariff)
9492
/**
9593
* @return int
9694
*/
97-
public function getTariff()
95+
public function getTariff(): int
9896
{
9997
return $this->tariff;
10098
}
@@ -105,9 +103,9 @@ public function getTariff()
105103
* @return $this
106104
* @throws InvalidMessage
107105
*/
108-
public function multipart($minimum, $maximum)
106+
public function multipart(int $minimum, int $maximum)
109107
{
110-
if (! is_int($minimum) || ! is_int($maximum) || $maximum > 8 || $minimum >= $maximum) {
108+
if ($maximum > 8 || $minimum >= $maximum) {
111109
throw InvalidMessage::invalidMultipart($minimum, $maximum);
112110
}
113111

@@ -120,7 +118,7 @@ public function multipart($minimum, $maximum)
120118
/**
121119
* @return array
122120
*/
123-
public function toXmlArray()
121+
public function toXmlArray(): array
124122
{
125123
return array_filter([
126124
'BODY' => $this->body,

src/CmsmsServiceProvider.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace NotificationChannels\Cmsms;
46

5-
use Illuminate\Support\ServiceProvider;
67
use GuzzleHttp\Client as GuzzleClient;
8+
use Illuminate\Support\ServiceProvider;
79
use NotificationChannels\Cmsms\Exceptions\InvalidConfiguration;
810

911
class CmsmsServiceProvider extends ServiceProvider
1012
{
11-
/**
12-
* Bootstrap the application services.
13-
*/
1413
public function boot()
1514
{
1615
$this->app->when(CmsmsChannel::class)
1716
->needs(CmsmsClient::class)
1817
->give(function () {
19-
$config = config('services.cmsms');
20-
21-
if (is_null($config)) {
18+
if (is_null($productToken = config('services.cmsms.product_token'))) {
2219
throw InvalidConfiguration::configurationNotSet();
2320
}
2421

25-
return new CmsmsClient(new GuzzleClient(), $config['product_token']);
22+
return new CmsmsClient(new GuzzleClient, $productToken);
2623
});
2724
}
2825
}

src/Exceptions/CouldNotSendNotification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CouldNotSendNotification extends Exception
1010
* @param string $error
1111
* @return static
1212
*/
13-
public static function serviceRespondedWithAnError($error)
13+
public static function serviceRespondedWithAnError(string $error)
1414
{
1515
return new static("CMSMS service responded with an error: {$error}'");
1616
}

src/Exceptions/InvalidMessage.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class InvalidMessage extends Exception
1010
* @param string $reference
1111
* @return static
1212
*/
13-
public static function invalidReference($reference)
13+
public static function invalidReference(string $reference)
1414
{
1515
return new static("The reference on the CMSMS message may only contain 1 - 32 alphanumeric characters. Was given '{$reference}'");
1616
}
@@ -19,26 +19,17 @@ public static function invalidReference($reference)
1919
* @param string $originator
2020
* @return static
2121
*/
22-
public static function invalidOriginator($originator)
22+
public static function invalidOriginator(string $originator)
2323
{
2424
return new static("The originator on the CMSMS message may only contain 1 - 11 characters. Was given '{$originator}'");
2525
}
2626

27-
/**
28-
* @param int $tariff
29-
* @return static
30-
*/
31-
public static function invalidTariff($tariff)
32-
{
33-
return new static("The tarrif on the CMSMS message may only contain a nonzero integer. Was given '{$tariff}'");
34-
}
35-
3627
/**
3728
* @param int $minimum
3829
* @param int $maximum
3930
* @return static
4031
*/
41-
public static function invalidMultipart($minimum, $maximum)
32+
public static function invalidMultipart(int $minimum, int $maximum)
4233
{
4334
return new static("The number of message parts for sending a multipart message on the CMSMS message may only contain a integer range from 0 to 8. Was given a minimum of '{$minimum}' and maximum of '{$maximum}'");
4435
}

tests/CmsmsChannelTest.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace NotificationChannels\Cmsms\Test;
44

5+
use Mockery;
56
use GuzzleHttp\Client;
7+
use PHPUnit\Framework\TestCase;
68
use Illuminate\Notifications\Notifiable;
79
use Illuminate\Notifications\Notification;
8-
use Mockery;
9-
use NotificationChannels\Cmsms\CmsmsChannel;
1010
use NotificationChannels\Cmsms\CmsmsClient;
11+
use NotificationChannels\Cmsms\CmsmsChannel;
1112
use NotificationChannels\Cmsms\CmsmsMessage;
12-
use PHPUnit_Framework_TestCase;
1313

14-
class CmsmsChannelTest extends PHPUnit_Framework_TestCase
14+
class CmsmsChannelTest extends TestCase
1515
{
1616
public function setUp()
1717
{
@@ -35,7 +35,10 @@ public function it_can_be_instantiated()
3535
$this->assertInstanceOf(CmsmsChannel::class, $this->channel);
3636
}
3737

38-
/** @test */
38+
/**
39+
* @test
40+
* @doesNotPerformAssertions
41+
*/
3942
public function it_shares_message()
4043
{
4144
$this->client->shouldReceive('send')->once();

tests/CmsmsClientTest.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace NotificationChannels\Cmsms\Test;
44

5+
use Mockery;
56
use GuzzleHttp\Client;
67
use GuzzleHttp\Psr7\Response;
7-
use Mockery;
8+
use Orchestra\Testbench\TestCase;
89
use NotificationChannels\Cmsms\CmsmsClient;
910
use NotificationChannels\Cmsms\CmsmsMessage;
1011
use NotificationChannels\Cmsms\Exceptions\CouldNotSendNotification;
11-
use Orchestra\Testbench\TestCase;
1212

1313
class CmsmsClientTest extends TestCase
1414
{
@@ -34,7 +34,10 @@ public function it_can_be_instantiated()
3434
$this->assertInstanceOf(CmsmsMessage::class, $this->message);
3535
}
3636

37-
/** @test */
37+
/**
38+
* @test
39+
* @doesNotPerformAssertions
40+
*/
3841
public function it_can_send_message()
3942
{
4043
$this->guzzle
@@ -45,7 +48,10 @@ public function it_can_send_message()
4548
$this->client->send($this->message, '00301234');
4649
}
4750

48-
/** @test */
51+
/**
52+
* @test
53+
* @doesNotPerformAssertions
54+
*/
4955
public function it_sets_a_default_originator_if_none_is_set()
5056
{
5157
$message = Mockery::mock(new CmsmsMessage('Message body'));
@@ -64,7 +70,7 @@ public function it_sets_a_default_originator_if_none_is_set()
6470
/** @test */
6571
public function it_throws_exception_on_error_response()
6672
{
67-
$this->setExpectedException(CouldNotSendNotification::class);
73+
$this->expectException(CouldNotSendNotification::class);
6874

6975
$this->guzzle
7076
->shouldReceive('request')

0 commit comments

Comments
 (0)