Debian Codegraph @

tests/phpunit/unit/includes/libs/Stats/BufferingStatsdDataFactoryTest.php

raw symbols SCIP
1 <?php
2
3 namespace Wikimedia\Tests\Stats;
4
5 use PHPUnit\Framework\TestCase;
6 use Wikimedia\Stats\BufferingStatsdDataFactory;
7 use Wikimedia\TestingAccessWrapper;
8
9 /**
10 * @covers \Wikimedia\Stats\BufferingStatsdDataFactory
11 */
12 class BufferingStatsdDataFactoryTest extends TestCase {
13
14 public static function provideNormalizeMetricKey() {
15 // Reasonable and relied upon
16 yield 'Keep empty string' => [ '', '' ];
17 yield 'Keep normal' => [ 'foo.BarbaraBar.baz_quux', 'foo.BarbaraBar.baz_quux' ];
18 yield 'Skip empty segments' => [ '.missing.start.end.', 'missing.start.end' ];
19 yield 'Strip separator prefix' => [ '\\Vendor\\Class::method.x', 'Vendor_Class.method.x' ];
20
21 // Unreasonable and may change, here to self-document current behaviour
22 yield [ '__double__under__', 'double_under' ];
23 yield [ '.:!:.paamayim.:!:.nekudotayim.:!:.', 'paamayim._.nekudotayim' ];
24 yield [ 'first----.!!.!!.-second', 'first_._._._second' ];
25 }
26
27 /**
28 * @dataProvider provideNormalizeMetricKey
29 */
30 public function testNormalizeMetricKey( string $input, string $expected ) {
31 $stats = TestingAccessWrapper::newFromClass( BufferingStatsdDataFactory::class );
32 $this->assertSame( $expected, $stats->normalizeMetricKey( $input ) );
33 }
34 }