Skip to content

Commit

Permalink
test: test getting datetime from timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 11, 2023
1 parent f4c10de commit 0a6f9e0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/phpunit/Result/ResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class ResultSetTest extends TestCase {
const FAKE_DATA = [
["id" => 1, "name" => "Alice"],
["id" => 2, "name" => "Bob"],
["id" => 3, "name" => "Charlie"],
["id" => 1, "name" => "Alice", "timestamp" => 576264240, "date" => "1988-04-05 17:24"],
["id" => 2, "name" => "Bob", "timestamp" => 554900700, "date" => "1987-08-02 11:05"],
["id" => 3, "name" => "Charlie", "timestamp" => 1433548800, "date" => "2015-06-06"],
];
private $fake_data_index = 0;

Expand Down Expand Up @@ -130,6 +130,13 @@ public function testAsArray() {
}
}

public function testAsDateTime() {
$resultSet = new ResultSet($this->getStatementMock());
$row = $resultSet->fetch();
self::assertEquals("1988-04-05 17:24", $row->getDateTime("date")->format("Y-m-d H:i"));
self::assertEquals("1988-04-05 17:24", $row->getDateTime("timestamp")->format("Y-m-d H:i"));
}

private function getStatementMock():PDOStatement {
$statement = $this->createMock(PDOStatement::class);
$statement->method("fetch")
Expand Down

0 comments on commit 0a6f9e0

Please sign in to comment.