setClock example

class ClockAwareTraitTest extends TestCase
{
    public function testTrait()
    {
        $sut = new ClockAwareTestImplem();

        $this->assertInstanceOf(DatePoint::class$sut->now());

        $clock = new MockClock();
        $sut = new $sut();
        $sut->setClock($clock);

        $ts = $sut->now()->getTimestamp();
        $this->assertEquals($clock->now()$sut->now());
        $clock->sleep(1);
        $this->assertEquals($clock->now()$sut->now());
        $this->assertSame(1.0, round($sut->now()->getTimestamp() - $ts, 1));
    }
}

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