Skip to content

Commit

Permalink
Merge branch 'master' into add_options
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Preusner authored Oct 31, 2017
2 parents cabb52c + 07e9693 commit 9485db1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/DataCollector/HttpDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ class HttpDataCollector extends DataCollector
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
$this->data = [
'logs' => [],
'callCount' => 0,
];

$this->reset();
}

/**
Expand Down Expand Up @@ -67,6 +65,17 @@ public function getName() : string
return 'eight_points_guzzle';
}

/**
* Resets this data collector to its initial state.
*/
public function reset()
{
$this->data = [
'logs' => [],
'callCount' => 0,
];
}

/**
* Returning log entries
*
Expand Down
39 changes: 38 additions & 1 deletion tests/DataCollector/HttpDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class HttpDataCollectorTest extends TestCase
{
/**
* @var Logger
* @var Logger|\PHPUnit_Framework_MockObject_MockObject
*/
protected $logger;

Expand Down Expand Up @@ -184,6 +184,43 @@ public function testCallCount()
$this->assertSame(2, $collector->getCallCount());
}

/**
* Test reset method
*
* @covers \EightPoints\Bundle\GuzzleBundle\DataCollector\HttpDataCollector::reset
*/
public function testReset()
{
$this->logger->expects($this->once())
->method('getMessages')
->willReturn(['test message #1', 'test message #2']);

$collector = new HttpDataCollector($this->logger);

$response = $this->getMockBuilder(Response::class)
->getMock();

$request = $this->getMockBuilder(Request::class)
->getMock();

$request->expects($this->once())
->method('getUri')
->willReturn('someRandomUrlId');

$request->expects($this->once())
->method('getPathInfo')
->willReturn('id');

$collector->collect($request, $response);

$this->assertSame(2, $collector->getCallCount());

$collector->reset();

$this->assertSame(0, $collector->getCallCount());
$this->assertCount(0, $collector->getLogs());
}

/**
* Test Error Count
*
Expand Down

0 comments on commit 9485db1

Please sign in to comment.