Overview

Namespaces

  • phpmock
    • environment
    • functions
    • spy

Classes

  • MockEnvironment
  • SleepEnvironmentBuilder
  • Overview
  • Namespace
  • Class

Class SleepEnvironmentBuilder

Builds a sleep(), usleep(), date(), time() and microtime() mock environment.

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();
Namespace: phpmock\environment
License: WTFPL
Author: Markus Malkusch markus@malkusch.de
Link: Donations
Located at environment/SleepEnvironmentBuilder.php
Methods summary
public phpmock\environment\SleepEnvironmentBuilder
# addNamespace( string $namespace )

Add a namespace for the mock environment.

Add a namespace for the mock environment.

Parameters

$namespace
A namespace for the mock environment.

Returns

phpmock\environment\SleepEnvironmentBuilder
public phpmock\environment\SleepEnvironmentBuilder
# setTimestamp( mixed $timestamp )

Sets the mocked timestamp.

Sets the mocked timestamp.

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.

Parameters

$timestamp
The timestamp.

Returns

phpmock\environment\SleepEnvironmentBuilder
public phpmock\environment\MockEnvironment
# build( )

Builds a sleep(), usleep(), date(), time() and microtime() mock environment.

Builds a sleep(), usleep(), date(), time() and microtime() mock environment.

Returns

phpmock\environment\MockEnvironment
API documentation generated by ApiGen