Search by

adachsoft / lease-lock-contract-tests

Arkadiusz Adach

Reusable PHPUnit contract tests and a frozen clock for lease lock implementations.

Package info

gitlab.com/a.adach/lease-lock-contract-tests

Issues

pkg:composer/adachsoft/lease-lock-contract-tests

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-20 10:37 UTC

This package is auto-updated.

Last update: 2026-11-20 09:38:07 UTC


README

adachsoft/lease-lock-contract-tests provides a reusable PHPUnit behavioral contract and a deterministic PSR-20 FrozenClock for implementations of AdachSoft\LeaseLockContracts\LeaseLockInterface.

Features

  • A reusable contract suite for lease acquisition, ownership, expiry, renewal, release, independent keys, and argument validation.
  • A UTC-normalized frozen clock for deterministic time-dependent tests.
  • Coverage of keys containing separators such as : and /.

Requirements

  • PHP ^8.3
  • PHPUnit ^12.5
  • adachsoft/lease-lock-contracts ^0.1.0
  • psr/clock ^1.0

Installation

Install the package as a development dependency in the project containing your lock implementation:

composer require --dev adachsoft/lease-lock-contract-tests

Usage

Extend AbstractLeaseLockContractTest and implement createLock() for your adapter. The factory must return a new lock instance on every call. Instances created in the same test must share backing storage, while storage must be isolated between test methods.

use AdachSoft\LeaseLockContracts\LeaseLockInterface;
use AdachSoft\LeaseLockContractTests\Contract\AbstractLeaseLockContractTest;
use Psr\Clock\ClockInterface;

final class FileLeaseLockContractTest extends AbstractLeaseLockContractTest
{
    protected function createLock(ClockInterface $clock): LeaseLockInterface
    {
        return new FileLeaseLock($this->testDirectory, $clock);
    }
}

For file-backed locks, create a unique temporary directory per test and clean it up afterward. For in-memory locks, share a storage object owned by the test instance. See the contract example for the setup requirements.

Frozen clock

AdachSoft\LeaseLockContractTests\Support\FrozenClock implements PSR-20 ClockInterface and normalizes time to UTC. Use advance(int $seconds) to move forward by a non-negative number of seconds or set(DateTimeImmutable $now) to set a specific instant. Pass the same clock instance to every lock instance created during one contract test.