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 (markus@malkusch.de)
コード例 #1
0
 protected function setUp()
 {
     $builder = new SleepEnvironmentBuilder();
     $builder->addNamespace(__NAMESPACE__)->addNamespace("bandwidthThrottle\\tokenBucket\\converter")->setTimestamp(1417011228);
     $this->sleepEnvironent = $builder->build();
     $this->sleepEnvironent->enable();
 }
コード例 #2
0
ファイル: LoopTest.php プロジェクト: hyperunknown/lock
 protected function setUp()
 {
     parent::setUp();
     $builder = new SleepEnvironmentBuilder();
     $builder->addNamespace(__NAMESPACE__);
     $sleep = $builder->build();
     $sleep->enable();
     $this->registerForTearDown($sleep);
 }
コード例 #3
0
ファイル: ExampleTest.php プロジェクト: php-mock/php-mock
 /**
  * Tests the example from the documentation.
  *
  * @test
  */
 public function testExample3()
 {
     $builder = new SleepEnvironmentBuilder();
     $builder->addNamespace(__NAMESPACE__)->setTimestamp(12345);
     $environment = $builder->build();
     $environment->enable();
     sleep(10);
     assert(12345 + 10 == time());
     $this->assertEquals(12345 + 10, time());
 }