diff --git a/src/BatchedDogStatsd.php b/src/BatchedDogStatsd.php index ffb7822..98fdc1d 100644 --- a/src/BatchedDogStatsd.php +++ b/src/BatchedDogStatsd.php @@ -55,4 +55,12 @@ public function flushBuffer() static::$buffer = array(); static::$bufferLength = 0; } + + /** + * @return int + */ + public static function getBufferLength() + { + return self::$bufferLength; + } } diff --git a/tests/UnitTests/BatchedDogStatsdTest.php b/tests/UnitTests/BatchedDogStatsdTest.php index 7594d91..cf4b467 100644 --- a/tests/UnitTests/BatchedDogStatsdTest.php +++ b/tests/UnitTests/BatchedDogStatsdTest.php @@ -2,6 +2,7 @@ namespace DataDog\UnitTests; +use A\B; use DataDog\BatchedDogStatsd; use DataDog\TestHelpers\SocketSpy; use DataDog\TestHelpers\SocketSpyTestCase; @@ -74,4 +75,34 @@ public function testReportSendsOnceBufferIsFilled() array("metrics" => 3) ); } + + public function testGetBufferLength() { + // Given + $batchedDog = new BatchedDogStatsd(); + + // assert pre-condition + $this->assertEquals(0, BatchedDogStatsd::getBufferLength()); + + // When + $batchedDog->gauge("some-value", 1); + + // Then + $this->assertEquals(1, BatchedDogStatsd::getBufferLength()); + } + + public function testGetBufferLengthAfterExceedingMaxBufferLength() + { + // Given + BatchedDogStatsd::$maxBufferLength = 2; + + // And + $batchedDog = new BatchedDogStatsd(); + + // When + $batchedDog->increment(["first-value", "another-value", "yet-another-value"]); + $batchedDog->gauge("some-value", 1); + + // Then + $this->assertEquals(1, BatchedDogStatsd::getBufferLength()); + } }