-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from LelineaITManufaktur/nullable-datetime-wil…
…dcard Add wildcard type for date time or null
- Loading branch information
Showing
6 changed files
with
85 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KigaRoo\SnapshotTesting\Wildcard; | ||
|
||
use DateTime; | ||
use Throwable; | ||
|
||
abstract class BaseDateTimeWildcard implements Wildcard | ||
{ | ||
/** @var string */ | ||
private $path; | ||
|
||
/** @var string */ | ||
private $format; | ||
|
||
public function __construct(string $path, string $format = DateTime::ATOM) | ||
{ | ||
$this->path = $path; | ||
$this->format = $format; | ||
} | ||
|
||
public function atPath() : string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* @param mixed $mixed | ||
*/ | ||
public function match($mixed) : bool | ||
{ | ||
try { | ||
$dateTime = DateTime::createFromFormat($this->format, $mixed); | ||
|
||
return $dateTime !== false; | ||
} catch (Throwable $exception) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KigaRoo\SnapshotTesting\Wildcard; | ||
|
||
final class DateTimeOrNullWildcard extends BaseDateTimeWildcard | ||
{ | ||
/** | ||
* @param mixed $mixed | ||
*/ | ||
public function match($mixed) : bool | ||
{ | ||
if ($mixed === null) { | ||
return true; | ||
} | ||
|
||
return parent::match($mixed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,10 @@ | |
"02.02.2012 12:12", | ||
"01.01.2011 11:11" | ||
] | ||
], | ||
"dateTimeOrNull": [ | ||
"2019-07-10T12:50:20+00:00", | ||
null | ||
] | ||
} | ||
} |