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

NexusPHP / framework / 16868376028

02 Aug 2025 01:15PM UTC coverage: 100.0%. Remained the same
16868376028

push

github

paulbalandan
Remove use of deprecated `DATE_RFC7231` constant

1 of 1 new or added line in 1 file covered. (100.0%)

1176 of 1176 relevant lines covered (100.0%)

9.77 hits per line

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

100.0
/src/Nexus/Clock/Extension/ClockSensitive.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of the Nexus framework.
7
 *
8
 * (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Nexus\Clock\Extension;
15

16
use Nexus\Clock\Clock;
17
use Nexus\Clock\FrozenClock;
18
use Nexus\Clock\InternalClock;
19
use PHPUnit\Framework\Attributes\After;
20
use PHPUnit\Framework\Attributes\Before;
21

22
/**
23
 * Trait to be used by test cases when mocking the clock.
24
 */
25
trait ClockSensitive
26
{
27
    private static ?Clock $originalClock = null;
28

29
    #[Before]
30
    protected static function saveClock(): void
31
    {
32
        self::$originalClock = InternalClock::getCurrent();
2✔
33
    }
34

35
    #[After]
36
    protected static function restoreClock(): void
37
    {
38
        if (null !== self::$originalClock) {
2✔
39
            InternalClock::set(self::$originalClock);
2✔
40
            self::$originalClock = null;
2✔
41
        }
42
    }
43

44
    /**
45
     * Mocks the current time to a fixed non-moving clock.
46
     */
47
    private static function mockTime(\DateTimeImmutable|string $mock = 'now', bool $saveClock = true): Clock
48
    {
49
        if ($saveClock) {
2✔
50
            self::saveClock();
2✔
51
        }
52

53
        InternalClock::set(match (true) {
2✔
54
            $mock instanceof \DateTimeImmutable => new FrozenClock($mock),
2✔
55
            default => new FrozenClock(new \DateTimeImmutable($mock)),
2✔
56
        });
2✔
57

58
        return InternalClock::getCurrent();
2✔
59
    }
60
}
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