From 97a4eb6bbff56679428d67d6e3bb9360355c1c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurens=20St=C3=B6tzel?= Date: Fri, 31 Mar 2017 08:52:01 +0200 Subject: [PATCH] Correct false positive tests for invalid label names, correct label check --- src/Prometheus/Histogram.php | 4 ++-- tests/Test/Prometheus/AbstractHistogramTest.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Prometheus/Histogram.php b/src/Prometheus/Histogram.php index 1d23999..9dbfda4 100644 --- a/src/Prometheus/Histogram.php +++ b/src/Prometheus/Histogram.php @@ -39,8 +39,8 @@ public function __construct(Adapter $adapter, $namespace, $name, $help, $labels ); } } - foreach ($buckets as $bucket) { - if ($bucket == 'le') { + foreach ($labels as $label) { + if ($label === 'le') { throw new \InvalidArgumentException("Histogram cannot have a label named 'le'."); } } diff --git a/tests/Test/Prometheus/AbstractHistogramTest.php b/tests/Test/Prometheus/AbstractHistogramTest.php index e83ff39..76d3f5b 100644 --- a/tests/Test/Prometheus/AbstractHistogramTest.php +++ b/tests/Test/Prometheus/AbstractHistogramTest.php @@ -374,6 +374,7 @@ public function itShouldProvideDefaultBuckets() /** * @test * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Histogram buckets must be in increasing order */ public function itShouldThrowAnExceptionWhenTheBucketSizesAreNotIncreasing() { @@ -383,6 +384,7 @@ public function itShouldThrowAnExceptionWhenTheBucketSizesAreNotIncreasing() /** * @test * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Histogram must have at least one bucket */ public function itShouldThrowAnExceptionWhenThereIsLessThanOneBucket() { @@ -392,15 +394,17 @@ public function itShouldThrowAnExceptionWhenThereIsLessThanOneBucket() /** * @test * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Histogram cannot have a label named */ public function itShouldThrowAnExceptionWhenThereIsALabelNamedLe() { - new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', array('le'), array()); + new Histogram($this->adapter, 'test', 'some_metric', 'this is for testing', array('le'), array(1)); } /** * @test * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid metric name */ public function itShouldRejectInvalidMetricsNames() { @@ -410,6 +414,7 @@ public function itShouldRejectInvalidMetricsNames() /** * @test * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Invalid label name */ public function itShouldRejectInvalidLabelNames() {