Added generic stopwatch collector and tests.

This commit is contained in:
Andrey Savchenko committed 2018-02-20 18:09:44 +02:00
1 parent 7020e84b2d
commit 420305143b
7 files changed
+215 -71

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Rarst\Laps\Tests\Record;
use Rarst\Laps\Record\Stopwatch_Record;
use Rarst\Laps\Record\Stopwatch_Record_Collector;
use Rarst\Laps\Tests\LapsTestCase;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;
class StopwatchTest extends LapsTestCase {
/**
* @covers \Rarst\Laps\Record\Stopwatch_Record_Collector
*/
public function testCollector() {
$collector = new Stopwatch_Record_Collector( new Stopwatch() );
$collector->start( 'Event', 'info' );
$collector->start( 'Not stopped', 'info' );
$event = $collector->stop( 'Event' );
$this->assertFalse( $collector->stop( 'Not event' ) );
$records = $collector->get_records();
$this->assertInternalType( 'array', $records );
$this->assertCount( 1, $records );
$this->assertInstanceOf( Stopwatch_Record::class, $records[0] );
return $event;
}
/**
* @depends testCollector
* @covers \Rarst\Laps\Record\Stopwatch_Record
*
* @param StopwatchEvent $event Event instance.
*/
public function testRecord( StopwatchEvent $event ) {
$record = new Stopwatch_Record( 'Event', $event );
$this->assertEquals( 'Event', $record->get_name() );
$this->assertEquals( 'info', $record->get_category() );
$this->assertEquals( $event->getOrigin(), $record->get_origin() );
$this->assertEquals( $event->getDuration(), $record->get_duration() );
$this->assertContains( 'Event', $record->get_description() );
}
}