Skip to content

Commit 206b7fd

Browse files
authored
Merge pull request #6 from tortuetorche/next
PHP 8.0 support 🚀
2 parents efb43ce + 62cdce8 commit 206b7fd

7 files changed

+100
-70
lines changed

.travis.yml

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

33
php:
4-
- 5.5.9
5-
- 5.5
6-
- 5.6
7-
- 7.0
8-
- hhvm
4+
- 7.2
5+
- 7.3
6+
- 7.4
7+
- 8.0snapshot
98

109
env:
1110
matrix:
@@ -18,8 +17,3 @@ before_script:
1817

1918
script:
2019
- vendor/bin/phpunit
21-
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi
22-
23-
after_script:
24-
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
25-
- if [ "$TRAVIS_PHP_VERSION" == "5.5.9" ] || [ "$TRAVIS_PHP_VERSION" == "5.5" ] || [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
"Tylercd100\\Monolog\\Tests\\": "tests/"
2323
}
2424
},
25-
"minimum-stability": "stable",
25+
"minimum-stability": "dev",
26+
"prefer-stable": true,
2627
"require": {
27-
"php": "^5.4|^7.0",
28-
"monolog/monolog": "^1.12 || ^2.0"
28+
"php": "^7.2|^8.0",
29+
"monolog/monolog": "^2.0"
2930
},
3031
"require-dev": {
31-
"phpunit/phpunit": "^4.0|^5.0"
32+
"phpunit/phpunit": "^8.2.3|^9.0"
3233
},
3334
"authors": [
3435
{

src/Handler/SMSHandler.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tylercd100\Monolog\Handler;
44

55
use Exception;
6+
use Monolog\Formatter\FormatterInterface;
67
use Monolog\Handler\SocketHandler;
78
use Monolog\Logger;
89
use Tylercd100\Monolog\Formatter\SMSFormatter;
@@ -81,7 +82,7 @@ public function __construct($authToken, $authId, $fromNumber, $toNumber, $level
8182
* @param array $record
8283
* @return string
8384
*/
84-
protected function generateDataStream($record)
85+
protected function generateDataStream(array $record) :string
8586
{
8687
$content = $this->buildContent($record);
8788
return $this->buildHeader($content) . $content;
@@ -133,7 +134,7 @@ private function buildHeader($content)
133134
*
134135
* @param array $record
135136
*/
136-
protected function write(array $record)
137+
protected function write(array $record) :void
137138
{
138139
parent::write($record);
139140
$this->closeSocket();
@@ -142,7 +143,7 @@ protected function write(array $record)
142143
/**
143144
* {@inheritdoc}
144145
*/
145-
protected function getDefaultFormatter()
146+
protected function getDefaultFormatter(): FormatterInterface
146147
{
147148
return new SMSFormatter();
148149
}

tests/ClickatellHandlerTest.php

+15-16
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ class ClickatellHandlerTest extends TestCase
1414

1515
/** @var ClickatellHandler */
1616
private $handler;
17-
17+
1818
public function testCanBeInstantiatedAndProvidesDefaultFormatter()
1919
{
2020
$handler = new ClickatellHandler('token', '+15555555555', '+16666666666');
2121

2222
$this->assertInstanceOf('Tylercd100\\Monolog\\Formatter\\SMSFormatter', $handler->getFormatter());
23-
$this->assertAttributeEquals('token', 'authToken', $handler);
24-
$this->assertAttributeEquals('+15555555555', 'fromNumber', $handler);
25-
$this->assertAttributeEquals('+16666666666', 'toNumber', $handler);
23+
$this->assertEquals('token', $this->accessProtected($handler, 'authToken'));
24+
$this->assertEquals('+15555555555', $this->accessProtected($handler, 'fromNumber'));
25+
$this->assertEquals('+16666666666', $this->accessProtected($handler, 'toNumber'));
2626
}
2727

2828
public function testItThrowsExceptionWhenUsingDifferentVersionOtherThanV1()
2929
{
30-
$this->setExpectedException(Exception::class);
30+
$this->expectException(Exception::class);
3131
$handler = new ClickatellHandler('token', 'auth_id', '+15555555555', '+16666666666', Logger::CRITICAL, true, true, 'twilio.foo.bar', 'v2');
3232
}
3333

@@ -38,7 +38,7 @@ public function testWriteHeader()
3838
fseek($this->res, 0);
3939
$content = fread($this->res, 1024);
4040

41-
$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);
41+
$this->assertMatchesRegularExpression('/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);
4242

4343
return $content;
4444
}
@@ -50,7 +50,7 @@ public function testWriteCustomHostHeader()
5050
fseek($this->res, 0);
5151
$content = fread($this->res, 1024);
5252

53-
$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);
53+
$this->assertMatchesRegularExpression('/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);
5454

5555
return $content;
5656
}
@@ -60,7 +60,7 @@ public function testWriteCustomHostHeader()
6060
*/
6161
public function testWriteContent($content)
6262
{
63-
$this->assertRegexp('/{"content":"test1","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content);
63+
$this->assertMatchesRegularExpression('/{"content":"test1","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content);
6464
}
6565

6666
public function testWriteContentV1WithoutToAndFromNumbers()
@@ -70,7 +70,7 @@ public function testWriteContentV1WithoutToAndFromNumbers()
7070
fseek($this->res, 0);
7171
$content = fread($this->res, 1024);
7272

73-
$this->assertRegexp('/{"content":"test1","to":\[null\]}/', $content);
73+
$this->assertMatchesRegularExpression('/{"content":"test1","to":\[null\]}/', $content);
7474

7575
return $content;
7676
}
@@ -80,7 +80,7 @@ public function testWriteContentV1WithoutToAndFromNumbers()
8080
*/
8181
public function testWriteContentNotify($content)
8282
{
83-
$this->assertRegexp('/{"content":"test1","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content);
83+
$this->assertMatchesRegularExpression('/{"content":"test1","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content);
8484
}
8585

8686
public function testWriteWithComplexMessage()
@@ -90,18 +90,17 @@ public function testWriteWithComplexMessage()
9090
fseek($this->res, 0);
9191
$content = fread($this->res, 1024);
9292

93-
$this->assertRegexp('/{"content":"Backup of database example finished in 16 minutes\.","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content);
93+
$this->assertMatchesRegularExpression('/{"content":"Backup of database example finished in 16 minutes\.","to":\["\+16666666666"\],"from":"\+15555555555"}/', $content);
9494
}
9595

9696
private function createHandler($authToken = 'token', $fromNumber = '+15555555555', $toNumber = '+16666666666', $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = ClickatellHandler::API_V1)
9797
{
9898
$constructorArgs = array($authToken, $fromNumber, $toNumber, Logger::DEBUG, true, true, $host, $version);
9999
$this->res = fopen('php://memory', 'a');
100-
$this->handler = $this->getMock(
101-
'\Tylercd100\Monolog\Handler\ClickatellHandler',
102-
array('fsockopen', 'streamSetTimeout', 'closeSocket'),
103-
$constructorArgs
104-
);
100+
$this->handler = $this->getMockBuilder(ClickatellHandler::class)
101+
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
102+
->setConstructorArgs($constructorArgs)
103+
->getMock();
105104

106105
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
107106
$reflectionProperty->setAccessible(true);

tests/PlivoHandlerTest.php

+16-17
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ class PlivoHandlerTest extends TestCase
1313
private $res;
1414
/** @var PlivoHandler */
1515
private $handler;
16-
16+
1717
public function testCanBeInstantiatedAndProvidesDefaultFormatter()
1818
{
1919
$handler = new PlivoHandler('token', 'auth_id', '+15555555555', '+16666666666');
2020

2121
$this->assertInstanceOf('Tylercd100\\Monolog\\Formatter\\SMSFormatter', $handler->getFormatter());
22-
$this->assertAttributeEquals('token', 'authToken', $handler);
23-
$this->assertAttributeEquals('auth_id', 'authId', $handler);
24-
$this->assertAttributeEquals('+15555555555', 'fromNumber', $handler);
25-
$this->assertAttributeEquals('+16666666666', 'toNumber', $handler);
22+
$this->assertEquals('token', $this->accessProtected($handler, 'authToken'));
23+
$this->assertEquals('auth_id', $this->accessProtected($handler, 'authId'));
24+
$this->assertEquals('+15555555555', $this->accessProtected($handler, 'fromNumber'));
25+
$this->assertEquals('+16666666666', $this->accessProtected($handler, 'toNumber'));
2626
}
2727

2828
public function testItThrowsExceptionWhenUsingDifferentVersionOtherThanV1()
2929
{
30-
$this->setExpectedException(Exception::class);
30+
$this->expectException(Exception::class);
3131
$handler = new PlivoHandler('token', 'auth_id', '+15555555555', '+16666666666', Logger::CRITICAL, true, true, 'plivo.foo.bar', 'v2');
3232
}
3333

@@ -38,7 +38,7 @@ public function testWriteHeader()
3838
fseek($this->res, 0);
3939
$content = fread($this->res, 1024);
4040

41-
$this->assertRegexp('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1\\r\\nHost: api.plivo.com\\r\\nAuthorization: Basic YXV0aF9pZDp0b2tlbg==\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
41+
$this->assertMatchesRegularExpression('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1\\r\\nHost: api.plivo.com\\r\\nAuthorization: Basic YXV0aF9pZDp0b2tlbg==\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
4242

4343
return $content;
4444
}
@@ -50,7 +50,7 @@ public function testWriteCustomHostHeader()
5050
fseek($this->res, 0);
5151
$content = fread($this->res, 1024);
5252

53-
$this->assertRegexp('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1\\r\\nHost: plivo.foo.bar\\r\\nAuthorization: Basic YXV0aF9pZDp0b2tlbg==\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
53+
$this->assertMatchesRegularExpression('/POST \/v1\/Account\/auth_id\/Message\/ HTTP\/1.1\\r\\nHost: plivo.foo.bar\\r\\nAuthorization: Basic YXV0aF9pZDp0b2tlbg==\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
5454

5555
return $content;
5656
}
@@ -60,7 +60,7 @@ public function testWriteCustomHostHeader()
6060
*/
6161
public function testWriteContent($content)
6262
{
63-
$this->assertRegexp('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/', $content);
63+
$this->assertMatchesRegularExpression('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/', $content);
6464
}
6565

6666
public function testWriteContentV1WithoutToAndFromNumbers()
@@ -70,7 +70,7 @@ public function testWriteContentV1WithoutToAndFromNumbers()
7070
fseek($this->res, 0);
7171
$content = fread($this->res, 1024);
7272

73-
$this->assertRegexp('/{"src":false,"dst":null,"text":"test1"}/', $content);
73+
$this->assertMatchesRegularExpression('/{"src":false,"dst":null,"text":"test1"}/', $content);
7474

7575
return $content;
7676
}
@@ -80,7 +80,7 @@ public function testWriteContentV1WithoutToAndFromNumbers()
8080
*/
8181
public function testWriteContentNotify($content)
8282
{
83-
$this->assertRegexp('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/', $content);
83+
$this->assertMatchesRegularExpression('/{"src":"\+15555555555","dst":"\+16666666666","text":"test1"}/', $content);
8484
}
8585

8686
public function testWriteWithComplexMessage()
@@ -90,18 +90,17 @@ public function testWriteWithComplexMessage()
9090
fseek($this->res, 0);
9191
$content = fread($this->res, 1024);
9292

93-
$this->assertRegexp('/{"src":"\+15555555555","dst":"\+16666666666","text":"Backup of database example finished in 16 minutes\."}/', $content);
93+
$this->assertMatchesRegularExpression('/{"src":"\+15555555555","dst":"\+16666666666","text":"Backup of database example finished in 16 minutes\."}/', $content);
9494
}
9595

9696
private function createHandler($authToken = 'token', $authId = 'auth_id', $fromNumber = '+15555555555', $toNumber = '+16666666666', $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'api.plivo.com', $version = PlivoHandler::API_V1)
9797
{
9898
$constructorArgs = array($authToken, $authId, $fromNumber, $toNumber, Logger::DEBUG, true, true, $host, $version);
9999
$this->res = fopen('php://memory', 'a');
100-
$this->handler = $this->getMock(
101-
'\Tylercd100\Monolog\Handler\PlivoHandler',
102-
array('fsockopen', 'streamSetTimeout', 'closeSocket'),
103-
$constructorArgs
104-
);
100+
$this->handler = $this->getMockBuilder(PlivoHandler::class)
101+
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
102+
->setConstructorArgs($constructorArgs)
103+
->getMock();
105104

106105
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
107106
$reflectionProperty->setAccessible(true);

tests/TestCase.php

+40-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
namespace Tylercd100\Monolog\Tests;
1313

14+
use ReflectionClass;
1415
use Monolog\Logger;
16+
use Monolog\Formatter\FormatterInterface;
17+
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
1518

16-
class TestCase extends \PHPUnit_Framework_TestCase
19+
class TestCase extends PHPUnitTestCase
1720
{
1821
/**
1922
* @return array Record
@@ -50,11 +53,45 @@ protected function getMultipleRecords()
5053
*/
5154
protected function getIdentityFormatter()
5255
{
53-
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
56+
$formatter = $this->getMockBuilder(FormatterInterface::class)->getMock();
5457
$formatter->expects($this->any())
5558
->method('format')
56-
->will($this->returnCallback(function ($record) { return $record['message']; }));
59+
->will(
60+
$this->returnCallback(function ($record) {
61+
return $record['message'];
62+
})
63+
);
5764

5865
return $formatter;
5966
}
67+
68+
/**
69+
* Helper to return protected or private property value of an object
70+
*
71+
* @param mixed $object
72+
* @param string $property
73+
* @return mixed
74+
*/
75+
protected function accessProtected($object, $property)
76+
{
77+
$reflection = new ReflectionClass($object);
78+
$propertyReflection = $reflection->getProperty($property);
79+
$propertyReflection->setAccessible(true);
80+
81+
return $propertyReflection->getValue($object);
82+
}
83+
84+
/**
85+
* {@inheritdoc}
86+
*/
87+
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
88+
{
89+
if (method_exists(PHPUnitTestCase::class, 'assertMatchesRegularExpression')) {
90+
// For PHPUnit >= 9
91+
parent::assertMatchesRegularExpression($pattern, $string, $message);
92+
} else {
93+
// For PHPUnit < 9
94+
static::assertRegExp($pattern, $string, $message);
95+
}
96+
}
6097
}

0 commit comments

Comments
 (0)