From baf2218980e7ee9c3ecf0de66b9806b52ddc9d1d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 21 Oct 2019 15:38:15 +0200 Subject: [PATCH] Bug fixes --- DataStorage/Database/DataMapperAbstract.php | 5 ++++- DataStorage/Database/Query/Grammar/Grammar.php | 2 +- Stdlib/Base/Heap.php | 2 +- Stdlib/Base/SmartDateTime.php | 14 ++++++++++++++ tests/Stdlib/Base/SmartDateTimeTest.php | 2 ++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index ba8895025..e6b61e843 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -495,7 +495,10 @@ class DataMapperAbstract implements DataMapperInterface var_dump($query->toSql()); } - return self::$db->con->lastInsertId(); + $objId = self::$db->con->lastInsertId(); + \settype($objId, static::$columns[static::$primaryField]['type']); + + return $objId; } /** diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index d4eb3af53..492399813 100644 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -418,7 +418,7 @@ class Grammar extends GrammarAbstract $expression .= '(' . \rtrim($join['table']->toSql(), ';') . ')' . (\is_string($key) ? ' as ' . $query->getPrefix() . $key : ''); } - $expression .= $this->compileOn($query, $query->ons[$key]); + $expression .= $this->compileOn($query, $query->ons[$key]) . ' '; } $expression = \rtrim($expression, ', '); diff --git a/Stdlib/Base/Heap.php b/Stdlib/Base/Heap.php index 76bff0879..04ca9ac00 100644 --- a/Stdlib/Base/Heap.php +++ b/Stdlib/Base/Heap.php @@ -27,7 +27,7 @@ class Heap /** * Comparison function * - * @var \Closure + * @var \Closure * @since 1.0.0 */ private \Closure $compare; diff --git a/Stdlib/Base/SmartDateTime.php b/Stdlib/Base/SmartDateTime.php index 313d0d78f..ca39b8bdf 100644 --- a/Stdlib/Base/SmartDateTime.php +++ b/Stdlib/Base/SmartDateTime.php @@ -142,6 +142,20 @@ class SmartDateTime extends \DateTime return new self($this->format('Y') . '-' . $this->format('m') . '-01'); } + /** + * Get start of the week + * + * @return SmartDateTime + * + * @since 1.0.0 + */ + public function getStartOfWeek() : self + { + $w = \strtotime('-' . \date('w', $this->getTimestamp()) .' days', $this->getTimestamp()); + + return new self(\date('Y-m-d', $w)); + } + /** * Get days of current month * diff --git a/tests/Stdlib/Base/SmartDateTimeTest.php b/tests/Stdlib/Base/SmartDateTimeTest.php index ee4256c06..cd07a21c1 100644 --- a/tests/Stdlib/Base/SmartDateTimeTest.php +++ b/tests/Stdlib/Base/SmartDateTimeTest.php @@ -59,6 +59,8 @@ class SmartDateTimeTest extends \PHPUnit\Framework\TestCase self::assertTrue(SmartDateTime::leapYear(2104)); self::assertEquals(\date('w', $expected->getTimestamp()), SmartDateTime::getDayOfWeek((int) $expected->format('Y'), (int) $expected->format('m'), (int) $expected->format('d'))); + + // todo: i think this assertion is wrong! or the function getFirstDay... doesn't do what is supposed to do self::assertEquals(\date('w', $expected->getTimestamp()), $obj->getFirstDayOfWeek()); self::assertCount(42, $obj->getMonthCalendar());