PHP Class phpmock\environment\SleepEnvironmentBuilder

In this environment sleep() and usleep() don't sleep for real. Instead they return immediatly and increase the amount of time in the mocks for date(), time() and microtime(). Example: namespace foo; use phpmock\environment\SleepEnvironmentBuilder; $builder = new SleepEnvironmentBuilder(); $builder->addNamespace(__NAMESPACE__) ->setTimestamp(1417011228); $environment = $builder->build(); $environment->enable(); This won't delay the test for 10 seconds, but increase time(). sleep(10); assert(1417011228 + 10 == time()); Now revert the effect so that sleep() and time() are not mocked anymore. $environment->disable();
Author: Markus Malkusch ([email protected])
Afficher le fichier Open project: php-mock/php-mock Class Usage Examples

Méthodes publiques

Méthode Description
addNamespace ( string $namespace ) : SleepEnvironmentBuilder Add a namespace for the mock environment.
build ( ) : MockEnvironment Builds a sleep(), usleep(), date(), time() and microtime() mock environment.
setTimestamp ( mixed $timestamp ) : SleepEnvironmentBuilder Sets the mocked timestamp.

Method Details

addNamespace() public méthode

Add a namespace for the mock environment.
public addNamespace ( string $namespace ) : SleepEnvironmentBuilder
$namespace string A namespace for the mock environment.
Résultat SleepEnvironmentBuilder

build() public méthode

Builds a sleep(), usleep(), date(), time() and microtime() mock environment.
public build ( ) : MockEnvironment
Résultat MockEnvironment

setTimestamp() public méthode

If not set the mock will use the current time at creation time. The timestamp can be an int, a float with microseconds or a string in the microtime() format.
public setTimestamp ( mixed $timestamp ) : SleepEnvironmentBuilder
$timestamp mixed The timestamp.
Résultat SleepEnvironmentBuilder