diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:30:02 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:30:02 -0400 |
commit | 1de335ad3f395ca6861085393ba366a9e3fb4a0d (patch) | |
tree | f1fdd326034e05177596851be6a7127615d81498 /vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php | |
parent | 9c75fa8ff6d4d38ef552c00fef5969fb154765e8 (diff) | |
parent | f6d65e533c62f6deb21342d4901ece24497b433e (diff) |
Merge commit 'f6d65'
# Conflicts:
# skins/ArchLinux/ArchLinux.php
Diffstat (limited to 'vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php')
-rw-r--r-- | vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php new file mode 100644 index 00000000..4608a601 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php @@ -0,0 +1,72 @@ +<?php + +namespace Liuggio\StatsdClient; + +use Liuggio\StatsdClient\StatsdClient; +use Liuggio\StatsdClient\Factory\StatsdDataFactory; +//use Liuggio\StatsdClient\Sender\SocketSender; + + +class ReadmeTest extends \PHPUnit_Framework_TestCase +{ + public function testFullUsageWithObject() { + + $sender = $this->mockSender(); + // $sender = new Sender(); + + // StatsdClient(SenderInterface $sender, $host = 'udp://localhost', $port = 8126, $reducePacket = true, $fail_silently = true) + $client = new StatsdClient($sender); + $factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); + + // create the data with the factory + $data[] = $factory->timing('usageTime', 100); + $data[] = $factory->increment('visitor'); + $data[] = $factory->decrement('click'); + $data[] = $factory->gauge('gaugor', 333); + $data[] = $factory->set('uniques', 765); + + // send the data as array or directly as object + $client->send($data); + } + + + + public function testFullUsageArray() { + + $sender = $this->mockSender(); + // $sender = new Sender(); + + // StatsdClient(SenderInterface $sender, $host = 'localhost', $port = 8126, $protocol='udp', $reducePacket = true, $fail_silently = true) + $client = new StatsdClient($sender, $host = 'localhost', $port = 8126, 'udp', $reducePacket = true, $fail_silently = true); + + $data[] ="increment:1|c"; + $data[] ="set:value|s"; + $data[] ="gauge:value|g"; + $data[] = "timing:10|ms"; + $data[] = "decrement:-1|c"; + $data[] ="key:1|c"; + + // send the data as array or directly as object + $client->send($data); + } + + + private function mockSender() { + $sender = $this->getMock('\Liuggio\StatsdClient\Sender\SenderInterface', array('open', 'write', 'close')); + $sender->expects($this->once()) + ->method('open') + ->will($this->returnValue(true)); + + $sender->expects($this->any()) //If you set the reduce = true into the StatsdClient the write will be called once + ->method('write') + ->will($this->returnCallBack(function($fp, $message) { + // echo PHP_EOL . "- " . $message; + })); + + $sender->expects($this->once()) + ->method('close') + ->will($this->returnValue(true)); + + return $sender; + } +}
\ No newline at end of file |