Skip to content

Commit

Permalink
Merge pull request #8 from michal-kocarek/tried-older-php-versions
Browse files Browse the repository at this point in the history
Allow library to be used in PHP 5.5.
  • Loading branch information
Michal Kočárek committed Mar 22, 2016
2 parents da39afa + 47294ba commit 678d689
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: php
php:
- 5.5
- 5.6
- 7.0
- hhvm
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is a minimal example of a `composer.json` file that just defines a dependen

{
"require": {
"michal-kocarek/teamcity-messages": "^1.0"
"michal-kocarek/teamcity-messages": "^1.1"
}
}

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "michal-kocarek/teamcity-messages",
"description": "Write TeamCity service messages from PHP.",
"version": "1.0.0",
"version": "1.1.0",
"keywords": [
"teamcity"
],
Expand All @@ -14,10 +14,10 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^5.2.9",
"phpunit/phpunit": "^4.8.9",
"satooshi/php-coveralls": "^1.0.1"
},
"autoload": {
Expand Down
28 changes: 17 additions & 11 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@

class Util
{
const ESCAPE_CHARACTER_MAP = [
'\'' => '|\'',
"\n" => '|n',
"\r" => '|r',
'|' => '||',
'[' => '|[',
']' => '|]',
];

const TIMESTAMP_FORMAT = 'Y-m-d\TH:i:s.uO';

/**
Expand Down Expand Up @@ -97,11 +88,26 @@ public static function formatTimestamp(DateTimeInterface $date = null)
*/
private static function escape($value)
{
return preg_replace_callback('/([\'\n\r|[\]])|\\\\u(\d{4})/', function($matches) {
$escapeCharacterMap = [
'\'' => '|\'',
"\n" => '|n',
"\r" => '|r',
'|' => '||',
'[' => '|[',
']' => '|]',
];

return preg_replace_callback(/**
* @param $matches
* @return mixed|string
*/
'/([\'\n\r|[\]])|\\\\u(\d{4})/', function($matches) use($escapeCharacterMap) {
if ($matches[1]) {
return self::ESCAPE_CHARACTER_MAP[$matches[1]];
return $escapeCharacterMap[$matches[1]];
} elseif ($matches[2]) {
return '|0x'.$matches[2];
} else {
throw new LogicException('Unexpected match combination.');
}
}, $value);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MessageLoggerCallbacksTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bileto\TeamcityMessages\Tests;
namespace MichalKocarek\TeamcityMessages\Tests;

use Exception;
use LogicException;
Expand Down
6 changes: 4 additions & 2 deletions tests/Writers/CallbackWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
class CallbackWriterTest extends PHPUnit_Framework_TestCase
{
/**
* Method accepts messages as an argument.
* @dataProvider dataProviderWrite
* @param array $messages
*/
public function testWrite(...$messages)
public function testWrite(/* ...$messages */)
{
$messages = func_get_args();

$result = '';
$writer = new CallbackWriter(function($message) use(&$result) {
$result .= $message;
Expand Down
6 changes: 4 additions & 2 deletions tests/Writers/StdoutWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
class StdoutWriterTest extends PHPUnit_Framework_TestCase
{
/**
* Method accepts messages as an argument.
* @dataProvider dataProviderWrite
* @param array $messages
*/
public function testWrite(...$messages)
public function testWrite(/* ...$messages */)
{
$messages = func_get_args();

$writer = new StdoutWriter();

ob_start();
Expand Down

0 comments on commit 678d689

Please sign in to comment.