diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /vendor/liuggio/statsd-php-client/tests | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'vendor/liuggio/statsd-php-client/tests')
3 files changed, 86 insertions, 0 deletions
diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.php index fad9175c..fad9175c 100644..100755 --- a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.php +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.php diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php new file mode 100644 index 00000000..dcf2710d --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php @@ -0,0 +1,86 @@ +<?php + +namespace Liuggio\StatsdClient\Entity; + +use Liuggio\StatsdClient\Service\StatsdService; + +class StatsdServiceTest extends \PHPUnit_Framework_TestCase +{ + private $clientMock; + private $factoryMock; + + public function setUp() + { + $this->clientMock = $this->getMockBuilder('Liuggio\StatsdClient\StatsdClient') + ->disableOriginalConstructor() + ->getMock(); + $this->factoryMock = $this->getMockBuilder('Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface') + ->disableOriginalConstructor() + ->getMock(); + } + + public function testConstructorWithoutFactory() + { + $dut = new StatsdService($this->clientMock); + $dut->timing('foo.bar', 123); + } + + public function testFactoryImplementation() + { + $data = new StatsdData(); + + // Configure the client mock. + $this->factoryMock->expects($this->once())->method('timing')->willReturn($data); + $this->factoryMock->expects($this->once())->method('gauge')->willReturn($data); + $this->factoryMock->expects($this->once())->method('set')->willReturn($data); + $this->factoryMock->expects($this->once())->method('increment')->willReturn($data); + $this->factoryMock->expects($this->once())->method('decrement')->willReturn($data); + $this->factoryMock->expects($this->once())->method('updateCount')->willReturn($data); + + // Actual test + $dut = new StatsdService($this->clientMock, $this->factoryMock); + $dut->timing('foo.bar', 123); + $dut->gauge('foo.bar', 123); + $dut->set('foo.bar', 123); + $dut->increment('foo.bar'); + $dut->decrement('foo.bar'); + $dut->updateCount('foo.bar', 123); + } + + public function testFlush() + { + $data = new StatsdData(); + $this->factoryMock->expects($this->once())->method('timing')->willReturn($data); + $this->clientMock->expects($this->once())->method('send') + ->with($this->equalTo(array($data))); + + // Actual test + $dut = new StatsdService($this->clientMock, $this->factoryMock); + $dut->timing('foobar', 123); + $dut->flush(); + } + + public function testSampling() + { + $tries = false; + $closure = function($a, $b) use (&$tries) { + $tries = !$tries; + return $tries ? 1 : 0; + }; + + $data = new StatsdData(); + $this->factoryMock->expects($this->exactly(2))->method('timing')->willReturn($data); + $this->clientMock->expects($this->once())->method('send') + ->with($this->equalTo(array($data))); + + // Actual test + $dut = new StatsdService($this->clientMock, $this->factoryMock); + $dut->setSamplingRate(0.1); + $dut->setSamplingFunction($closure); + $dut->timing('foo', 123); + $dut->timing('bar', 123); + $dut->flush(); + + $this->assertSame(0.1, $data->getSampleRate()); + } +} diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php index 144f629c..144f629c 100644..100755 --- a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php |