Skip to content

Commit 678d689

Browse files
author
Michal Kočárek
committed
Merge pull request #8 from michal-kocarek/tried-older-php-versions
Allow library to be used in PHP 5.5.
2 parents da39afa + 47294ba commit 678d689

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: php
22
php:
3+
- 5.5
34
- 5.6
45
- 7.0
56
- hhvm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Here is a minimal example of a `composer.json` file that just defines a dependen
1212

1313
{
1414
"require": {
15-
"michal-kocarek/teamcity-messages": "^1.0"
15+
"michal-kocarek/teamcity-messages": "^1.1"
1616
}
1717
}
1818

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "michal-kocarek/teamcity-messages",
33
"description": "Write TeamCity service messages from PHP.",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"keywords": [
66
"teamcity"
77
],
@@ -14,10 +14,10 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.6"
17+
"php": ">=5.5"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "^5.2.9",
20+
"phpunit/phpunit": "^4.8.9",
2121
"satooshi/php-coveralls": "^1.0.1"
2222
},
2323
"autoload": {

src/Util.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99

1010
class Util
1111
{
12-
const ESCAPE_CHARACTER_MAP = [
13-
'\'' => '|\'',
14-
"\n" => '|n',
15-
"\r" => '|r',
16-
'|' => '||',
17-
'[' => '|[',
18-
']' => '|]',
19-
];
20-
2112
const TIMESTAMP_FORMAT = 'Y-m-d\TH:i:s.uO';
2213

2314
/**
@@ -97,11 +88,26 @@ public static function formatTimestamp(DateTimeInterface $date = null)
9788
*/
9889
private static function escape($value)
9990
{
100-
return preg_replace_callback('/([\'\n\r|[\]])|\\\\u(\d{4})/', function($matches) {
91+
$escapeCharacterMap = [
92+
'\'' => '|\'',
93+
"\n" => '|n',
94+
"\r" => '|r',
95+
'|' => '||',
96+
'[' => '|[',
97+
']' => '|]',
98+
];
99+
100+
return preg_replace_callback(/**
101+
* @param $matches
102+
* @return mixed|string
103+
*/
104+
'/([\'\n\r|[\]])|\\\\u(\d{4})/', function($matches) use($escapeCharacterMap) {
101105
if ($matches[1]) {
102-
return self::ESCAPE_CHARACTER_MAP[$matches[1]];
106+
return $escapeCharacterMap[$matches[1]];
103107
} elseif ($matches[2]) {
104108
return '|0x'.$matches[2];
109+
} else {
110+
throw new LogicException('Unexpected match combination.');
105111
}
106112
}, $value);
107113
}

tests/MessageLoggerCallbacksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Bileto\TeamcityMessages\Tests;
3+
namespace MichalKocarek\TeamcityMessages\Tests;
44

55
use Exception;
66
use LogicException;

tests/Writers/CallbackWriterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
class CallbackWriterTest extends PHPUnit_Framework_TestCase
1111
{
1212
/**
13+
* Method accepts messages as an argument.
1314
* @dataProvider dataProviderWrite
14-
* @param array $messages
1515
*/
16-
public function testWrite(...$messages)
16+
public function testWrite(/* ...$messages */)
1717
{
18+
$messages = func_get_args();
19+
1820
$result = '';
1921
$writer = new CallbackWriter(function($message) use(&$result) {
2022
$result .= $message;

tests/Writers/StdoutWriterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
class StdoutWriterTest extends PHPUnit_Framework_TestCase
1111
{
1212
/**
13+
* Method accepts messages as an argument.
1314
* @dataProvider dataProviderWrite
14-
* @param array $messages
1515
*/
16-
public function testWrite(...$messages)
16+
public function testWrite(/* ...$messages */)
1717
{
18+
$messages = func_get_args();
19+
1820
$writer = new StdoutWriter();
1921

2022
ob_start();

0 commit comments

Comments
 (0)