Skip to content

Commit

Permalink
Merge pull request #3 from zero-to-prod/docs/update-incorrect-example…
Browse files Browse the repository at this point in the history
…-in-the-custom-class-instantiation-section

docs/update-incorrect-example-in-the-custom-class-instantiation-section
  • Loading branch information
zero-to-prod authored Oct 23, 2024
2 parents 87af485 + 22de15a commit 980d361
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ echo $User->last_name; // 'Doe'

### Custom Class Instantiation

To customize instantiation, override the `instantiate()` method in your factory and call it within `make()`.
To customize instantiation, override the `make()` method.

```php
class User
Expand All @@ -118,15 +118,10 @@ class UserFactory
];
}

private function instantiate(): User
private function make(): User
{
return new User($this->context['first_name'], $this->context['last_name']);
}

public function make(): User
{
return $this->instantiate();
}
}

$User = UserFactory::factory()->make();
Expand Down
7 changes: 1 addition & 6 deletions tests/Unit/OverrideExample/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ private function definition(): array
];
}

private function instantiate()
{
return new User($this->context['first_name'], $this->context['last_name']);
}

public function make(): User
{
return $this->instantiate();
return new User($this->context['first_name'], $this->context['last_name']);
}
}

0 comments on commit 980d361

Please sign in to comment.