Skip to content

driade/sleepery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP wrapper for the sleep() and usleep() functions for easy testing

Packagist Tests Downloads

This package allows you to easily test the sleep() and usleep() functions without having to "wait".

Installation

You can install the package via composer:

composer require driade/sleepery

Usage

Instead of using sleep() in your code you should use

Driade\Sleepery::dream(1);

and, instead of using usleep() in your code you should use

Driade\Sleepery::nap(1000);

When it comes to test your code, you can use the "fake" function to make the calls to dream() and nap() recorded, so you can later test them.

In your tests

use Driade\Sleepery;

Sleepery::fake();

(new PerformAction)->handle(); // execute your code

Sleepery::wakeup();

//

Sleepery::assertDreamt(1);
Sleepery::assertNapped(1000);

You may also use the following functions

Sleepery::assertNeverDreamt(); // no call to sleep() was made
Sleepery::assertNeverNapped(); // no call to usleep() was made
Sleepery::getDreams(); // returns all the dream() calls while dreaming
Sleepery::getNaps(); // returns all the nap() calls while dreaming
Sleepery::wakeup(); // stop dreaming

Testing

composer test

Contributing

Please feel free to open an issue or pull request if you think something can be improved

Credits

License

The MIT License (MIT). Please see License File for more information.

About

PHP sleep and usleep wrappers to make them easier to test

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages