Download the PHP package slope-it/clock-mock without Composer

On this page you can find all versions of the php package slope-it/clock-mock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package clock-mock

ClockMock

Slope s.r.l.

Latest Stable Version Total Downloads License

ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related functions. It requires the uopz extension (version >= 6.1.1).

This library is meant for development and testing only. It does not aim to propose a clock service to be used in production code, as we believe that you shouldn't need to do that when your only purpose is to mock the current time in testing code.

Why we built it

Here is an article that explains in depth how and why this library was built: link to the article.

TL;DR

Installation

You can install the library using Composer. Run the following command to install the latest version from Packagist:

Note that, as this is not a tool intended for production, it should be required only for development (--dev flag).

Mocked functions/methods

Usage

1. Stateful API

You can call ClockMock::freeze with a \DateTime or \DateTimeImmutable. Any code executed after it will use that specific date and time as the current timestamp. Call ClockMock::reset when done to restore real, current time.

Example:

2. Stateless API

The library also provides a closure-based API that will execute the provided code at a specific point in time. This API does not need manually freezing or re-setting time, so it can be less error prone in some circumstances.

Example:

How to contribute

Under any of these circumstances, please fork this repo and create a pull request. We are more than happy to accept contributions!

Credits


All versions of clock-mock with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
ext-uopz Version >=6.1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package slope-it/clock-mock contains the following files

Loading the files please wait ....