Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Update phpunit to version 8 (#23)
Browse files Browse the repository at this point in the history
* Update phpunit to version 8

* fix shield

* Require PHPUnit version at least 8.4
  • Loading branch information
martinssipenko authored and NoelDavies committed Nov 29, 2019
1 parent ce813f7 commit 44cccb4
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.iml
/.idea/
composer.lock
composer.phar
composer.phar
.phpunit.result.cache
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# A prometheus client library written in PHP

[![Build Status](https://travis-ci.org/Jimdo/prometheus_client_php.svg?branch=master)](https://travis-ci.org/Jimdo/prometheus_client_php)
[![CircleCI](https://circleci.com/gh/endclothing/prometheus_client_php/tree/master.svg?style=shield)](https://circleci.com/gh/endclothing/prometheus_client_php/tree/master)

This library uses Redis or APCu to do the client side aggregation.
If using Redis, we recommend to run a local Redis instance next to your PHP workers.
Expand Down Expand Up @@ -101,9 +101,9 @@ exponential / geometric buckets.
Eg:
```
Histogram::exponentialBuckets(0.05, 1.5, 10);
```
```

This will start your buckets with a value of 1.5, grow them by a factor of 1.5 per bucket across a set of 10 buckets.
This will start your buckets with a value of 1.5, grow them by a factor of 1.5 per bucket across a set of 10 buckets.

Also look at the [examples](examples).

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"symfony/polyfill-apcu": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^8.4",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
Expand Down
25 changes: 17 additions & 8 deletions tests/Test/Prometheus/AbstractCollectorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Prometheus\RenderTextFormat;
use Prometheus\Storage\Adapter;
use Prometheus\Storage\Redis;
use Prometheus\Exception\MetricsRegistrationException;
use Prometheus\Exception\MetricNotFoundException;

abstract class AbstractCollectorRegistryTest extends TestCase
{
Expand All @@ -21,7 +23,7 @@ abstract class AbstractCollectorRegistryTest extends TestCase
*/
private $renderer;

public function setUp()
public function setUp(): void
{
$this->configureAdapter();
$this->renderer = new RenderTextFormat();
Expand Down Expand Up @@ -204,77 +206,84 @@ public function itShouldIncreaseACounterWithoutNamespace()

/**
* @test
* @expectedException \Prometheus\Exception\MetricsRegistrationException
*/
public function itShouldForbidRegisteringTheSameCounterTwice()
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter('foo', 'metric', 'help');

$this->expectException(MetricsRegistrationException::class);
$registry->registerCounter('foo', 'metric', 'help');
}

/**
* @test
* @expectedException \Prometheus\Exception\MetricsRegistrationException
*/
public function itShouldForbidRegisteringTheSameCounterWithDifferentLabels()
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter('foo', 'metric', 'help', ["foo", "bar"]);

$this->expectException(MetricsRegistrationException::class);
$registry->registerCounter('foo', 'metric', 'help', ["spam", "eggs"]);
}

/**
* @test
* @expectedException \Prometheus\Exception\MetricsRegistrationException
*/
public function itShouldForbidRegisteringTheSameHistogramTwice()
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerHistogram('foo', 'metric', 'help');

$this->expectException(MetricsRegistrationException::class);
$registry->registerHistogram('foo', 'metric', 'help');
}

/**
* @test
* @expectedException \Prometheus\Exception\MetricsRegistrationException
*/
public function itShouldForbidRegisteringTheSameHistogramWithDifferentLabels()
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter('foo', 'metric', 'help', ["foo", "bar"]);

$this->expectException(MetricsRegistrationException::class);
$registry->registerCounter('foo', 'metric', 'help', ["spam", "eggs"]);
}

/**
* @test
* @expectedException \Prometheus\Exception\MetricsRegistrationException
*/
public function itShouldForbidRegisteringTheSameGaugeTwice()
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerGauge('foo', 'metric', 'help');

$this->expectException(MetricsRegistrationException::class);
$registry->registerGauge('foo', 'metric', 'help');
}

/**
* @test
* @expectedException \Prometheus\Exception\MetricsRegistrationException
*/
public function itShouldForbidRegisteringTheSameGaugeWithDifferentLabels()
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerGauge('foo', 'metric', 'help', ["foo", "bar"]);

$this->expectException(MetricsRegistrationException::class);
$registry->registerGauge('foo', 'metric', 'help', ["spam", "eggs"]);
}

/**
* @test
* @expectedException \Prometheus\Exception\MetricNotFoundException
*/
public function itShouldThrowAnExceptionWhenGettingANonExistentMetric()
{
$registry = new CollectorRegistry($this->adapter);

$this->expectException(MetricNotFoundException::class);
$registry->getGauge("not_here", "go_away");
}

Expand Down
16 changes: 8 additions & 8 deletions tests/Test/Prometheus/AbstractCounterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractCounterTest extends TestCase
*/
public $adapter;

public function setUp()
public function setUp(): void
{
$this->configureAdapter();
}
Expand Down Expand Up @@ -127,19 +127,19 @@ public function itShouldIncreaseTheCounterByAnArbitraryInteger()

/**
* @test
* @expectedException InvalidArgumentException
*/
public function itShouldRejectInvalidMetricsNames()
{
$this->expectException(InvalidArgumentException::class);
new Counter($this->adapter, 'test', 'some metric invalid metric', 'help');
}

/**
* @test
* @expectedException InvalidArgumentException
*/
public function itShouldRejectInvalidLabelNames()
{
$this->expectException(InvalidArgumentException::class);
new Counter($this->adapter, 'test', 'some_metric', 'help', ['invalid label']);
}

Expand All @@ -156,20 +156,20 @@ public function isShouldAcceptAnySequenceOfBasicLatinCharactersForLabelValues($v
$histogram->inc([$value]);

$metrics = $this->adapter->collect();
self::assertInternalType('array', $metrics);
self::assertCount(1, $metrics);
self::assertContainsOnlyInstancesOf(MetricFamilySamples::class, $metrics);
$this->assertIsArray($metrics);
$this->assertCount(1, $metrics);
$this->assertContainsOnlyInstancesOf(MetricFamilySamples::class, $metrics);

$metric = reset($metrics);
$samples = $metric->getSamples();
self::assertContainsOnlyInstancesOf(Sample::class, $samples);
$this->assertContainsOnlyInstancesOf(Sample::class, $samples);

foreach ($samples as $sample) {
$labels = array_combine(
array_merge($metric->getLabelNames(), $sample->getLabelNames()),
$sample->getLabelValues()
);
self::assertEquals($value, $labels[$label]);
$this->assertEquals($value, $labels[$label]);
}
}

Expand Down
16 changes: 8 additions & 8 deletions tests/Test/Prometheus/AbstractGaugeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractGaugeTest extends TestCase
*/
public $adapter;

public function setUp()
public function setUp(): void
{
$this->configureAdapter();
}
Expand Down Expand Up @@ -295,19 +295,19 @@ public function itShouldOverwriteWhenSettingTwice()

/**
* @test
* @expectedException InvalidArgumentException
*/
public function itShouldRejectInvalidMetricsNames()
{
$this->expectException(InvalidArgumentException::class);
new Gauge($this->adapter, 'test', 'some metric invalid metric', 'help');
}

/**
* @test
* @expectedException InvalidArgumentException
*/
public function itShouldRejectInvalidLabelNames()
{
$this->expectException(InvalidArgumentException::class);
new Gauge($this->adapter, 'test', 'some_metric', 'help', ['invalid label']);
}

Expand All @@ -324,20 +324,20 @@ public function isShouldAcceptAnySequenceOfBasicLatinCharactersForLabelValues($v
$histogram->inc([$value]);

$metrics = $this->adapter->collect();
self::assertInternalType('array', $metrics);
self::assertCount(1, $metrics);
self::assertContainsOnlyInstancesOf(MetricFamilySamples::class, $metrics);
$this->assertIsArray($metrics);
$this->assertCount(1, $metrics);
$this->assertContainsOnlyInstancesOf(MetricFamilySamples::class, $metrics);

$metric = reset($metrics);
$samples = $metric->getSamples();
self::assertContainsOnlyInstancesOf(Sample::class, $samples);
$this->assertContainsOnlyInstancesOf(Sample::class, $samples);

foreach ($samples as $sample) {
$labels = array_combine(
array_merge($metric->getLabelNames(), $sample->getLabelNames()),
$sample->getLabelValues()
);
self::assertEquals($value, $labels[$label]);
$this->assertEquals($value, $labels[$label]);
}
}

Expand Down
34 changes: 17 additions & 17 deletions tests/Test/Prometheus/AbstractHistogramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractHistogramTest extends TestCase
*/
public $adapter;

public function setUp()
public function setUp(): void
{
$this->configureAdapter();
}
Expand Down Expand Up @@ -374,51 +374,51 @@ public function itShouldProvideDefaultBuckets()

/**
* @test
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Histogram buckets must be in increasing order
*/
public function itShouldThrowAnExceptionWhenTheBucketSizesAreNotIncreasing()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Histogram buckets must be in increasing order');
new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', [], [1, 1]);
}

/**
* @test
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Histogram must have at least one bucket
*/
public function itShouldThrowAnExceptionWhenThereIsLessThanOneBucket()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Histogram must have at least one bucket');
new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', [], []);
}

/**
* @test
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Histogram cannot have a label named
*/
public function itShouldThrowAnExceptionWhenThereIsALabelNamedLe()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Histogram cannot have a label named');
new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', ['le'], [1]);
}

/**
* @test
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid metric name
*/
public function itShouldRejectInvalidMetricsNames()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid metric name');
new Histogram($this->adapter, 'test', 'some invalid metric', 'help', [], [1]);
}

/**
* @test
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid label name
*/
public function itShouldRejectInvalidLabelNames()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid label name');
new Histogram($this->adapter, 'test', 'some_metric', 'help', ['invalid label'], [1]);
}

Expand All @@ -435,20 +435,20 @@ public function isShouldAcceptAnySequenceOfBasicLatinCharactersForLabelValues($v
$histogram->observe(1, [$value]);

$metrics = $this->adapter->collect();
self::assertInternalType('array', $metrics);
self::assertCount(1, $metrics);
self::assertContainsOnlyInstancesOf(MetricFamilySamples::class, $metrics);
$this->assertIsArray($metrics);
$this->assertCount(1, $metrics);
$this->assertContainsOnlyInstancesOf(MetricFamilySamples::class, $metrics);

$metric = reset($metrics);
$samples = $metric->getSamples();
self::assertContainsOnlyInstancesOf(Sample::class, $samples);
$this->assertContainsOnlyInstancesOf(Sample::class, $samples);

foreach ($samples as $sample) {
$labels = array_combine(
array_merge($metric->getLabelNames(), $sample->getLabelNames()),
$sample->getLabelValues()
);
self::assertEquals($value, $labels[$label]);
$this->assertEquals($value, $labels[$label]);
}
}

Expand Down Expand Up @@ -480,7 +480,7 @@ public function itShouldBeAbleToGenerateExponentialBucketsGivenSpecificBounds()
9.7309753417969,
];

self::assertEquals($generatedBuckets, $expectedBuckets);
$this->assertEquals($generatedBuckets, $expectedBuckets);
}

/**
Expand Down

0 comments on commit 44cccb4

Please sign in to comment.