Skip to content

Commit

Permalink
Merge branch 'master' of github.com:PhpGt/Database into 318-semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 11, 2023
2 parents c243999 + 727750a commit 98a089f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Fetchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ protected function castRow(
$key = key($assocArray);
$value = $assocArray[$key];

if($type === Type::DATETIME && is_numeric($value)) {
$value = "@$value";
}

return match ($type) {
Type::BOOL, "boolean" => (bool)$value,
Type::INT, "integer" => (int)$value,
Expand Down
3 changes: 2 additions & 1 deletion src/Query/SqlQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Gt\Database\Result\ResultSet;
use PHPSQLParser\PHPSQLParser;

/** @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */
class SqlQuery extends Query {
const SPECIAL_BINDINGS = [
"limit",
Expand Down Expand Up @@ -211,7 +212,7 @@ private function injectDynamicOr(string $sql, array &$data):string {
}

$replacementString = "";
foreach($data["__dynamicOr"] as $i => $kvp) {
foreach($data["__dynamicOr"] as $kvp) {
$conditionString = "";
foreach($kvp as $key => $value) {
if(is_string($value)) {
Expand Down
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 98a089f

Please sign in to comment.