| 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 |
|
| 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 |
|
| 29 |
|
| 30 |
public function testPrefixingAndPassthrough( $method ) { |
| 31 |
|
| 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 |
|
| 41 |
$proxy->$method( 'metricname', 1, 2, 3, 4 ); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function testPrefixIsTrimmed( $method ) { |
| 48 |
|
| 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 |
|
| 58 |
$proxy->$method( 'metricname', 1, 2, 3, 4 ); |
| 59 |
} |
| 60 |
|
| 61 |
} |