Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 namespace Wikimedia\Tests\Stats;
4
5 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
6 use PHPUnit\Framework\MockObject\MockObject;
7 use PHPUnit\Framework\TestCase;
8 use Wikimedia\Stats\PrefixingStatsdDataFactoryProxy;
9
10 /**
11 * @covers \Wikimedia\Stats\PrefixingStatsdDataFactoryProxy
12 */
13 class PrefixingStatsdDataFactoryProxyTest extends TestCase {
14
15 public static function provideMethodNames() {
16 return [
17 [ 'timing' ],
18 [ 'gauge' ],
19 [ 'set' ],
20 [ 'increment' ],
21 [ 'decrement' ],
22 [ 'updateCount' ],
23 [ 'produceStatsdData' ],
24 ];
25 }
26
27 /**
28 * @dataProvider provideMethodNames
29 */
30 public function testPrefixingAndPassthrough( $method ) {
31 /** @var StatsdDataFactoryInterface|MockObject $innerFactory */
32 $innerFactory = $this->createMock(
33 StatsdDataFactoryInterface::class
34 );
35 $innerFactory->expects( $this->once() )
36 ->method( $method )
37 ->with( 'testprefix.metricname' );
38
39 $proxy = new PrefixingStatsdDataFactoryProxy( $innerFactory, 'testprefix' );
40 // 1,2,3,4 simply makes sure we provide enough parameters, without caring what they are
41 $proxy->$method( 'metricname', 1, 2, 3, 4 );
42 }
43
44 /**
45 * @dataProvider provideMethodNames
46 */
47 public function testPrefixIsTrimmed( $method ) {
48 /** @var StatsdDataFactoryInterface|MockObject $innerFactory */
49 $innerFactory = $this->createMock(
50 StatsdDataFactoryInterface::class
51 );
52 $innerFactory->expects( $this->once() )
53 ->method( $method )
54 ->with( 'testprefix.metricname' );
55
56 $proxy = new PrefixingStatsdDataFactoryProxy( $innerFactory, 'testprefix...' );
57 // 1,2,3,4 simply makes sure we provide enough parameters, without caring what they are
58 $proxy->$method( 'metricname', 1, 2, 3, 4 );
59 }
60
61 }