Fix DocumentFactory withoutTranslations + path trailing period
afterCreating appends rather than replaces, so a no-op closure does not override configure(). Use withoutAfterCreating() to actually clear the translation-creation callback (otherwise DocumentTranslation::factory() recurses through Document::factory()->withoutTranslations()). Also use words() instead of sentence() to avoid Faker's trailing period producing paths like "Foo bar..md". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ class DocumentFactory extends Factory
|
|||||||
|
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
$title = fake()->unique()->sentence(3);
|
$title = rtrim(fake()->unique()->words(3, true), '.');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'path' => $title . '.md',
|
'path' => $title . '.md',
|
||||||
@@ -29,8 +29,9 @@ public function definition(): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After creating, attach a translation in the document's default_locale.
|
* After creating, attach a translation in the document's default_locale
|
||||||
* Pass an explicit ['title' => ..., 'content' => ...] via withTranslation() to override.
|
* (skipped if a translation was already created via state, or if the
|
||||||
|
* caller used withoutTranslations()).
|
||||||
*/
|
*/
|
||||||
public function configure(): static
|
public function configure(): static
|
||||||
{
|
{
|
||||||
@@ -45,7 +46,7 @@ public function configure(): static
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the default_locale and create the corresponding translation.
|
* Override the default_locale (auto-translation will be created in this locale).
|
||||||
*/
|
*/
|
||||||
public function defaultLocale(string $locale): static
|
public function defaultLocale(string $locale): static
|
||||||
{
|
{
|
||||||
@@ -53,10 +54,12 @@ public function defaultLocale(string $locale): static
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suppress automatic translation creation (caller will create manually).
|
* Suppress automatic translation creation. Uses Laravel's built-in
|
||||||
|
* withoutAfterCreating() to clear callbacks rather than appending a no-op
|
||||||
|
* (afterCreating appends, so a no-op closure does NOT override the configure() callback).
|
||||||
*/
|
*/
|
||||||
public function withoutTranslations(): static
|
public function withoutTranslations(): static
|
||||||
{
|
{
|
||||||
return $this->afterCreating(fn () => null);
|
return $this->withoutAfterCreating();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user