Skip to content

Commit

Permalink
Adding tests for the expected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Rican7 committed May 19, 2016
1 parent d4b980f commit da5d27a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,33 @@ public function test_empty_and_null_datetime_strings_should_return_null()
$this->assert_equals(null,$column->cast(null,$this->conn));
$this->assert_equals(null,$column->cast('',$this->conn));
}

public function test_native_date_time_attribute_copies_exact_tz()
{
$dt = new \DateTime(null, new \DateTimeZone('America/New_York'));

$column = new Column();
$column->type = Column::DATETIME;

$dt2 = $column->cast($dt, $this->conn);

$this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp());
$this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone());
$this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName());
}

public function test_ar_date_time_attribute_copies_exact_tz()
{
$dt = new DateTime(null, new \DateTimeZone('America/New_York'));

$column = new Column();
$column->type = Column::DATETIME;

$dt2 = $column->cast($dt, $this->conn);

$this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp());
$this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone());
$this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName());
}
}
?>
28 changes: 28 additions & 0 deletions test/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,33 @@ public function test_create_from_format_with_tz()
$d = DateTime::createFromFormat('Y-m-d H:i:s', '2000-02-01 03:04:05', new \DateTimeZone('Etc/GMT-10'));
$this->assert_equals(new DateTime('2000-01-31 17:04:05'), $d);
}

public function test_native_date_time_attribute_copies_exact_tz()
{
$dt = new \DateTime(null, new \DateTimeZone('America/New_York'));
$model = new Author();

// Test that the data transforms without modification
$model->assign_attribute('updated_at', $dt);
$dt2 = $model->read_attribute('updated_at');

$this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp());
$this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone());
$this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName());
}

public function test_ar_date_time_attribute_copies_exact_tz()
{
$dt = new DateTime(null, new \DateTimeZone('America/New_York'));
$model = new Author();

// Test that the data transforms without modification
$model->assign_attribute('updated_at', $dt);
$dt2 = $model->read_attribute('updated_at');

$this->assert_equals($dt->getTimestamp(), $dt2->getTimestamp());
$this->assert_equals($dt->getTimeZone(), $dt2->getTimeZone());
$this->assert_equals($dt->getTimeZone()->getName(), $dt2->getTimeZone()->getName());
}
}
?>

3 comments on commit da5d27a

@visavi
Copy link

@visavi visavi commented on da5d27a May 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only sqlite

phpunit

@visavi
Copy link

@visavi visavi commented on da5d27a May 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you run the tests included a strict standart mysql, almost all the errors related to the incorrect time format

Invalid datetime format: 1292 Incorrect datetime value: '2016-05-21 11:54:43 UTC'
phpunitfill

Ubuntu 16.04, php 7.0, mysql 5.7

@Rican7
Copy link
Collaborator Author

@Rican7 Rican7 commented on da5d27a May 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@visavi: not sure why you're commenting on this commit. The MySQL error you're getting is due to this: #412

These tests are only testing how the data is transformed internally, not how it's stored.

Please sign in to comment.