From 78e3709c0983f4c193780dde22fedc92acd43bd7 Mon Sep 17 00:00:00 2001 From: Fabien Bourigault Date: Mon, 6 Nov 2017 09:24:14 +0100 Subject: [PATCH] add reset method to collector --- Collector/Collector.php | 11 ++++++++++- Tests/Unit/Collector/CollectorTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Collector/Collector.php b/Collector/Collector.php index 406cb694..1a02d9c3 100644 --- a/Collector/Collector.php +++ b/Collector/Collector.php @@ -27,7 +27,7 @@ class Collector extends DataCollector public function __construct() { - $this->data['stacks'] = []; + $this->reset(); } /** @@ -38,6 +38,15 @@ public function collect(Request $request, Response $response, Exception $excepti // We do not need to collect any data from the Symfony Request and Response } + /** + * {@inheritdoc} + */ + public function reset() + { + $this->data['stacks'] = []; + $this->activeStack = null; + } + /** * {@inheritdoc} */ diff --git a/Tests/Unit/Collector/CollectorTest.php b/Tests/Unit/Collector/CollectorTest.php index 7bd8766a..9cb37c77 100644 --- a/Tests/Unit/Collector/CollectorTest.php +++ b/Tests/Unit/Collector/CollectorTest.php @@ -69,4 +69,18 @@ public function testAddStack() $this->assertEquals(['acme'], $collector->getClients()); $this->assertEquals([$stack], $collector->getClientRootStacks('acme')); } + + public function testResetAction() + { + $stack = new Stack('acme', 'GET / HTTP/1.1'); + + $collector = new Collector(); + $collector->addStack($stack); + $collector->activateStack($stack); + + $collector->reset(); + + $this->assertNull($collector->getActiveStack()); + $this->assertEmpty($collector->getStacks()); + } }