Skip to content

Commit 542d39d

Browse files
authored
Merge pull request #216 from fbourigault/data-collector-reset
Add reset method to collector
2 parents 3da46d5 + 78e3709 commit 542d39d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Collector/Collector.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Collector extends DataCollector
2727

2828
public function __construct()
2929
{
30-
$this->data['stacks'] = [];
30+
$this->reset();
3131
}
3232

3333
/**
@@ -38,6 +38,15 @@ public function collect(Request $request, Response $response, Exception $excepti
3838
// We do not need to collect any data from the Symfony Request and Response
3939
}
4040

41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function reset()
45+
{
46+
$this->data['stacks'] = [];
47+
$this->activeStack = null;
48+
}
49+
4150
/**
4251
* {@inheritdoc}
4352
*/

Tests/Unit/Collector/CollectorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,18 @@ public function testAddStack()
6969
$this->assertEquals(['acme'], $collector->getClients());
7070
$this->assertEquals([$stack], $collector->getClientRootStacks('acme'));
7171
}
72+
73+
public function testResetAction()
74+
{
75+
$stack = new Stack('acme', 'GET / HTTP/1.1');
76+
77+
$collector = new Collector();
78+
$collector->addStack($stack);
79+
$collector->activateStack($stack);
80+
81+
$collector->reset();
82+
83+
$this->assertNull($collector->getActiveStack());
84+
$this->assertEmpty($collector->getStacks());
85+
}
7286
}

0 commit comments

Comments
 (0)