-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added output value tests. Added cast tests. Fixed value casting
- Loading branch information
1 parent
54b82f4
commit 572642d
Showing
4 changed files
with
112 additions
and
9 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,77 @@ | ||
<?php | ||
|
||
use Whitecube\LaravelTimezones\Casts\TimezonedDatetime; | ||
|
||
it('can access UTC database date with application timezone', function() { | ||
setupFacade(); | ||
|
||
$cast = new TimezonedDatetime(); | ||
|
||
$input = '2022-12-15 09:00:00'; | ||
|
||
$output = $cast->get(fakeModel(), 'id', $input, []); | ||
|
||
expect($output->getTimezone()->getName())->toBe('Europe/Brussels'); | ||
expect($output->format('Y-m-d H:i:s'))->toBe('2022-12-15 10:00:00'); | ||
}); | ||
|
||
it('can access UTC database date with application timezone and specific format', function() { | ||
setupFacade(); | ||
|
||
$cast = new TimezonedDatetime('d/m/Y H:i'); | ||
|
||
$input = '15/12/2022 09:00'; | ||
|
||
$output = $cast->get(fakeModel(), 'id', $input, []); | ||
|
||
expect($output->getTimezone()->getName())->toBe('Europe/Brussels'); | ||
expect($output->format('Y-m-d H:i:s'))->toBe('2022-12-15 10:00:00'); | ||
}); | ||
|
||
it('can mutate application timezone datetime string to UTC database date string', function() { | ||
setupFacade(); | ||
|
||
$cast = new TimezonedDatetime(); | ||
|
||
$input = '2022-12-15 10:00:00'; | ||
|
||
$output = $cast->set(fakeModel(), 'id', $input, []); | ||
|
||
expect($output)->toBe('2022-12-15 09:00:00'); | ||
}); | ||
|
||
it('can mutate application timezone date instance to UTC database date string', function() { | ||
setupFacade(); | ||
|
||
$cast = new TimezonedDatetime(); | ||
|
||
$input = new \Carbon\Carbon('2022-12-15 10:00:00', 'Europe/Brussels'); | ||
|
||
$output = $cast->set(fakeModel(), 'id', $input, []); | ||
|
||
expect($output)->toBe('2022-12-15 09:00:00'); | ||
}); | ||
|
||
it('can mutate UTC date instance to UTC database date string', function() { | ||
setupFacade(); | ||
|
||
$cast = new TimezonedDatetime(); | ||
|
||
$input = new \Carbon\Carbon('2022-12-15 09:00:00', 'UTC'); | ||
|
||
$output = $cast->set(fakeModel(), 'id', $input, []); | ||
|
||
expect($output)->toBe('2022-12-15 09:00:00'); | ||
}); | ||
|
||
it('can mutate date instance with exotic timezone to UTC database date string', function() { | ||
setupFacade(); | ||
|
||
$cast = new TimezonedDatetime(); | ||
|
||
$input = new \Carbon\Carbon('2022-12-15 04:00:00', 'America/Toronto'); | ||
|
||
$output = $cast->set(fakeModel(), 'id', $input, []); | ||
|
||
expect($output)->toBe('2022-12-15 09:00:00'); | ||
}); |
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