• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 9045933531

11 May 2024 07:25PM UTC coverage: 86.566% (+0.3%) from 86.24%
9045933531

Pull #240

github

web-flow
Merge ef4f1596e into d6a8ae2f5
Pull Request #240: feat: Adds Timebox utility class and extends Clock

30 of 33 new or added lines in 4 files covered. (90.91%)

21 existing lines in 4 files now uncovered.

1321 of 1526 relevant lines covered (86.57%)

10.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/Clock/MockClock.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Clock;
6

7
use DateInterval;
8
use DateTimeImmutable;
9
use DateTimeInterface;
10

11
final class MockClock implements Clock
12
{
13
    private DateTimeImmutable $now;
14

15
    public function __construct(DateTimeInterface|string $now = 'now')
16
    {
17
        $this->now = $now instanceof DateTimeInterface
9✔
18
            ? DateTimeImmutable::createFromInterface($now)
4✔
19
            : new DateTimeImmutable($now);
5✔
20
    }
21

22
    public function now(): DateTimeImmutable
23
    {
24
        return $this->now;
3✔
25
    }
26

27
    public function time(TimeUnit $unit = TimeUnit::SECOND): int
28
    {
29
        return (int) floor((($this->now->getTimestamp() * 1_000_000 + (int) $this->now->format('u')) / $unit->toMicroseconds()));
9✔
30
    }
31

32
    public function sleep(int $time, TimeUnit $unit = TimeUnit::SECOND): void
33
    {
34
        $this->now = $this->now->add(
4✔
35
            DateInterval::createFromDateString("$time $unit->value")
4✔
36
        );
4✔
37
    }
38

39
    public function changeTime(int $time, TimeUnit $unit = TimeUnit::SECOND): void
40
    {
41
        if ($time < 0) {
2✔
NEW
42
            $time = abs($time);
×
NEW
43
            $this->now = $this->now->sub(DateInterval::createFromDateString("$time $unit->value"));
×
44
        } else {
45
            $this->now = $this->now->add(DateInterval::createFromDateString("$time $unit->value"));
2✔
46
        }
47
    }
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc