From 7dfec39d8ec106014db9f50c8eaf75a493b89e83 Mon Sep 17 00:00:00 2001 From: arondeparon Date: Wed, 15 Dec 2021 17:24:24 +0100 Subject: [PATCH] Implement CarbonDateSanitizer --- src/Sanitizers/CarbonDateSanitizer.php | 18 +++++++++ tests/Sanitizers/CarbonDateSanitizerTest.php | 40 ++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/Sanitizers/CarbonDateSanitizer.php create mode 100644 tests/Sanitizers/CarbonDateSanitizerTest.php diff --git a/src/Sanitizers/CarbonDateSanitizer.php b/src/Sanitizers/CarbonDateSanitizer.php new file mode 100644 index 0000000..b30f320 --- /dev/null +++ b/src/Sanitizers/CarbonDateSanitizer.php @@ -0,0 +1,18 @@ +assertInstanceOf(Carbon::class, $sanitizer->sanitize($dateFormat)); + } + } + + public function test_it_will_return_null_if_the_date_is_invalid() + { + $invalidDateFormats = [ + 'derp', + 'May 33', + '2021-13-30' + ]; + + $sanitizer = new CarbonDateSanitizer(); + + foreach ($invalidDateFormats as $dateFormat) { + $this->assertNull($sanitizer->sanitize($dateFormat), "It will not parse {$dateFormat}"); + } + } +} \ No newline at end of file