From f0046eca19992c1daecbc080c1e1529a0b8983ff Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Sun, 2 Jun 2024 15:32:23 +0330 Subject: [PATCH] add `jalali_date_is_not_correct_with_different_default_character` test --- src/Rules/ValidJalaliDate.php | 4 ++++ tests/Rules/ValidJalaliDateTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Rules/ValidJalaliDate.php b/src/Rules/ValidJalaliDate.php index 869dd00..550cde7 100644 --- a/src/Rules/ValidJalaliDate.php +++ b/src/Rules/ValidJalaliDate.php @@ -25,6 +25,10 @@ public function passes($attribute, $value) $date = explode($this->character, $value); + if (count($date) <= 1) { + return false; + } + return $this->checkValidDate(...$date); } diff --git a/tests/Rules/ValidJalaliDateTest.php b/tests/Rules/ValidJalaliDateTest.php index 96550af..7ca2329 100644 --- a/tests/Rules/ValidJalaliDateTest.php +++ b/tests/Rules/ValidJalaliDateTest.php @@ -79,4 +79,19 @@ public function jalali_date_is_correct_with_different_default_character() $this->assertTrue($passes); } + /** + * Test jalali date is not correct with different default character. + * + * @test + * + * @return void + */ + public function jalali_date_is_not_correct_with_different_default_character() + { + $rules = ['jalali_date' => [new ValidJalaliDate('-')]]; + $data = ['jalali_date' => '2016/15/25']; + $passes = $this->app['validator']->make($data, $rules)->passes(); + + $this->assertFalse($passes); + } }