When running the test below, I get an error at the line $this->assertTrue(File::exists(database_path('migrations/'.$filename)));
. My model is being created and the migration file is being created, but I don't think the $filename
function is running properly because the migration file being created is named 2021_10_28_165227_create_tests_table.php
but the assert
checks are looking for migration file 2021_10_28_045227_create_tests_table.php
. As you can see $now->format('h')
part of the filename is different from what is created than what is being verified.
A separate variable that may or may not be an issue is I am using Laravel Valet, which might be a reason the hour, seconds and minutes are not synced to my local time.
...
class TenantScopeTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function a_model_has_a_tenant_id_on_the_migration()
{
$now = Carbon::now();
$this->artisan('make:model Test -m');
// find the migration file and check it has a tenant_id on it
$filename = $now->year . '_' . $now->format('m') . '_' . $now->format('d') . '_' . $now->format('h')
. $now->format('i') . $now->format('s') .
'_create_tests_table.php';
$this->assertTrue(File::exists(database_path('migrations/'.$filename)));
$this->assertStringContainsString('$table->unsignedBigInteger(\'tenant_id\')->index();',
File::get(database_path('migrations/'.$filename)));
// clean up
File::delete(database_path('migrations/'.$filename));
File::delete(app_path('Models/Test.php'));
}
...
CodePudding user response:
Maybe selecting a different timezone when using Carbon::now() would fix your issue