Task 7 - automatic column value

This commit is contained in:
PovilasKorop
2021-11-09 10:53:43 +02:00
parent 888d5d87c2
commit 76504ffe87
3 changed files with 51 additions and 0 deletions
+8
View File
@@ -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()`.
---
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// TASK: edit this migration so that if company is created without the name
// its automatic value of name would be "My company"
Schema::create('companies', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('companies');
}
}
+9
View File
@@ -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);
}
}