diff --git a/README.md b/README.md index bc85106..dee6bf7 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,11 @@ Test method `test_column_added_to_the_table()`. --- +## Task 3. Soft Deletes. + +Folder `database/migrations/task3` contains a migration for projects table. You need to add a field there, for Soft Delete functionality. + +Test method `test_soft_deletes()`. + +--- + diff --git a/app/Models/Project.php b/app/Models/Project.php new file mode 100644 index 0000000..dc43be0 --- /dev/null +++ b/app/Models/Project.php @@ -0,0 +1,12 @@ + $this->faker->text(20), + ]; + } +} diff --git a/database/migrations/task3/2021_11_09_080955_create_projects_table.php b/database/migrations/task3/2021_11_09_080955_create_projects_table.php new file mode 100644 index 0000000..9dc9d7b --- /dev/null +++ b/database/migrations/task3/2021_11_09_080955_create_projects_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('name'); + $table->timestamps(); + + // TASK: Add soft deletes column here + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('projects'); + } +} diff --git a/tests/Feature/MigrationsTest.php b/tests/Feature/MigrationsTest.php index f1fb7f8..403a284 100644 --- a/tests/Feature/MigrationsTest.php +++ b/tests/Feature/MigrationsTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\Models\Project; use App\Models\User; use Illuminate\Support\Facades\Artisan; use Tests\TestCase; @@ -39,4 +40,15 @@ class MigrationsTest extends TestCase $this->assertEquals(3, $fieldNumber); } + + public function test_soft_deletes() + { + // We just test if the test succeeds or throws an exception + $this->expectNotToPerformAssertions(); + + Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task3']); + + $project = Project::factory()->create(); + $project->delete(); + } }