Skip to content

Commit

Permalink
Merge pull request #588 from sediqzada94/fix/hashtag-factory-name-unique
Browse files Browse the repository at this point in the history
Fix HashtagFactory to Prevent Duplicate Name Constraint Violations
  • Loading branch information
nunomaduro authored Sep 9, 2024
2 parents a5ce9e6 + 3a4c227 commit bd1bd59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion database/factories/HashtagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class HashtagFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->word(),
'name' => $this->faker->unique()->word(),
];
}
}
12 changes: 12 additions & 0 deletions tests/Unit/Factories/HashtagFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use App\Models\Hashtag;

it('creates a hashtag with a unique name', function () {
$hashtags = Hashtag::factory(40)->create();

$this->assertCount(40, $hashtags);
$this->assertEquals(40, $hashtags->unique('name')->count());
});

0 comments on commit bd1bd59

Please sign in to comment.