From 76504ffe8703219babf8236fc481e82ce025643b Mon Sep 17 00:00:00 2001 From: PovilasKorop Date: Tue, 9 Nov 2021 10:53:43 +0200 Subject: [PATCH] Task 7 - automatic column value --- README.md | 8 +++++ ...21_11_09_084922_create_companies_table.php | 34 +++++++++++++++++++ tests/Feature/MigrationsTest.php | 9 +++++ 3 files changed, 51 insertions(+) create mode 100644 database/migrations/task7/2021_11_09_084922_create_companies_table.php 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); + } }