Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit 20966fb

Browse files
committed
Do not install statsd library by default
1 parent d774751 commit 20966fb

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ php:
77

88
script:
99
- composer install -n
10+
- vendor/bin/php-cs-fixer fix --dry-run -v
1011
- vendor/bin/phpunit
1112
- rm -rf vendor
1213
- composer update --prefer-lowest -n

composer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
{
22
"name": "hellofresh/stats-php",
3+
"keywords": [
4+
"logging",
5+
"stats"
6+
],
7+
"homepage": "https://github.com/hellofresh/stats-php",
8+
"license": "MIT",
39
"authors": [
410
{
511
"name": "Vladimir Garvardt",
612
"email": "[email protected]"
713
}
814
],
15+
"support": {
16+
"email": "[email protected]"
17+
},
918
"autoload": {
1019
"psr-4": {
1120
"HelloFresh\\Stats\\": "src/"
1221
}
1322
},
1423
"require": {
1524
"php": ">= 5.6",
16-
"league/statsd": "^1.4",
1725
"psr/http-message": "^1.0",
1826
"behat/transliterator": "^1.2",
1927
"psr/log": "^1.0"
2028
},
2129
"require-dev": {
2230
"friendsofphp/php-cs-fixer": "^2.3",
23-
"phpunit/phpunit": "^5.7"
31+
"phpunit/phpunit": "^5.7",
32+
"league/statsd": "^1.4"
33+
},
34+
"suggest": {
35+
"league/statsd": "Required for statsd backend"
2436
}
2537
}

src/Bucket/HTTPRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ class HTTPRequest extends Plain
1111
/**
1212
* HTTPRequest constructor.
1313
*
14-
* @param string $section
15-
* @param RequestInterface $request
16-
* @param bool $success
14+
* @param string $section
15+
* @param RequestInterface $request
16+
* @param bool $success
1717
* @param HTTPMetricAlterCallback|null $callback
1818
*/
1919
public function __construct($section, RequestInterface $request, $success, HTTPMetricAlterCallback $callback = null)
2020
{
21-
parent::__construct($section, $this->buildMetricOperation($request, $callback), $success);
21+
parent::__construct($section, static::buildMetricOperation($request, $callback), $success);
2222
}
2323

2424
/**
25-
* @param RequestInterface $request
25+
* @param RequestInterface $request
2626
* @param HTTPMetricAlterCallback|null $callback
2727
*
2828
* @return MetricOperation
2929
*/
30-
public function buildMetricOperation(RequestInterface $request, HTTPMetricAlterCallback $callback = null)
30+
public static function buildMetricOperation(RequestInterface $request, HTTPMetricAlterCallback $callback = null)
3131
{
3232
$operation = new MetricOperation([strtolower($request->getMethod())]);
3333
if ($request->getUri()->getPath() !== '/') {

tests/Client/StatsDTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class StatsDTest extends TestCase
1313
{
1414
public function testConfigure()
1515
{
16+
if (!class_exists('\League\StatsD\Client')) {
17+
$this->markTestSkipped('Missing league/statsd package');
18+
}
19+
1620
$statsClient = $this->getMockBuilder('\HelloFresh\Stats\Client\StatsD')
1721
->disableOriginalConstructor()
1822
->getMock();
@@ -40,6 +44,10 @@ public function testConfigure()
4044

4145
public function testInstances()
4246
{
47+
if (!class_exists('\League\StatsD\Client')) {
48+
$this->markTestSkipped('Missing league/statsd package');
49+
}
50+
4351
$statsClient = new StatsD('statsd://');
4452
$this->assertInstanceOf(Stats\Timer\StatsD::class, $statsClient->buildTimer());
4553

@@ -56,6 +64,10 @@ public function testInstances()
5664

5765
public function testHTTPRequestSection()
5866
{
67+
if (!class_exists('\League\StatsD\Client')) {
68+
$this->markTestSkipped('Missing league/statsd package');
69+
}
70+
5971
$section = uniqid('section', true);
6072

6173
/** @var \PHPUnit_Framework_MockObject_MockObject|\League\StatsD\Client $statsd */

tests/FactoryTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@ public function testBuild()
1212
/** @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface $logger */
1313
$logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
1414

15-
$this->assertInstanceOf(Client\StatsD::class, Factory::build('statsd://qwe:1234/asd', $logger));
1615
$this->assertInstanceOf(Client\Log::class, Factory::build('log://log', $logger));
1716
$this->assertInstanceOf(Client\NoOp::class, Factory::build('noop://noop', $logger));
1817
$this->assertInstanceOf(Client\Memory::class, Factory::build('memory://memory', $logger));
1918
}
2019

20+
public function testBuildStatsD()
21+
{
22+
if (!class_exists('\League\StatsD\Client')) {
23+
$this->markTestSkipped('Missing league/statsd package');
24+
}
25+
26+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface $logger */
27+
$logger = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
28+
29+
$this->assertInstanceOf(Client\StatsD::class, Factory::build('statsd://qwe:1234/asd', $logger));
30+
}
31+
2132
/**
2233
* @expectedException \RuntimeException
2334
* @expectedExceptionMessage Unknown client type

tests/Incrementer/StatsDTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ protected function setUp()
1414

1515
public function testMetrics()
1616
{
17+
if (!class_exists('\League\StatsD\Client')) {
18+
$this->markTestSkipped('Missing league/statsd package');
19+
}
20+
1721
/** @var \PHPUnit_Framework_MockObject_MockObject|\League\StatsD\Client $statsd */
1822
$statsd = $this->getMockBuilder('\League\StatsD\Client')->setMethods(['increment'])->getMock();
1923

tests/State/StatsDTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public function setUp()
1414

1515
public function testSet()
1616
{
17+
if (!class_exists('\League\StatsD\Client')) {
18+
$this->markTestSkipped('Missing league/statsd package');
19+
}
20+
1721
/** @var \PHPUnit_Framework_MockObject_MockObject|\League\StatsD\Client $statsd */
1822
$statsd = $this->getMockBuilder('\League\StatsD\Client')->setMethods(['gauge'])->getMock();
1923

tests/Timer/StatsDTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class StatsDTest extends TestCase
99
{
1010
public function testFinish()
1111
{
12+
if (!class_exists('\League\StatsD\Client')) {
13+
$this->markTestSkipped('Missing league/statsd package');
14+
}
15+
1216
/** @var \PHPUnit_Framework_MockObject_MockObject|\League\StatsD\Client $statsd */
1317
$statsd = $this->getMockBuilder('\League\StatsD\Client')->getMock();
1418

0 commit comments

Comments
 (0)