Skip to content

Commit

Permalink
Merge pull request #34 from DeepDiver1975/fix/33
Browse files Browse the repository at this point in the history
fix: exporting an unknown group no longer results in ErrorException
  • Loading branch information
rennokki authored Apr 29, 2022
2 parents a2e7add + 6707651 commit 377e3f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.phar
composer.lock
.DS_Store
database.sqlite
.phpunit.result.cache
2 changes: 1 addition & 1 deletion src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static function run(string $group = 'metrics')
static::$registeredMetrics[$metricClass] = $metric;
}

return static::$registries[$group];
return static::$registries[$group] ?? new CollectorRegistry(new InMemory);
}

/**
Expand Down
14 changes: 10 additions & 4 deletions tests/MetricTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class MetricTest extends TestCase
{
public function test_registering_metric()
public function test_registering_metric(): void
{
Exporter::metrics([TestMetric::class]);
Exporter::metrics([TestMetric::class]);
Expand Down Expand Up @@ -38,7 +38,7 @@ public function test_registering_metric()
->assertDontSee('laravel_test_metric');
}

public function test_metrics_modification_without_update()
public function test_metrics_modification_without_update(): void
{
Exporter::metrics([OutsideMetric::class]);

Expand All @@ -57,7 +57,7 @@ public function test_metrics_modification_without_update()
);
}

public function test_response_with_plain_text()
public function test_response_with_plain_text(): void
{
Exporter::metrics([OutsideMetric::class]);

Expand All @@ -78,7 +78,7 @@ public function test_response_with_plain_text()
);
}

public function test_response_with_plain_text_on_different_group()
public function test_response_with_plain_text_on_different_group(): void
{
Exporter::metrics([OutsideMetric::class]);

Expand All @@ -103,4 +103,10 @@ public function test_response_with_plain_text_on_different_group()
Exporter::exportAsPlainText('metrics2')
);
}

public function test_unknown_group(): void
{
$registry = Exporter::run('you-dont-know-me');
self::assertNotNull($registry);
}
}

0 comments on commit 377e3f3

Please sign in to comment.