Ejemplo n.º 1
0
 protected function setUp()
 {
     parent::setUp();
     Clock::freeze('2014-01-01 11:11:11');
     StreamStub::register('test');
     $this->logger = new StdOutputLogger('TEST', 'default', 'test');
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function shouldModifyCurrentDate()
 {
     //when
     $date = Date::modifyNow('2 days');
     //then
     $this->assertGreaterThan(Clock::nowAsString(), $date);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 /**
  * @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;
 }
Ejemplo n.º 6
0
 /**
  * @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());
 }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
 public function __construct($attributes = [])
 {
     parent::__construct(['attributes' => $attributes, 'fields' => ['id', 'name', 'params', 'created_at' => Clock::nowAsString()]]);
 }
Ejemplo n.º 9
0
 private function _nowAsTimestamp()
 {
     return Clock::now()->getTimestamp();
 }
Ejemplo n.º 10
0
 public function isBeforeOrEqualTo(Clock $other)
 {
     return $this->getTimestamp() <= $other->getTimestamp();
 }
Ejemplo n.º 11
0
 /**
  * @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);
 }
Ejemplo n.º 12
0
 /**
  * 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);
 }
Ejemplo n.º 13
0
<?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();
Ejemplo n.º 14
0
 /**
  * @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);
 }
Ejemplo n.º 15
0
 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']]]);
 }
Ejemplo n.º 16
0
 protected function tearDown()
 {
     parent::tearDown();
     Clock::freeze();
 }