diff --git a/README.md b/README.md index d1fe8ed..0165eb5 100644 --- a/README.md +++ b/README.md @@ -87,3 +87,11 @@ Test method `test_duplicate_name()`. --- +## Task 7. Automatic Column Value + +Folder `database/migrations/task7` contains a migration for companies table. Edit that migration, so that if someone creates a company without the name, the automatic name would be "My company". + +Test method `test_automatic_value()`. + +--- + diff --git a/database/migrations/task7/2021_11_09_084922_create_companies_table.php b/database/migrations/task7/2021_11_09_084922_create_companies_table.php new file mode 100644 index 0000000..5e05207 --- /dev/null +++ b/database/migrations/task7/2021_11_09_084922_create_companies_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('companies'); + } +} diff --git a/tests/Feature/MigrationsTest.php b/tests/Feature/MigrationsTest.php index aaafe29..95c93c1 100644 --- a/tests/Feature/MigrationsTest.php +++ b/tests/Feature/MigrationsTest.php @@ -86,4 +86,13 @@ class MigrationsTest extends TestCase Company::create(['name' => 'Company One']); Company::create(['name' => 'Company One']); } + + public function test_automatic_value() + { + Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task7']); + + Company::create([]); + $company = Company::first(); + $this->assertEquals('My company', $company->name); + } }