From 7beaf369b1bab7b2b76ed06e3218d98b5f5b591a Mon Sep 17 00:00:00 2001 From: Corentin Larose Date: Fri, 12 Jul 2013 12:16:00 +0200 Subject: [PATCH 1/3] Fix typo at line 55 --- src/Filter/Sample.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter/Sample.php b/src/Filter/Sample.php index 228302c2..c2802eda 100644 --- a/src/Filter/Sample.php +++ b/src/Filter/Sample.php @@ -52,6 +52,6 @@ public function __construct($sampleRate = 1) */ public function filter(array $event) { - return (mt_rand() / mt_getrandmax()) <= $this->$_sampleRate; + return (mt_rand() / mt_getrandmax()) <= $this->_sampleRate; } } From b5d18eb2996d53fecaf29adaaa8e66eed8718c12 Mon Sep 17 00:00:00 2001 From: Corentin Larose Date: Fri, 12 Jul 2013 13:00:31 +0200 Subject: [PATCH 2/3] Removed trailing spaces (damn !) --- src/Filter/Sample.php | 8 ++++---- test/Filter/SampleTest.php | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Filter/Sample.php b/src/Filter/Sample.php index c2802eda..ce09a851 100644 --- a/src/Filter/Sample.php +++ b/src/Filter/Sample.php @@ -16,7 +16,7 @@ class Sample implements FilterInterface { /** * Sample rate [0-1]. - * + * * @var float */ protected $_sampleRate; @@ -27,7 +27,7 @@ class Sample implements FilterInterface * Sample rate must be a float number between 0 and 1 included. * If 0.5, only half of the values will be logged. * If 0.1 only 1 among 10 values will be logged. - * + * * @param float|int $samplerate Sample rate [0-1]. * @return Priority * @throws Exception\InvalidArgumentException @@ -40,10 +40,10 @@ public function __construct($sampleRate = 1) gettype($sampleRate) )); } - + $this->_sampleRate = (float) $sampleRate; } - + /** * Returns TRUE to accept the message, FALSE to block it. * diff --git a/test/Filter/SampleTest.php b/test/Filter/SampleTest.php index 70d5ef4d..56972288 100644 --- a/test/Filter/SampleTest.php +++ b/test/Filter/SampleTest.php @@ -25,7 +25,7 @@ public function testConstructorThrowsOnInvalidSampleRate() $this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'must be numeric'); new Sample('bar'); } - + public function testSampleLimit0() { // Should log nothing. @@ -35,11 +35,28 @@ public function testSampleLimit0() $ret = false; for ($i = 0; $i < 100; $i ++) { if ($filter->filter(array())) { - break; + break; $ret = true; - } + } } - + $this->assertFalse($ret); } + + public function testSampleLimit1() + { + // Should log all events. + $filter = new Sample(1); + + // Since sampling is a random process, let's test several times. + $ret = true; + for ($i = 0; $i < 100; $i ++) { + if (! $filter->filter(array())) { + break; + $ret = false; + } + } + + $this->assertTrue($ret); + } } From 1f399468cc630c30f9107315a388caab4799ac0d Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 19 Jul 2013 09:17:55 -0500 Subject: [PATCH 3/3] [zendframework/zf2#4813] remove underscore - no longer underscore-prefixing non-public properties --- src/Filter/Sample.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Filter/Sample.php b/src/Filter/Sample.php index ce09a851..ae0c8882 100644 --- a/src/Filter/Sample.php +++ b/src/Filter/Sample.php @@ -19,7 +19,7 @@ class Sample implements FilterInterface * * @var float */ - protected $_sampleRate; + protected $sampleRate; /** * Filters logging by sample rate. @@ -41,17 +41,17 @@ public function __construct($sampleRate = 1) )); } - $this->_sampleRate = (float) $sampleRate; + $this->sampleRate = (float) $sampleRate; } /** * Returns TRUE to accept the message, FALSE to block it. * - * @param array $event event data + * @param array $event event data * @return bool Accepted ? */ public function filter(array $event) { - return (mt_rand() / mt_getrandmax()) <= $this->_sampleRate; + return (mt_rand() / mt_getrandmax()) <= $this->sampleRate; } }