Skip to content

Commit

Permalink
Try to make tests less fragile.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 16, 2012
1 parent 6d3ae3b commit 3077595
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/Cake/Test/Case/Utility/CakeTimeTest.php
Expand Up @@ -779,17 +779,17 @@ public function testUserOffset() {

$expected = time();
$result = $this->Time->fromString(time(), $yourTimezone);
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

$result = $this->Time->fromString(time(), $timezoneServer->getName());
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

$result = $this->Time->fromString(time(), $timezoneServer);
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

Configure::write('Config.timezone', $timezoneServer->getName());
$result = $this->Time->fromString(time());
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);
Configure::delete('Config.timezone');
}

Expand All @@ -807,17 +807,17 @@ public function testFromString() {

$result = $this->Time->fromString('+1 hour');
$expected = strtotime('+1 hour');
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

$timezone = date('Z', time());
$result = $this->Time->fromString('+1 hour', $timezone);
$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

$timezone = date_default_timezone_get();
$result = $this->Time->fromString('+1 hour', $timezone);
$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

date_default_timezone_set('UTC');
$date = new DateTime('now', new DateTimeZone('Europe/London'));
Expand All @@ -840,15 +840,15 @@ public function testFromStringWithDateTime() {
$date->setTimezone(new DateTimeZone('UTC'));
$expected = $date->format('U') + $date->getOffset();

$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

date_default_timezone_set('Australia/Melbourne');

$date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
$result = $this->Time->fromString($date, 'Asia/Kuwait');
$date->setTimezone(new DateTimeZone('Asia/Kuwait'));
$expected = $date->format('U') + $date->getOffset();
$this->assertEquals($expected, $result);
$this->assertWithinMargin($expected, $result, 1);

$this->_restoreSystemTimezone();
}
Expand Down Expand Up @@ -1058,10 +1058,10 @@ public function testListTimezones() {
public function testCorrectTimezoneConversion() {
date_default_timezone_set('UTC');
$date = '2012-01-01 10:00:00';
$converted = CakeTime::format($date, '%Y-%m-%d %H:%M:%S', '', 'Europe/Copenhagen');
$converted = CakeTime::format($date, '%Y-%m-%d %H:%M', '', 'Europe/Copenhagen');
$expected = new DateTime($date);
$expected->setTimezone(new DateTimeZone('Europe/Copenhagen'));
$this->assertEquals($expected->format('Y-m-d H:i:s'), $converted);
$this->assertEquals($expected->format('Y-m-d H:i'), $converted);
}

}

0 comments on commit 3077595

Please sign in to comment.