Skip to content

Commit 591856e

Browse files
committed
Add multipart option
1 parent 8bdc285 commit 591856e

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## [0.0.3] - 2016-09-12
6+
#### Added
7+
- Added `multipart` method for `CmsmsMessage`.
8+
59
## [0.0.2] - 2016-09-04
610
#### Added
711
- Added `tariff` method for `CmsmsMessage`.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function routeNotificationForCmsms()
105105
- `originator('')`: Accepts a string value between 1 and 11 characters, used as the message sender name.
106106
- `reference('')`: Accepts a string value for your message reference. This information will be returned in a status report so you can match the message and it's status. Restrictions: 1 - 32 alphanumeric characters and reference will not work for demo accounts.
107107
- `tariff()`: Accepts a integer value for your message tariff. The unit is eurocent. Requires the `originator` to be set to a specific value. Contact CM for this value and to enable this feature for your contract.
108+
- `multipart($minimum, $maximum)`: Accepts a 0 to 8 integer range which allows multipart messages. See the [documentation from CM](https://dashboard.onlinesmsgateway.com/docs#send-a-message-multipart) for more information.
108109

109110
## Changelog
110111

src/CmsmsMessage.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class CmsmsMessage
1818
/** @var int */
1919
protected $tariff;
2020

21+
/** @var int */
22+
protected $minimumNumberOfMessageParts;
23+
24+
/** @var int */
25+
protected $maximumNumberOfMessageParts;
26+
2127
/**
2228
* @param string $body
2329
*/
@@ -85,6 +91,24 @@ public function tariff($tariff)
8591
return $this;
8692
}
8793

94+
/**
95+
* @param int $minimum
96+
* @param int $maximum
97+
* @return $this
98+
* @throws InvalidMessage
99+
*/
100+
public function multipart($minimum, $maximum)
101+
{
102+
if (! is_int($minimum) || ! is_int($maximum) || $maximum > 8 || $minimum >= $maximum) {
103+
throw InvalidMessage::invalidMessageParts($minimum, $maximum);
104+
}
105+
106+
$this->minimumNumberOfMessageParts = $minimum;
107+
$this->maximumNumberOfMessageParts = $maximum;
108+
109+
return $this;
110+
}
111+
88112
/**
89113
* @return array
90114
*/
@@ -95,6 +119,8 @@ public function toXmlArray()
95119
'FROM' => $this->originator,
96120
'REFERENCE' => $this->reference,
97121
'TARIFF' => $this->tariff,
122+
'MINIMUMNUMBEROFMESSAGEPARTS' => $this->minimumNumberOfMessageParts,
123+
'MAXIMUMNUMBEROFMESSAGEPARTS' => $this->maximumNumberOfMessageParts,
98124
]);
99125
}
100126

src/Exceptions/InvalidMessage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ public static function invalidTariff($tariff)
3232
{
3333
return new static("The tarrif on the CMSMS message may only contain a nonzero integer. Was given '{$tariff}'");
3434
}
35+
36+
/**
37+
* @param int $minimum
38+
* @param int $maximum
39+
* @return static
40+
*/
41+
public static function invalidMessageParts($minimum, $maximum)
42+
{
43+
return new static("The number of message parts on the CMSMS message may only contain a integer range from 0 to 8. Was given a minimum of '{$minimum}' and maximum of '{$maximum}'");
44+
}
3545
}

tests/CmsmsMessageTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function it_cannot_set_a_reference_that_contains_non_alpha_numeric_values
9898
}
9999

100100
/** @test */
101-
public function is_can_set_tariff()
101+
public function it_can_set_tariff()
102102
{
103103
$message = (new CmsmsMessage)->tariff(12);
104104

@@ -121,6 +121,39 @@ public function it_cannot_set_a_float_to_tariff()
121121
(new CmsmsMessage)->tariff(2.5);
122122
}
123123

124+
/** @test */
125+
public function it_can_set_multipart()
126+
{
127+
$message = (new CmsmsMessage)->multipart(1, 4);
128+
129+
$this->assertEquals(1, Arr::get($message->toXmlArray(), 'MINIMUMNUMBEROFMESSAGEPARTS'));
130+
$this->assertEquals(4, Arr::get($message->toXmlArray(), 'MAXIMUMNUMBEROFMESSAGEPARTS'));
131+
}
132+
133+
/** @test */
134+
public function it_cannot_set_a_float_to_multipart()
135+
{
136+
$this->setExpectedException(InvalidMessage::class);
137+
138+
(new CmsmsMessage)->multipart(1.3, 4.8);
139+
}
140+
141+
/** @test */
142+
public function it_cannot_have_more_than_8_parts()
143+
{
144+
$this->setExpectedException(InvalidMessage::class);
145+
146+
(new CmsmsMessage)->multipart(1, 9);
147+
}
148+
149+
/** @test */
150+
public function it_cannot_have_a_higher_minimum_than_maximum_for_multipart()
151+
{
152+
$this->setExpectedException(InvalidMessage::class);
153+
154+
(new CmsmsMessage)->multipart(4, 3);
155+
}
156+
124157
/** @test */
125158
public function it_xml_contains_only_filled_parameters()
126159
{

0 commit comments

Comments
 (0)