Fixed test case and travelTo function in test cases

This commit is contained in:
Constantin Graf
2024-06-05 23:13:04 +02:00
committed by Constantin Graf
parent 86555664c5
commit b0cdeb3e33
5 changed files with 40 additions and 16 deletions

View File

@@ -5,8 +5,10 @@ declare(strict_types=1);
namespace Tests;
use App\Service\PermissionStore;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Mail;
use TiMacDonald\Log\LogFake;
@@ -32,4 +34,17 @@ abstract class TestCase extends BaseTestCase
{
$this->assertEqualsCanonicalizing($ids, $models->pluck('id')->toArray());
}
/**
* Set the current time to the given time.
* This method fixes a bug, that setting the test now with Carbon::setTestNow() with a Carbon instance that has a timezone set, will not work as expected.
* IT will also set the timezone for model casts with type "datetime" to the timezone and not use the timezone configured in the configuration "app.timezone".
*
* @param Carbon|CarbonImmutable $date
* @param callable|null $callback
*/
public function travelTo($date, $callback = null): void
{
parent::travelTo($date->utc());
}
}