|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sentry\SentryBundle\Tests\End2End; |
| 6 | + |
| 7 | +use Sentry\SentryBundle\Tests\End2End\App\KernelWithMetrics; |
| 8 | +use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 9 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 10 | +use Symfony\Component\Console\Input\ArgvInput; |
| 11 | +use Symfony\Component\Console\Output\NullOutput; |
| 12 | + |
| 13 | +/** |
| 14 | + * @runTestsInSeparateProcesses |
| 15 | + */ |
| 16 | +class MetricsCommandTest extends WebTestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var Application |
| 20 | + */ |
| 21 | + private $application; |
| 22 | + |
| 23 | + protected static function getKernelClass(): string |
| 24 | + { |
| 25 | + return KernelWithMetrics::class; |
| 26 | + } |
| 27 | + |
| 28 | + protected function setUp(): void |
| 29 | + { |
| 30 | + StubTransport::$events = []; |
| 31 | + $this->application = new Application(self::bootKernel()); |
| 32 | + } |
| 33 | + |
| 34 | + public function testMetricsInCommand(): void |
| 35 | + { |
| 36 | + $this->application->doRun(new ArgvInput(['bin/console', 'metrics:test']), new NullOutput()); |
| 37 | + |
| 38 | + $this->assertCount(1, StubTransport::$events); |
| 39 | + $metrics = StubTransport::$events[0]->getMetrics(); |
| 40 | + |
| 41 | + $this->assertCount(3, $metrics); |
| 42 | + |
| 43 | + $count = $metrics[0]; |
| 44 | + $this->assertSame('test-counter', $count->getName()); |
| 45 | + $this->assertSame(10.0, $count->getValue()); |
| 46 | + |
| 47 | + $gauge = $metrics[1]; |
| 48 | + $this->assertSame('test-gauge', $gauge->getName()); |
| 49 | + $this->assertSame(20.51, $gauge->getValue()); |
| 50 | + |
| 51 | + $distribution = $metrics[2]; |
| 52 | + $this->assertSame('test-distribution', $distribution->getName()); |
| 53 | + $this->assertSame(100.81, $distribution->getValue()); |
| 54 | + } |
| 55 | +} |
0 commit comments