Skip to content

Commit

Permalink
Add option for published sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Sep 3, 2024
1 parent ee2f587 commit 79835e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public function published(bool|string $published): self
{
return match ($published) {
'random' => $this->sequence(fn (Sequence $sequence) => ['published' => collect([true, false])->random()]),
'sequence' => $this->sequence(fn (Sequence $sequence) => ['published' => true], ['published' => false]),
false, 'false' => $this->set('published', false),
default => $this->set('published', true),
};
Expand Down
7 changes: 5 additions & 2 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,14 @@ public function test_can_set_publish_state()
$entry = FactoryTestEntryFactory::new()->published('false')->create();
$this->assertSame(false, $entry->published());

$entry = FactoryTestEntryFactory::new()->site('random')->create();
$entry = FactoryTestEntryFactory::new()->published('random')->create();
$this->assertContains($entry->published(), [true, false]);

$entry = FactoryTestEntryFactory::new()->site('anything')->create();
$entry = FactoryTestEntryFactory::new()->published('anything')->create();
$this->assertSame(true, $entry->published());

$entries = FactoryTestEntryFactory::times(10)->published('sequence')->create();
$entries->each(fn ($entry, $index) => $this->assertSame($index % 2 === 0 ? true : false, $entry->published()));
}
}

Expand Down

0 comments on commit 79835e4

Please sign in to comment.