protected function setUp() { parent::setUp(); Clock::freeze('2014-01-01 11:11:11'); StreamStub::register('test'); $this->logger = new StdOutputLogger('TEST', 'default', 'test'); }
/** * @test */ public function shouldModifyCurrentDate() { //when $date = Date::modifyNow('2 days'); //then $this->assertGreaterThan(Clock::nowAsString(), $date); }
private function _log($stdOut, $level, $levelName, $message, $params) { $this->log(function ($message) use($stdOut) { $date = Clock::nowAsString(); $fileHandle = fopen($stdOut, 'a'); fwrite($fileHandle, "{$date}: {$message}\n"); fclose($fileHandle); }, $level, $levelName, $message, $params); }
/** * @test * @dataProvider dates * @param string $currentDate * @param string $date * @param string $expectedText */ public function shouldCreateTranslatableTimeAgo($currentDate, $date, $expectedText) { //given Clock::freeze($currentDate); //when $translatableTimeAgo = TranslatableTimeAgo::create($date)->asString(); //then $this->assertEquals($expectedText, $translatableTimeAgo, 'Error in [' . $date . '] with expected [' . $expectedText . ']'); }
/** * @inheritdoc */ public function get() { $function = $this->function; $now = Clock::now()->getTimestamp(); if ($this->cachedResult === null || $now - $this->lastCallTime > $this->expireTime) { $this->cachedResult = $function(); $this->lastCallTime = $now; } return $this->cachedResult; }
/** * @test * @dataProvider dates * @param string $currentDate * @param string $date * @param string $expectedKey * @param array $expectedParams */ public function shouldCreateTimeAgo($currentDate, $date, $expectedKey, $expectedParams) { //given Clock::freeze($currentDate); //when $timeAgo = TimeAgo::create($date); //then $this->assertEquals($expectedKey, $timeAgo->getKey()); $this->assertEquals($expectedParams, $timeAgo->getParams()); }
public function poll() { Stats::reset(); session_write_close(); $stop = Clock::now()->plusSeconds(self::TIMEOUT); while (true) { if (!$stop->isAfter(Clock::now()) || connection_aborted()) { $this->layout->renderAjax("[]"); return; } session_start(); $events = Event::loadNew(); session_write_close(); if ($events) { $this->layout->renderAjax(Json::encode(Arrays::map($events, function (Event $event) { return $event->toJsonArray(); }))); return; } Stats::reset(); usleep(100 * 1000); } }
public function __construct($attributes = []) { parent::__construct(['attributes' => $attributes, 'fields' => ['id', 'name', 'params', 'created_at' => Clock::nowAsString()]]); }
private function _nowAsTimestamp() { return Clock::now()->getTimestamp(); }
public function isBeforeOrEqualTo(Clock $other) { return $this->getTimestamp() <= $other->getTimestamp(); }
/** * @test */ public function shouldCreateClockForGivenTimestamp() { //given $clock = Clock::fromTimestamp(1427207001)->setTimezone('UTC'); //when $result = $clock->format(); //then $this->assertEquals('2015-03-24 14:23:21', $result); }
/** * Modifies the current time and returns a formatted date. * * @link http://php.net/manual/en/datetime.formats.php * * @param string $interval * @param string $format * @return string */ public static function modifyNow($interval, $format = self::DEFAULT_TIME_FORMAT) { return Clock::now()->toDateTime()->modify($interval)->format($format); }
<?php use Ouzo\Utilities\Clock; use Ouzo\Utilities\Files; use Ouzo\Utilities\Path; error_reporting(E_ALL); putenv('environment=test'); define('ROOT_PATH', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR); require 'vendor/autoload.php'; Files::loadIfExists(Path::join(ROOT_PATH, 'config', 'error_codes.php')); Files::loadIfExists(Path::join(ROOT_PATH, 'config', 'routes.php')); Clock::freeze();
/** * @test */ public function shouldCopyFileContent() { //given StreamStub::register('logfile'); StreamStub::$body = 'content'; $tmpFileName = Path::joinWithTemp('test' . Clock::nowAsString('Y_m_d_H_i_s') . '.txt'); //when Files::copyContent('logfile://input', $tmpFileName); //then $content = file_get_contents($tmpFileName); StreamStub::unregister(); Files::delete($tmpFileName); $this->assertEquals('content', $content); }
public function __construct($attributes = []) { parent::__construct(['attributes' => $attributes, 'fields' => ['id', 'current_game_user_id', 'round' => 1, 'finished' => false, 'winner_game_user_id', 'type', 'started_at' => Clock::nowAsString()], 'belongsTo' => ['current_game_user' => ['class' => 'GameUser', 'foreignKey' => 'current_game_user_id', 'referencedColumn' => 'id'], 'winner_game_user' => ['class' => 'GameUser', 'foreignKey' => 'winner_game_user_id', 'referencedColumn' => 'id']], 'hasMany' => ['game_users' => ['class' => 'GameUser', 'foreignKey' => 'game_id', 'referencedColumn' => 'id']]]); }
protected function tearDown() { parent::tearDown(); Clock::freeze(); }