PHPackages                             mawebdk/clock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. mawebdk/clock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mawebdk/clock
=============

Representation of a clock with easy mocking of current date and time for testing.

1.0.1(1y ago)081BSD-2-ClausePHPPHP ^8.3.6

Since Feb 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mawebdk/clock)[ Packagist](https://packagist.org/packages/mawebdk/clock)[ RSS](/packages/mawebdk-clock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (1)

clock
=====

[](#clock)

This package contains a representation of a clock with easy mocking of current date and time for testing.

Usage
-----

[](#usage)

Obtain the current UTC date and time as a DateTimeImmutable object.

```
$currentUtcDateTime = Clock::getSingleton()->now();

```

Mocking of current UTC date and time
------------------------------------

[](#mocking-of-current-utc-date-and-time)

Use ReflectionClass to set the Clock singleton to a mocked class implementing ClockInterface.

```
/**
 * @throws Exception
 */
public function testMocking()
{
    $mockedDateTimeImmutable = DateTimeImmutable::createFromFormat(
        format: 'Y-m-d H:i:s.u',
        datetime: '1999-12-31 23:59:59.999999',
        timezone: new DateTimeZone(timezone: 'UTC')
    );

    $mockedClock = $this->createMock(type: ClockInterface::class);
    $mockedClock
        ->method(constraint: 'now')
        ->willReturn($mockedDateTimeImmutable);

    $reflectionClass = new ReflectionClass(objectOrClass: Clock::class);
    $reflectionClass->setStaticPropertyValue(name: 'singleton', value: $mockedClock);

    $this->assertSame(
        expected: $mockedDateTimeImmutable->format(format: 'Y-m-d H:i:s.u'),
        actual: Clock::getSingleton()->now()->format(format: 'Y-m-d H:i:s.u')
    );
}

```

Remember to reset singleton to ensure usage of correct date and time in subsequent tests.

```
protected function tearDown(): void
{
    // Reset singleton to ensure usage of correct date and time in subsequent tests.
    $reflectionClass = new ReflectionClass(objectOrClass: Clock::class);
    $reflectionClass->setStaticPropertyValue(name: 'singleton', value: null);
}

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance45

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Total

2

Last Release

428d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff52225bf61e0534f8e176e62a068779155c4121dccee2223b9814828e6a5867?d=identicon)[mawebdk](/maintainers/mawebdk)

---

Top Contributors

[![mawebdk](https://avatars.githubusercontent.com/u/176606063?v=4)](https://github.com/mawebdk "mawebdk (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mawebdk-clock/health.svg)

```
[![Health](https://phpackages.com/badges/mawebdk-clock/health.svg)](https://phpackages.com/packages/mawebdk-clock)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpstan/phpstan-symfony

Symfony Framework extensions and rules for PHPStan

78768.9M1.5k](/packages/phpstan-phpstan-symfony)[phpstan/phpstan-doctrine

Doctrine extensions for PHPStan

66766.6M1.1k](/packages/phpstan-phpstan-doctrine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
