Skip to content

Commit 1cf1915

Browse files
committed
Add another test
1 parent a68487f commit 1cf1915

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/FactoryTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use DirectoryTree\Dummy\Tests\Fixtures\FactoryClassStub;
44
use DirectoryTree\Dummy\Tests\Fixtures\FactoryStub;
5+
use DirectoryTree\Dummy\Tests\Fixtures\FactoryWithConfigurationStub;
56
use DirectoryTree\Dummy\Tests\Fixtures\FactoryWithCustomClassStub;
67
use DirectoryTree\Dummy\Tests\Fixtures\FactoryWithStateStub;
78
use Illuminate\Support\Collection;
@@ -119,3 +120,9 @@
119120
expect($instance->name)->toBe('Admin');
120121
expect($instance->email)->toBe('admin@example.com');
121122
});
123+
124+
it('can use after making callbacks', function () {
125+
$instance = FactoryWithConfigurationStub::new()->make();
126+
127+
expect($instance->name)->toBe('Custom');
128+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace DirectoryTree\Dummy\Tests\Fixtures;
4+
5+
use DirectoryTree\Dummy\Factory;
6+
use Illuminate\Support\Fluent;
7+
8+
class FactoryWithConfigurationStub extends Factory
9+
{
10+
protected function definition(): array
11+
{
12+
return [
13+
'name' => $this->faker->name(),
14+
'email' => $this->faker->email(),
15+
];
16+
}
17+
18+
protected function configure(): static
19+
{
20+
return $this->afterMaking(function (Fluent $fluent) {
21+
$fluent->name = 'Custom';
22+
});
23+
}
24+
}

0 commit comments

Comments
 (0)