All Projects → Lendable → clock

Lendable / clock

Licence: MIT license
Lendable Clock Abstraction

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to clock

dexopener
An Android library that provides the ability to mock your final classes on Android devices.
Stars: ✭ 112 (+646.67%)
Mutual labels:  mock
chip
📦 🐳 🚀 - Smart "dummy" mock for cloud native tests
Stars: ✭ 19 (+26.67%)
Mutual labels:  mock
Mokku
Mock API calls seamlessly
Stars: ✭ 109 (+626.67%)
Mutual labels:  mock
dextool
Suite of C/C++ tooling built on LLVM/Clang
Stars: ✭ 81 (+440%)
Mutual labels:  mock
admin-base-tmpl
⚡️基于vite2构建的vue2+typescript+elementUI 的后台基础套件,预览地址
Stars: ✭ 52 (+246.67%)
Mutual labels:  mock
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (+20%)
Mutual labels:  mock
ts-mock-imports
Intuitive mocking library for Typescript class imports
Stars: ✭ 103 (+586.67%)
Mutual labels:  mock
Paw-FakerDynamicValue
A dynamic value extension for Paw using Faker to generate data
Stars: ✭ 16 (+6.67%)
Mutual labels:  mock
entity-framework-mock
Easy Mock wrapper for mocking EF6 DbContext and DbSet using Moq or NSubstitute
Stars: ✭ 45 (+200%)
Mutual labels:  mock
interface-forge
Graceful mock-data and fixtures generation using TypeScript
Stars: ✭ 58 (+286.67%)
Mutual labels:  mock
clocklet
An opinionated clock-style vanilla-js timepicker.
Stars: ✭ 31 (+106.67%)
Mutual labels:  clock
twigs
Alternate firmware for Mutable Instruments Branches synthesizer module
Stars: ✭ 21 (+40%)
Mutual labels:  clock
TimeContinuum
No description or website provided.
Stars: ✭ 28 (+86.67%)
Mutual labels:  clock
moq.ts
Moq for Typescript
Stars: ✭ 107 (+613.33%)
Mutual labels:  mock
1440-clock
Simple JavaScript clock that visualizes the 1440 minutes one has in a day
Stars: ✭ 49 (+226.67%)
Mutual labels:  clock
Takvim-saat-chrome-extensions
😎 Anlık olarak takvim, saat ve hava durumu bilgilerinizi tarayıcınızın newtab alanında tutarak kullanımı oldukça kolay bir ortam oluşturur. extensions link:
Stars: ✭ 21 (+40%)
Mutual labels:  clock
axios-mock-server
RESTful mock server using axios.
Stars: ✭ 33 (+120%)
Mutual labels:  mock
joke
Typesafe mock utility with minimal boilerplate for jest
Stars: ✭ 16 (+6.67%)
Mutual labels:  mock
shai
数据模拟生成库
Stars: ✭ 55 (+266.67%)
Mutual labels:  mock
htest
htest is a http-test package
Stars: ✭ 24 (+60%)
Mutual labels:  mock

Lendable Clock Abstraction

Latest Stable Version License

Provides an object-oriented interface for retrieving the current time.

PHP of course provides \DateTime, \DateTimeImmutable and \DateTimeInterface. Why do we need a clock then? Why not just instantiate where required?

We can obtain the current time with $now = new \DateTime() after all, why do we need a Clock::now(): \DateTimeImmutable style API to obtain the current time?

Depending on a Clock rather than constructing native PHP time objects ad hoc means you can both reason and control time.

  • Underlying implementation can be swapped out to one more suitable for a test environment.
    • Time can now be stubbed with a fixed value, or even start from a point in time and tick from there.
    • Interactions with the Clock can be observed and asserted on.
    • Time passing can be simulated with changes to the output from the Clock.
    • Tests that make poor assumptions can be avoided, i.e., capturing the current time to the second, then asserting that an expected output matches it. However, time passed during the setup to the assertion, and this time it crossed the second boundary.
  • Clear dependencies on classes that require to obtain the current system time.
  • The PSR-20 proposal for a Clock contains further information and examples of current libraries and their solutions and workarounds to provide mocking support.

This library makes no attempt to mock global state, such as \time() or calls to new \DateTimeImmutable(). You will have conflicts if you cannot assert enough control over your dependencies to ensure all current system time retrieval goes through the Clock.

Installation

You can install the library via Composer.

composer require lendable/clock

Clock types

SystemClock

Delegates to PHP for the current system time, uses a fixed timezone at construction.

Target: runtime

FixedClock

Always provides a specific timestamp that is provided at construction.

Target: unit/functional tests

TickingMockClock

Mocks time starting from a given timestamp and simulates time progressing from that point. I.e a call to TickingMockClock::now() 200ms after it is created will give a time value 200ms after the given timestamp.

Target: unit/functional tests

PersistedFixedClock

Similar to FixedClock, but can persist and load the given timestamp from disk. Use PersistedFixedClock::initializeWith(...) to set up the timestamp and PersistedFixedClock::fromPersisted(...) to load from the persisted value on disk.

Target: functional tests where you reload your context. E.g. Behat vs Symfony Kernel. You would initialize in a BeforeScenario hook and then load the data from within the Kernel.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].