mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Merged r113933,113936-113937 from branches/2.4
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114001 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
73c6f1fa08
commit
9ac991636e
@ -1,19 +1,26 @@
|
||||
<?php
|
||||
|
||||
class DbDatetimeTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'sapphire/tests/model/DbDatetimeTest.yml';
|
||||
|
||||
private static $offset = 0; // number of seconds of php and db time are out of sync
|
||||
private static $offset_thresholds = array( // throw an error if the offset exceeds 30 minutes
|
||||
E_USER_ERROR => 1800,
|
||||
E_USER_NOTICE => 5,
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if dates match more or less. This takes into the account the db query
|
||||
* can overflow to the next second giving offset readings.
|
||||
*/
|
||||
private function matchesRoughly($date1, $date2, $comment = '') {
|
||||
$allowedDifference = 15; // seconds
|
||||
$allowedDifference = 5 + abs(self::$offset); // seconds
|
||||
|
||||
$time1 = is_numeric($date1) ? $date1 : strtotime($date1);
|
||||
$time2 = is_numeric($date2) ? $date2 : strtotime($date2);
|
||||
|
||||
$this->assertTrue(abs($time1-$time2)<$allowedDifference, $comment . " ($date1, $date2)");
|
||||
$this->assertTrue(abs($time1-$time2)<$allowedDifference, $comment . " (times differ by " . abs($time1-$time2) . " seconds)");
|
||||
}
|
||||
|
||||
private function getDbNow() {
|
||||
@ -21,6 +28,22 @@ class DbDatetimeTest extends FunctionalTest {
|
||||
return DB::query($query)->value();
|
||||
}
|
||||
|
||||
function setUpOnce() {
|
||||
parent::setUpOnce();
|
||||
|
||||
self::$offset = time() - strtotime(DB::query('SELECT ' . DB::getConn()->now())->value());
|
||||
foreach(self::$offset_thresholds as $code => $offset) {
|
||||
if(abs(self::$offset) > $offset) {
|
||||
if($code == E_USER_NOTICE) {
|
||||
Debug::show('The time of the database is out of sync with the webserver by ' . abs(self::$offset) . ' seconds.');
|
||||
} else {
|
||||
trigger_error('The time of the database is out of sync with the webserver by ' . abs(self::$offset) . ' seconds.', $code);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->adapter = DB::getConn();
|
||||
|
Loading…
Reference in New Issue
Block a user