From 84a873f345fa25b0782ef3d2f65e15a1f5498360 Mon Sep 17 00:00:00 2001 From: nasser Date: Wed, 16 Feb 2022 18:48:48 +0330 Subject: [PATCH] fix test last month --- src/Traits/Comparison.php | 6 +++--- src/Traits/Creator.php | 10 ++++------ src/Traits/Date.php | 26 +++++++++----------------- tests/ComparisionTest.php | 4 +--- tests/CreatorTest.php | 1 + tests/ModificationTest.php | 2 +- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/Traits/Comparison.php b/src/Traits/Comparison.php index 6801793..f0a5081 100644 --- a/src/Traits/Comparison.php +++ b/src/Traits/Comparison.php @@ -395,7 +395,7 @@ trait Comparison */ public function isNextMonth() { - return $this->month === static::now($this->getTimezone())->addMonth()->month; + return $this->format('Y-m') === static::now($this->getTimezone())->addMonth()->format('Y-m'); } /** @@ -405,7 +405,7 @@ trait Comparison */ public function isLastMonth() { - return $this->month === static::now($this->getTimezone())->subMonth()->month; + return $this->format('Y-m') === static::now($this->getTimezone())->subMonth()->format('Y-m'); } /** @@ -458,7 +458,7 @@ trait Comparison */ public function isSameAs($format, Verta $v = null) { - $v = $v ?: static::now($this->timezone); + $v = $v ?: static::now($this->getTimezone()); return $this->format($format) === $v->format($format); } diff --git a/src/Traits/Creator.php b/src/Traits/Creator.php index 2bd153d..2543a6a 100644 --- a/src/Traits/Creator.php +++ b/src/Traits/Creator.php @@ -12,16 +12,14 @@ trait Creator /** * create object of Jalali * - * @param null $datetime - * @param bool $timezone [optional] + * @param DateTime|string|int|null $datetime [optional] + * @param DateTimeZone|string|null $timezone [optional] * @internal param timestamp $timestamp [optional] */ public function __construct($datetime = null, $timezone = null) { $dt = $datetime; - if (static::$testNow) { - $dt = static::$testNow; - } elseif (empty($datetime)) { + if (empty($datetime)) { $dt = 'now'; } elseif (is_string($datetime)) { $dt = self::faToEnNumbers(self::arToEnNumbers($datetime)); @@ -254,7 +252,7 @@ trait Creator /** * @param null $timezone - * @return DateTimeZone|null + * @return DateTimeZone|string|null */ protected static function createTimeZone($timezone = null) { diff --git a/src/Traits/Date.php b/src/Traits/Date.php index 97706b8..833aabe 100644 --- a/src/Traits/Date.php +++ b/src/Traits/Date.php @@ -6,23 +6,15 @@ use Hekmatinasser\Verta\VertaInterface; trait Date { - use Accessor; - use Comparison; - use Creator; - use Formatting; - use Modification; - use Transformation; - use Translator; - use Boundaries; - use Difference; - - /** - * Format to use for __toString. - * - * @var string - */ - public static $testNow = null; - + use Accessor, + Comparison, + Creator, + Formatting, + Modification, + Transformation, + Translator, + Boundaries, + Difference; /** * Format to use for __toString. * diff --git a/tests/ComparisionTest.php b/tests/ComparisionTest.php index b0cab96..735b30b 100644 --- a/tests/ComparisionTest.php +++ b/tests/ComparisionTest.php @@ -249,7 +249,7 @@ class ComparisionTest extends TestCase $datetime = Verta::parse('1397-10-10 21:30:50'); $target = Verta::parse('1398-10-10 21:30:01'); - Verta::$testNow = $datetime->formatGregorian('Y-m-d H:i:s'); +// Verta::setTestNow('1397-10-10 21:30:50'); $this->assertTrue($datetime->isWeekday()); $this->assertFalse($datetime->isWeekend()); @@ -264,7 +264,6 @@ class ComparisionTest extends TestCase $this->assertFalse($datetime->isLastYear()); $this->assertFalse($datetime->isFuture()); $this->assertTrue($datetime->isPast()); - $this->assertTrue($datetime->isSameAs('m-d', $target)); $this->assertFalse($datetime->isSameAs('Y-m-d')); $this->assertFalse($datetime->isCurrentYear()); @@ -279,6 +278,5 @@ class ComparisionTest extends TestCase $this->assertFalse($datetime->isThursday()); $this->assertFalse($datetime->isFriday()); - Verta::$testNow = null; } } diff --git a/tests/CreatorTest.php b/tests/CreatorTest.php index e91666f..f1b3c91 100644 --- a/tests/CreatorTest.php +++ b/tests/CreatorTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase; class CreatorTest extends TestCase { + public function testNow() { $expected = (new DateTime())->getTimestamp(); diff --git a/tests/ModificationTest.php b/tests/ModificationTest.php index 28c4032..684873e 100644 --- a/tests/ModificationTest.php +++ b/tests/ModificationTest.php @@ -216,7 +216,7 @@ class ModificationTest extends TestCase public function testEndYear() { - $datetime = Verta::parse('1398-10-10 21:30:20'); + $datetime = Verta::parse('1398-10-15 21:30:20'); $result = $datetime->endYear()->format('Y-m-d H:i:s');