fedi-feed-router/database/factories/FeedFactory.php

81 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2025-07-06 01:35:59 +02:00
<?php
namespace Database\Factories;
use App\Models\Feed;
use App\Models\Language;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Feed>
*/
class FeedFactory extends Factory
{
protected $model = Feed::class;
public function definition(): array
{
return [
'name' => $this->faker->words(3, true),
'url' => $this->faker->url(),
'type' => $this->faker->randomElement(['website', 'rss']),
2025-08-10 21:47:10 +02:00
'provider' => $this->faker->randomElement(['vrt', 'belga']),
2025-08-10 15:20:28 +02:00
'language_id' => null,
2025-07-06 01:35:59 +02:00
'description' => $this->faker->optional()->sentence(),
'settings' => [],
'is_active' => true,
'last_fetched_at' => null,
];
}
public function inactive(): static
{
return $this->state(fn (array $attributes) => [
'is_active' => false,
]);
}
public function website(): static
{
return $this->state(fn (array $attributes) => [
'type' => 'website',
]);
}
public function rss(): static
{
return $this->state(fn (array $attributes) => [
'type' => 'rss',
]);
}
public function recentlyFetched(): static
{
return $this->state(fn (array $attributes) => [
'last_fetched_at' => now()->subHour(),
]);
}
2025-08-10 15:20:28 +02:00
public function language(Language $language): static
{
return $this->state(fn (array $attributes) => [
'language_id' => $language->id,
]);
}
2025-08-10 21:47:10 +02:00
public function vrt(): static
{
return $this->state(fn (array $attributes) => [
'provider' => 'vrt',
'url' => 'https://www.vrt.be/vrtnws/en/',
]);
}
public function belga(): static
{
return $this->state(fn (array $attributes) => [
'provider' => 'belga',
'url' => 'https://www.belganewsagency.eu/',
]);
}
2025-07-06 01:35:59 +02:00
}