From 889ac9b7f92714c33cdd6ed170e22ecdb6a4de7b Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sat, 18 Jul 2026 14:45:55 +0300 Subject: [PATCH] feat: add Site model, migration, and factory Implements Task 2: creates the Site model with fillable name, url, and description fields; the corresponding database migration; and a factory for generating test data. Includes TDD tests verifying model creation with and without optional description. Co-Authored-By: Claude Sonnet 5 --- app/Models/Site.php | 17 +++++++++++++ database/factories/SiteFactory.php | 20 +++++++++++++++ .../2026_07_18_114506_create_sites_table.php | 24 ++++++++++++++++++ tests/Feature/SiteModelTest.php | 25 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 app/Models/Site.php create mode 100644 database/factories/SiteFactory.php create mode 100644 database/migrations/2026_07_18_114506_create_sites_table.php create mode 100644 tests/Feature/SiteModelTest.php diff --git a/app/Models/Site.php b/app/Models/Site.php new file mode 100644 index 0000000..cd39e75 --- /dev/null +++ b/app/Models/Site.php @@ -0,0 +1,17 @@ + fake()->company(), + 'url' => fake()->url(), + 'description' => fake()->optional()->sentence(), + ]; + } +} diff --git a/database/migrations/2026_07_18_114506_create_sites_table.php b/database/migrations/2026_07_18_114506_create_sites_table.php new file mode 100644 index 0000000..8368372 --- /dev/null +++ b/database/migrations/2026_07_18_114506_create_sites_table.php @@ -0,0 +1,24 @@ +id(); + $table->string('name'); + $table->string('url'); + $table->text('description')->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('sites'); + } +}; diff --git a/tests/Feature/SiteModelTest.php b/tests/Feature/SiteModelTest.php new file mode 100644 index 0000000..889b0a9 --- /dev/null +++ b/tests/Feature/SiteModelTest.php @@ -0,0 +1,25 @@ + 'My Blog', + 'url' => 'https://example.com', + 'description' => 'A blog about things', + ]); + + expect($site->fresh()) + ->name->toBe('My Blog') + ->url->toBe('https://example.com') + ->description->toBe('A blog about things'); +}); + +test('a site can be created without a description', function () { + $site = Site::create([ + 'name' => 'My Blog', + 'url' => 'https://example.com', + ]); + + expect($site->fresh()->description)->toBeNull(); +});