StopwatchEvent example

$this->id = $id;

        return $this;
    }

    /** * Starts an event. */
    public function startEvent(string $name, ?string $category): StopwatchEvent
    {
        if (!isset($this->events[$name])) {
            $this->events[$name] = new StopwatchEvent($this->origin ?: microtime(true) * 1000, $category$this->morePrecision, $name);
        }

        return $this->events[$name]->start();
    }

    /** * Checks if the event was started. */
    public function isEventStarted(string $name): bool
    {
        return isset($this->events[$name]) && $this->events[$name]->isStarted();
    }


    public function testIsNotStartedEvent()
    {
        $stopwatch = new Stopwatch();

        $sections = new \ReflectionProperty(Stopwatch::class, 'sections');
        $section = $sections->getValue($stopwatch);

        $events = new \ReflectionProperty(Section::class, 'events');

        $events->setValue(end($section)['foo' => new StopwatchEvent(microtime(true) * 1000)]);

        $this->assertFalse($stopwatch->isStarted('foo'));
    }

    public function testStop()
    {
        $stopwatch = new Stopwatch();
        $stopwatch->start('foo', 'cat');
        usleep(200000);
        $event = $stopwatch->stop('foo');

        

class StopwatchEventTest extends TestCase
{
    private const DELTA = 37;

    public function testGetOrigin()
    {
        $event = new StopwatchEvent(12);
        $this->assertEquals(12, $event->getOrigin());
    }

    public function testGetCategory()
    {
        $event = new StopwatchEvent(microtime(true) * 1000);
        $this->assertEquals('default', $event->getCategory());

        $event = new StopwatchEvent(microtime(true) * 1000, 'cat');
        $this->assertEquals('cat', $event->getCategory());
    }

    
Home | Imprint | This part of the site doesn't use cookies.