Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / SamplingStatsdClientTest.php
1 <?php
2
3 use Liuggio\StatsdClient\Entity\StatsdData;
4
5 class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase {
6 /**
7 * @dataProvider samplingDataProvider
8 */
9 public function testSampling( $data, $sampleRate, $seed, $expectWrite ) {
10 $sender = $this->getMock( 'Liuggio\StatsdClient\Sender\SenderInterface' );
11 $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) );
12 if ( $expectWrite ) {
13 $sender->expects( $this->once() )->method( 'write' )
14 ->with( $this->anything(), $this->equalTo( $data ) );
15 } else {
16 $sender->expects( $this->never() )->method( 'write' );
17 }
18 mt_srand( $seed );
19 $client = new SamplingStatsdClient( $sender );
20 $client->send( $data, $sampleRate );
21 }
22
23 public function samplingDataProvider() {
24 $unsampled = new StatsdData();
25 $unsampled->setKey( 'foo' );
26 $unsampled->setValue( 1 );
27
28 $sampled = new StatsdData();
29 $sampled->setKey( 'foo' );
30 $sampled->setValue( 1 );
31 $sampled->setSampleRate( '0.1' );
32
33 return [
34 // $data, $sampleRate, $seed, $expectWrite
35 [ $unsampled, 1, 0 /*0.44*/, $unsampled ],
36 [ $sampled, 1, 0 /*0.44*/, null ],
37 [ $sampled, 1, 4 /*0.03*/, $sampled ],
38 [ $unsampled, 0.1, 4 /*0.03*/, $sampled ],
39 [ $sampled, 0.5, 0 /*0.44*/, null ],
40 [ $sampled, 0.5, 4 /*0.03*/, $sampled ],
41 ];
42 }
43 }