From 8e030c145dfacfc9dc84657c5018bef514001ce2 Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:03:09 +0300 Subject: [PATCH 01/10] Added the clickatell extension --- composer.json | 4 +- src/Handler/ClickatellHandler.php | 70 +++++++++++++++++++++++++++++++ src/Handler/SMSHandler.php | 8 +++- 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/Handler/ClickatellHandler.php diff --git a/composer.json b/composer.json index 144746d..11b7343 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "tylercd100/monolog-sms", - "description": "A Monolog Handler for SMS messaging services such as Plivo and Twilio.", + "name": "itay9001/monolog-sms", + "description": "A fork of: A Monolog Handler for SMS messaging services such as Plivo and Twilio.", "keywords": [ "monolog", "plivo", diff --git a/src/Handler/ClickatellHandler.php b/src/Handler/ClickatellHandler.php new file mode 100644 index 0000000..581e6ce --- /dev/null +++ b/src/Handler/ClickatellHandler.php @@ -0,0 +1,70 @@ + $this->limit){ + $record['formatted'] = substr($record['formatted'], 0, $this->limit); + } + + $dataArray = [ + 'content' => $record['formatted'], + 'to' => (!is_array($this>toNumber)? [$this->toNumber] : $this->toNumber) + ]; + + ($this->fromNumber)? $dataArray["from"] = $this->fromNumber : false; + + return json_encode($dataArray); + } + + /** + * Builds the URL for the API call + * + * @return string + */ + protected function buildRequestUrl() + { + return "POST /messages HTTP/1.1\r\n"; + } +} diff --git a/src/Handler/SMSHandler.php b/src/Handler/SMSHandler.php index a22ccb3..b3936b4 100644 --- a/src/Handler/SMSHandler.php +++ b/src/Handler/SMSHandler.php @@ -107,12 +107,16 @@ abstract protected function buildRequestUrl(); */ private function buildHeader($content) { - $auth = base64_encode($this->authId.":".$this->authToken); + $auth = $this->authId; + + if($this->authToken){ + $auth = "Basic " . base64_encode($this->authId.":".$this->authToken); + } $header = $this->buildRequestUrl(); $header .= "Host: {$this->host}\r\n"; - $header .= "Authorization: Basic ".$auth."\r\n";; + $header .= "Authorization: ".$auth."\r\n";; $header .= "Content-Type: application/json\r\n"; $header .= "Content-Length: " . strlen($content) . "\r\n"; $header .= "\r\n"; From 3ef6bd167c934acb18a94fe551d795fd4dc04b2e Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:20:30 +0300 Subject: [PATCH 02/10] no message --- src/Handler/ClickatellHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Handler/ClickatellHandler.php b/src/Handler/ClickatellHandler.php index 581e6ce..dee0691 100644 --- a/src/Handler/ClickatellHandler.php +++ b/src/Handler/ClickatellHandler.php @@ -6,8 +6,8 @@ use Monolog\Logger; /** -* Twilio - Monolog Handler -* @url https://www.twilio.com/docs/api/rest/sending-messages +* Clickatell - Monolog Handler +* @url https://www.clickatell.com/developers/api-documentation/rest-api-request-parameters */ class ClickatellHandler extends SMSHandler { @@ -28,7 +28,7 @@ class ClickatellHandler extends SMSHandler * @param string $version The Twilio API version (default TwilioHandler::API_V1) * @param string $limit The character limit */ - public function __construct($secret, $sid, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.twilio.com', $version = self::API_V1, $limit = 160) + public function __construct($secret, $sid, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) { if($version !== self::API_V1){ throw new Exception('API Version \'{$version}\' is not supported!'); From aef6cd3dfe086ebe7d4460cf590dce44143e9d83 Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:23:47 +0300 Subject: [PATCH 03/10] Remove the sid, as clickatell doesn't use it --- src/Handler/ClickatellHandler.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Handler/ClickatellHandler.php b/src/Handler/ClickatellHandler.php index dee0691..0e64d1c 100644 --- a/src/Handler/ClickatellHandler.php +++ b/src/Handler/ClickatellHandler.php @@ -17,23 +17,22 @@ class ClickatellHandler extends SMSHandler const API_V1 = '2010-04-01'; /** - * @param string $secret Twilio API Secret Token - * @param string $sid Twilio API SID + * @param string $secret Twilio API Secret Token * @param string $fromNumber The phone number that will be shown as the sender ID * @param string $toNumber The phone number to which the message will be sent * @param int $level The minimum logging level at which this handler will be triggered * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * @param bool $useSSL Whether to connect via SSL. * @param string $host The Twilio server hostname. - * @param string $version The Twilio API version (default TwilioHandler::API_V1) + * @param string $version The Twilio API version (default ClickatellHandler::API_V1) * @param string $limit The character limit */ - public function __construct($secret, $sid, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) + public function __construct($secret, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) { if($version !== self::API_V1){ throw new Exception('API Version \'{$version}\' is not supported!'); } - parent::__construct($secret, $sid, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); + parent::__construct($secret, null, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); } /** From ee673017613a509607fa2d9f0b28f64eeac21599 Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:37:07 +0300 Subject: [PATCH 04/10] HOTFIX --- src/Handler/ClickatellHandler.php | 2 +- src/Handler/SMSHandler.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Handler/ClickatellHandler.php b/src/Handler/ClickatellHandler.php index 0e64d1c..fddaddd 100644 --- a/src/Handler/ClickatellHandler.php +++ b/src/Handler/ClickatellHandler.php @@ -49,7 +49,7 @@ protected function buildContent($record) $dataArray = [ 'content' => $record['formatted'], - 'to' => (!is_array($this>toNumber)? [$this->toNumber] : $this->toNumber) + 'to' => (!is_array($this->toNumber)? [$this->toNumber] : $this->toNumber) ]; ($this->fromNumber)? $dataArray["from"] = $this->fromNumber : false; diff --git a/src/Handler/SMSHandler.php b/src/Handler/SMSHandler.php index b3936b4..8e08cf8 100644 --- a/src/Handler/SMSHandler.php +++ b/src/Handler/SMSHandler.php @@ -107,9 +107,9 @@ abstract protected function buildRequestUrl(); */ private function buildHeader($content) { - $auth = $this->authId; + $auth = $this->authToken; - if($this->authToken){ + if($this->authId){ $auth = "Basic " . base64_encode($this->authId.":".$this->authToken); } From 5ecbdc13e68f5edcd7ab8842083a8ec959d7025c Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:40:45 +0300 Subject: [PATCH 05/10] Set name back to tylercd100 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 11b7343..2e13813 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "itay9001/monolog-sms", + "name": "tylercd100/monolog-sms", "description": "A fork of: A Monolog Handler for SMS messaging services such as Plivo and Twilio.", "keywords": [ "monolog", From 84daffdc7eb6c49b1d90cba05967a7dbf95cf0f3 Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:42:06 +0300 Subject: [PATCH 06/10] Newbie forker here ;) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2e13813..144746d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tylercd100/monolog-sms", - "description": "A fork of: A Monolog Handler for SMS messaging services such as Plivo and Twilio.", + "description": "A Monolog Handler for SMS messaging services such as Plivo and Twilio.", "keywords": [ "monolog", "plivo", From 448f5beabdd52b07b28dfea07e1df6775d5a6cef Mon Sep 17 00:00:00 2001 From: Itay Elkouby Date: Sun, 30 Apr 2017 14:43:53 +0300 Subject: [PATCH 07/10] no message --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 9bdbfc8..1cf5550 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,13 @@ $logger = new Monolog\Logger('plivo.example'); $logger->pushHandler($handler); $logger->addCritical("Foo Bar!"); ``` + +For Clickatell: +```php +use Tylercd100\Monolog\Handler\ClickatellHandler; + +$handler = new ClickatellHandler($authToken,$fromPhoneNumber (/*Optional*/),$toPhoneNumber (/*String|Array*/)); +$logger = new Monolog\Logger('plivo.example'); +$logger->pushHandler($handler); +$logger->addCritical("Foo Bar!"); +``` \ No newline at end of file From 43054cb80fe8f92645640686fd8a098a47c8bb9e Mon Sep 17 00:00:00 2001 From: Tyler Arbon Date: Mon, 1 May 2017 11:45:20 -0600 Subject: [PATCH 08/10] Added a test for clickatell. updated changelog. updated readme. --- .gitignore | 3 +- CHANGELOG.md | 3 + README.md | 9 ++- composer.json | 7 +- src/Formatter/SMSFormatter.php | 2 +- src/Handler/ClickatellHandler.php | 14 ++-- src/Handler/PlivoHandler.php | 6 +- src/Handler/SMSHandler.php | 14 ++-- src/Handler/TwilioHandler.php | 6 +- tests/ClickatellHandlerTest.php | 122 ++++++++++++++++++++++++++++++ 10 files changed, 156 insertions(+), 30 deletions(-) create mode 100644 tests/ClickatellHandlerTest.php diff --git a/.gitignore b/.gitignore index 2f89fe5..7330572 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build composer.lock vendor -run.php \ No newline at end of file +run.php +ubuntu-xenial-16.04-cloudimg-console.log \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 63a6ea5..9cfa9ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `Monolog SMS` will be documented in this file. +### 1.3.0 +- Added support for Clickatell + ### 1.2.0 - Added character limit diff --git a/README.md b/README.md index 1cf5550..20dc12b 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,9 @@ A Monolog Handler for SMS messaging services Currently supported -- [Plivo](https://www.plivo.com/) - [Twilio](https://www.twilio.com/) +- [Clickatell](https://www.clickatell.com/) +- [Plivo](https://www.plivo.com/) ## Installation @@ -26,7 +27,7 @@ For Plivo: use Tylercd100\Monolog\Handler\PlivoHandler; $handler = new PlivoHandler($token,$auth_id,$fromPhoneNumber,$toPhoneNumber); -$logger = new Monolog\Logger('plivo.example'); +$logger = new Monolog\Logger('channel.name'); $logger->pushHandler($handler); $logger->addCritical("Foo Bar!"); ``` @@ -36,7 +37,7 @@ For Twilio: use Tylercd100\Monolog\Handler\TwilioHandler; $handler = new TwilioHandler($secret,$sid,$fromPhoneNumber,$toPhoneNumber); -$logger = new Monolog\Logger('plivo.example'); +$logger = new Monolog\Logger('channel.name'); $logger->pushHandler($handler); $logger->addCritical("Foo Bar!"); ``` @@ -46,7 +47,7 @@ For Clickatell: use Tylercd100\Monolog\Handler\ClickatellHandler; $handler = new ClickatellHandler($authToken,$fromPhoneNumber (/*Optional*/),$toPhoneNumber (/*String|Array*/)); -$logger = new Monolog\Logger('plivo.example'); +$logger = new Monolog\Logger('channel.name'); $logger->pushHandler($handler); $logger->addCritical("Foo Bar!"); ``` \ No newline at end of file diff --git a/composer.json b/composer.json index 144746d..fae08d8 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,13 @@ { "name": "tylercd100/monolog-sms", - "description": "A Monolog Handler for SMS messaging services such as Plivo and Twilio.", + "description": "A Monolog Handler for SMS messaging services such as Twilio, Clickatell and Plivo.", "keywords": [ + "clickatell", + "composer", + "handler", "monolog", "plivo", "twilio", - "handler", - "composer", "tylercd100" ], "homepage": "https://github.com/tylercd100/monolog-sms", diff --git a/src/Formatter/SMSFormatter.php b/src/Formatter/SMSFormatter.php index 23bf95c..cb15a8c 100644 --- a/src/Formatter/SMSFormatter.php +++ b/src/Formatter/SMSFormatter.php @@ -22,4 +22,4 @@ public function __construct($format = null, $allowInlineLineBreaks = false, $ign $dateFormat = null; parent::__construct($format, $dateFormat, $allowInlineLineBreaks, $ignoreEmptyContextAndExtra); } -} \ No newline at end of file +} diff --git a/src/Handler/ClickatellHandler.php b/src/Handler/ClickatellHandler.php index fddaddd..de8f0d8 100644 --- a/src/Handler/ClickatellHandler.php +++ b/src/Handler/ClickatellHandler.php @@ -17,7 +17,7 @@ class ClickatellHandler extends SMSHandler const API_V1 = '2010-04-01'; /** - * @param string $secret Twilio API Secret Token + * @param string $secret Twilio API Secret Token * @param string $fromNumber The phone number that will be shown as the sender ID * @param string $toNumber The phone number to which the message will be sent * @param int $level The minimum logging level at which this handler will be triggered @@ -29,8 +29,8 @@ class ClickatellHandler extends SMSHandler */ public function __construct($secret, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) { - if($version !== self::API_V1){ - throw new Exception('API Version \'{$version}\' is not supported!'); + if ($version !== self::API_V1) { + throw new Exception("API Version \'{$version}\' is not supported!"); } parent::__construct($secret, null, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); } @@ -43,7 +43,7 @@ public function __construct($secret, $fromNumber, $toNumber, $level = Logger::CR */ protected function buildContent($record) { - if(strlen($record['formatted']) > $this->limit){ + if (strlen($record['formatted']) > $this->limit) { $record['formatted'] = substr($record['formatted'], 0, $this->limit); } @@ -52,14 +52,14 @@ protected function buildContent($record) 'to' => (!is_array($this->toNumber)? [$this->toNumber] : $this->toNumber) ]; - ($this->fromNumber)? $dataArray["from"] = $this->fromNumber : false; - + ($this->fromNumber)? $dataArray['from'] = $this->fromNumber : false; + return json_encode($dataArray); } /** * Builds the URL for the API call - * + * * @return string */ protected function buildRequestUrl() diff --git a/src/Handler/PlivoHandler.php b/src/Handler/PlivoHandler.php index bf37ca2..901691a 100644 --- a/src/Handler/PlivoHandler.php +++ b/src/Handler/PlivoHandler.php @@ -30,7 +30,7 @@ class PlivoHandler extends SMSHandler */ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.plivo.com', $version = self::API_V1, $limit = 160) { - if($version !== self::API_V1){ + if ($version !== self::API_V1) { throw new Exception('API Version \'{$version}\' is not supported!'); } parent::__construct($authToken, $authId, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); @@ -43,7 +43,7 @@ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level */ protected function buildContent($record) { - if(strlen($record['formatted']) > $this->limit){ + if (strlen($record['formatted']) > $this->limit) { $record['formatted'] = substr($record['formatted'], 0, $this->limit); } @@ -57,7 +57,7 @@ protected function buildContent($record) /** * Builds the URL for the API call - * + * * @return string */ protected function buildRequestUrl() diff --git a/src/Handler/SMSHandler.php b/src/Handler/SMSHandler.php index 8e08cf8..91473b4 100644 --- a/src/Handler/SMSHandler.php +++ b/src/Handler/SMSHandler.php @@ -54,8 +54,7 @@ abstract class SMSHandler extends SocketHandler */ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.plivo.com', $version = null, $limit = 160) { - - if(empty($version)){ + if (empty($version)) { throw new Exception('API Version is empty'); } @@ -69,7 +68,6 @@ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level $this->host = $host; $this->version = $version; $this->limit = $limit; - } /** @@ -94,7 +92,7 @@ abstract protected function buildContent($record); /** * Builds the URL for the API call - * + * * @return string */ abstract protected function buildRequestUrl(); @@ -109,14 +107,14 @@ private function buildHeader($content) { $auth = $this->authToken; - if($this->authId){ + if ($this->authId) { $auth = "Basic " . base64_encode($this->authId.":".$this->authToken); - } + } $header = $this->buildRequestUrl(); $header .= "Host: {$this->host}\r\n"; - $header .= "Authorization: ".$auth."\r\n";; + $header .= "Authorization: ".$auth."\r\n"; $header .= "Content-Type: application/json\r\n"; $header .= "Content-Length: " . strlen($content) . "\r\n"; $header .= "\r\n"; @@ -143,4 +141,4 @@ protected function getDefaultFormatter() { return new SMSFormatter(); } -} \ No newline at end of file +} diff --git a/src/Handler/TwilioHandler.php b/src/Handler/TwilioHandler.php index 5550ee8..e013ce0 100644 --- a/src/Handler/TwilioHandler.php +++ b/src/Handler/TwilioHandler.php @@ -30,7 +30,7 @@ class TwilioHandler extends SMSHandler */ public function __construct($secret, $sid, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.twilio.com', $version = self::API_V1, $limit = 160) { - if($version !== self::API_V1){ + if ($version !== self::API_V1) { throw new Exception('API Version \'{$version}\' is not supported!'); } parent::__construct($secret, $sid, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); @@ -44,7 +44,7 @@ public function __construct($secret, $sid, $fromNumber, $toNumber, $level = Logg */ protected function buildContent($record) { - if(strlen($record['formatted']) > $this->limit){ + if (strlen($record['formatted']) > $this->limit) { $record['formatted'] = substr($record['formatted'], 0, $this->limit); } @@ -58,7 +58,7 @@ protected function buildContent($record) /** * Builds the URL for the API call - * + * * @return string */ protected function buildRequestUrl() diff --git a/tests/ClickatellHandlerTest.php b/tests/ClickatellHandlerTest.php new file mode 100644 index 0000000..a3b48fd --- /dev/null +++ b/tests/ClickatellHandlerTest.php @@ -0,0 +1,122 @@ +assertInstanceOf('Tylercd100\\Monolog\\Formatter\\SMSFormatter', $handler->getFormatter()); + $this->assertAttributeEquals('token', 'authToken', $handler); + $this->assertAttributeEquals('+15555555555', 'fromNumber', $handler); + $this->assertAttributeEquals('+16666666666', 'toNumber', $handler); + } + + public function testItThrowsExceptionWhenUsingDifferentVersionOtherThanV1() + { + $this->setExpectedException(Exception::class); + $handler = new ClickatellHandler('token', 'auth_id', '+15555555555', '+16666666666', Logger::CRITICAL, true, true, 'twilio.foo.bar', 'v2'); + } + + public function testWriteHeader() + { + $this->createHandler(); + $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); + fseek($this->res, 0); + $content = fread($this->res, 1024); + + $this->assertRegexp('/POST \/messages HTTP\/1.1\\r\\nHost: platform.clickatell.com\\r\\nAuthorization: token\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content); + + return $content; + } + + public function testWriteCustomHostHeader() + { + $this->createHandler('token', '+15555555555', '+16666666666', Logger::CRITICAL, true, true, 'twilio.foo.bar'); + $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); + fseek($this->res, 0); + $content = fread($this->res, 1024); + + $this->assertRegexp('/POST \/messages HTTP\/1.1\\r\\nHost: twilio.foo.bar\\r\\nAuthorization: token\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content); + + return $content; + } + + /** + * @depends testWriteHeader + */ + public function testWriteContent($content) + { + $this->assertRegexp('/{"content":"test1","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content); + } + + public function testWriteContentV1WithoutToAndFromNumbers() + { + $this->createHandler('token', false, null, Logger::CRITICAL, true, true, 'twilio.foo.bar'); + $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); + fseek($this->res, 0); + $content = fread($this->res, 1024); + + $this->assertRegexp('/{"content":"test1","to":\[null\]}/', $content); + + return $content; + } + + /** + * @depends testWriteCustomHostHeader + */ + public function testWriteContentNotify($content) + { + $this->assertRegexp('/{"content":"test1","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content); + } + + public function testWriteWithComplexMessage() + { + $this->createHandler(); + $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Backup of database example finished in 16 minutes.')); + fseek($this->res, 0); + $content = fread($this->res, 1024); + + $this->assertRegexp('/{"content":"Backup of database example finished in 16 minutes\.","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content); + } + + private function createHandler($authToken = 'token', $fromNumber = '+15555555555', $toNumber = '+16666666666', $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = ClickatellHandler::API_V1) + { + $constructorArgs = array($authToken, $fromNumber, $toNumber, Logger::DEBUG, true, true, $host, $version); + $this->res = fopen('php://memory', 'a'); + $this->handler = $this->getMock( + '\Tylercd100\Monolog\Handler\ClickatellHandler', + array('fsockopen', 'streamSetTimeout', 'closeSocket'), + $constructorArgs + ); + + $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->handler, 'localhost:1234'); + + $this->handler->expects($this->any()) + ->method('fsockopen') + ->will($this->returnValue($this->res)); + $this->handler->expects($this->any()) + ->method('streamSetTimeout') + ->will($this->returnValue(true)); + $this->handler->expects($this->any()) + ->method('closeSocket') + ->will($this->returnValue(true)); + + $this->handler->setFormatter($this->getIdentityFormatter()); + } +} From a52e751f4ebd59e5541639136ab820659c07b4bb Mon Sep 17 00:00:00 2001 From: Tyler Arbon Date: Mon, 1 May 2017 11:51:23 -0600 Subject: [PATCH 09/10] added property declaration --- src/Handler/SMSHandler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Handler/SMSHandler.php b/src/Handler/SMSHandler.php index 91473b4..0543fab 100644 --- a/src/Handler/SMSHandler.php +++ b/src/Handler/SMSHandler.php @@ -40,6 +40,11 @@ abstract class SMSHandler extends SocketHandler */ protected $version; + /** + * @var string + */ + protected $limit; + /** * @param string $authToken Plivo API Auth Token * @param string $authId Plivo API Auth ID From 68385788dc0123120288109e445816b9db290418 Mon Sep 17 00:00:00 2001 From: Tyler Arbon Date: Mon, 1 May 2017 11:52:21 -0600 Subject: [PATCH 10/10] fixed docblocks --- src/Handler/ClickatellHandler.php | 2 +- src/Handler/PlivoHandler.php | 2 +- src/Handler/SMSHandler.php | 4 ++-- src/Handler/TwilioHandler.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Handler/ClickatellHandler.php b/src/Handler/ClickatellHandler.php index de8f0d8..1db385b 100644 --- a/src/Handler/ClickatellHandler.php +++ b/src/Handler/ClickatellHandler.php @@ -25,7 +25,7 @@ class ClickatellHandler extends SMSHandler * @param bool $useSSL Whether to connect via SSL. * @param string $host The Twilio server hostname. * @param string $version The Twilio API version (default ClickatellHandler::API_V1) - * @param string $limit The character limit + * @param int $limit The character limit */ public function __construct($secret, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) { diff --git a/src/Handler/PlivoHandler.php b/src/Handler/PlivoHandler.php index 901691a..468a713 100644 --- a/src/Handler/PlivoHandler.php +++ b/src/Handler/PlivoHandler.php @@ -26,7 +26,7 @@ class PlivoHandler extends SMSHandler * @param bool $useSSL Whether to connect via SSL. * @param string $host The Plivo server hostname. * @param string $version The Plivo API version (default PlivoHandler::API_V1) - * @param string $limit The character limit + * @param int $limit The character limit */ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.plivo.com', $version = self::API_V1, $limit = 160) { diff --git a/src/Handler/SMSHandler.php b/src/Handler/SMSHandler.php index 0543fab..29e745c 100644 --- a/src/Handler/SMSHandler.php +++ b/src/Handler/SMSHandler.php @@ -41,7 +41,7 @@ abstract class SMSHandler extends SocketHandler protected $version; /** - * @var string + * @var integer */ protected $limit; @@ -55,7 +55,7 @@ abstract class SMSHandler extends SocketHandler * @param bool $useSSL Whether to connect via SSL. * @param string $host The Plivo server hostname. * @param string $version The Plivo API version (default PlivoHandler::API_V1) - * @param string $limit The character limit + * @param int $limit The character limit */ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.plivo.com', $version = null, $limit = 160) { diff --git a/src/Handler/TwilioHandler.php b/src/Handler/TwilioHandler.php index e013ce0..ac715df 100644 --- a/src/Handler/TwilioHandler.php +++ b/src/Handler/TwilioHandler.php @@ -26,7 +26,7 @@ class TwilioHandler extends SMSHandler * @param bool $useSSL Whether to connect via SSL. * @param string $host The Twilio server hostname. * @param string $version The Twilio API version (default TwilioHandler::API_V1) - * @param string $limit The character limit + * @param int $limit The character limit */ public function __construct($secret, $sid, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.twilio.com', $version = self::API_V1, $limit = 160) {