Skip to content

Commit

Permalink
PHP 7.3+ compatibility (#12)
Browse files Browse the repository at this point in the history
PHP 7.3+ compatibility
  • Loading branch information
nhatthm authored Dec 2, 2019
2 parents 3341cfd + c588e20 commit 58ca086
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 34 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: php

php:
- '7.0'
- '7.1'
- '7.2'
- 7.3

env:
- COMPOSER_UPDATE=
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ dashboards to track activity and problems.

## Supported PHP versions

`stats-php` version `1.x` supports the following PHP version: `7.0`, `7.1`, `7.2`. If you going to use the library with newer PHP versions - consider using version `2.x+`.
`stats-php` version `1.x` supports the following PHP version: `7.0`, `7.1`, `7.2`. If you going to use the library with newer PHP versions - consider using version `2.x+`.

Since version `2.x`, this library start using the built-in `intl` PHP extension instead of `behat/transliterator`

## Key Features

Expand All @@ -29,6 +31,18 @@ dashboards to track activity and problems.
* Easy to build HTTP requests metrics - timing and count
* Generalise or modify HTTP Requests metric - e.g. skip ID part

## Dependencies

### Version `1.x`

- `php: >= 7.0`
- `behat/transliterator: ^1.2`

### Version `2.x`

- `php: >= 7.3`
- `ext-intl: >= 2.0`

## Installation

```sh
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
}
},
"require": {
"php": ">= 5.6",
"php": ">= 7.3",
"ext-intl": ">= 2.0",
"psr/http-message": "^1.0",
"behat/transliterator": "^1.2",
"psr/log": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.3",
"phpunit/phpunit": "^6.5",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^8.4",
"league/statsd": "^1.5"
},
"suggest": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
<logging>
Expand Down
3 changes: 1 addition & 2 deletions src/Bucket/Plain.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace HelloFresh\Stats\Bucket;

use Behat\Transliterator\Transliterator;
use HelloFresh\Stats\Bucket;

class Plain implements Bucket
Expand Down Expand Up @@ -78,7 +77,7 @@ public static function sanitizeMetricName($metric)
}

// convert unicode symbols to ASCII
$asciiMetric = Transliterator::utf8ToAscii($metric);
$asciiMetric = transliterator_transliterate('Any-Latin; Latin-ASCII;', $metric);
if ($asciiMetric != $metric) {
$metric = Bucket::PREFIX_UNICODE . $asciiMetric;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Bucket/PlainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testSanitizeMetricName()
{
$this->assertEquals('-', Plain::sanitizeMetricName(''));

$this->assertEquals('-u-iunikod', Plain::sanitizeMetricName('юникод'));
$this->assertEquals('-u-unikod', Plain::sanitizeMetricName('юникод'));
$this->assertEquals('-u-Apollon', Plain::sanitizeMetricName('Ἀπόλλων'));
$this->assertEquals('-u-acougue', Plain::sanitizeMetricName('açougue'));

Expand All @@ -49,7 +49,7 @@ public function testSanitizeMetricName()
Plain::sanitizeMetricName('metric.with.dots_and_underscores')
);

$this->assertEquals('-u-iunikod_metrika', Plain::sanitizeMetricName('юникод.метрика'));
$this->assertEquals('-u-unikod_metrika', Plain::sanitizeMetricName('юникод.метрика'));
}

public function metrics()
Expand Down
2 changes: 1 addition & 1 deletion tests/Client/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class LogTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Client/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class MemoryTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
7 changes: 3 additions & 4 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ public function testBuildStatsD()
$this->assertInstanceOf(Client\StatsD::class, Factory::build('statsd://qwe:1234/asd', $logger));
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Unknown client type
*/
public function testUnknownClient()
{
/** @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface $logger */
$logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unknown client type');

Factory::build(uniqid(), $logger);
}
}
10 changes: 4 additions & 6 deletions tests/HTTPMetricAlterCallback/HasIDAtSecondLevelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,20 @@ public function testRegisterSectionTest()

/**
* @dataProvider createFromStringMapProvider
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid sections format
*
* @param string $map
*/
public function testCreateFromStringMap_InvalidFormat($map)
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid sections format');
HasIDAtSecondLevel::createFromStringMap($map);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unknown section test callback name: foo
*/
public function testCreateFromStringMap_UnknownSectionTest()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown section test callback name: foo');
HasIDAtSecondLevel::createFromStringMap('users:foo');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Incrementer/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class LogTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Incrementer/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MemoryTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Incrementer/NoOpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class NoOpTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Incrementer/StatsDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class StatsDTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/State/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class LogTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/State/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MemoryTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/State/NoOpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class NoOpTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/State/StatsDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class StatsDTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
mt_srand(time());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Timer/MetricTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MetricTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
parent::setUp();
mt_srand(time());
Expand Down

0 comments on commit 58ca086

Please sign in to comment.