Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion tests/MigrationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RonasIT\Support\Tests;

use Illuminate\Support\Carbon;
use RonasIT\Support\Events\WarningEvent;
use RonasIT\Support\Exceptions\UnknownFieldTypeException;
use RonasIT\Support\Generators\MigrationGenerator;

Expand Down Expand Up @@ -72,9 +73,40 @@ public function testCreateMigrationMYSQL()
'string' => ['title', 'body'],
'json' => ['meta'],
'timestamp' => ['created_at'],
'timestamp-required' => ['published_at'],
])
->generate();

$this->assertGeneratedFileEquals('migrations_mysql.php', 'database/migrations/2022_02_02_000000_posts_create_table.php');
$this->assertGeneratedFileEquals('generated_mysql_migration.php', 'database/migrations/2022_02_02_000000_posts_create_table.php');
}

public function testCreateMigrationWithoutMigrationStub(): void
{
Carbon::setTestNow('2022-02-02');

config(['entity-generator.stubs.migration' => 'incorrect_stub']);

app(MigrationGenerator::class)
->setModel('Post')
->setRelations([
'belongsTo' => [],
'belongsToMany' => [],
'hasOne' => [],
'hasMany' => [],
])
->setFields([
'integer-required' => ['media_id', 'user_id'],
'string' => ['title', 'body'],
'json' => ['meta'],
'timestamp' => ['created_at'],
])
->generate();

$this->assertFileDoesNotExist('database/migrations/2022_02_02_000000_posts_create_table.php');

$this->assertEventPushed(
className: WarningEvent::class,
message: 'Generation of migration has been skipped cause the view incorrect_stub from the config entity-generator.stubs.migration is not exists. Please check that config has the correct view name value.',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up(): void
$table->string('body')->nullable();
$table->json('meta')->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('published_at')->nullable();
$table->timestamps();
});
}
Expand Down