Added more factories
parent
ec355d40f5
commit
ff8adafd33
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Engelsystem\Models\Faq;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class FaqFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = Faq::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'question' => $this->faker->text(100),
|
||||
'text' => $this->faker->optional(.5, '')->realText(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Engelsystem\Models\Message;
|
||||
use Engelsystem\Models\User\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class MessageFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = Message::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'receiver_id' => User::factory(),
|
||||
'read' => $this->faker->boolean(),
|
||||
'text' => $this->faker->text(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Engelsystem\Models\News;
|
||||
use Engelsystem\Models\NewsComment;
|
||||
use Engelsystem\Models\User\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class NewsCommentFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = NewsComment::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'news_id' => News::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'text' => $this->faker->text(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Engelsystem\Models\News;
|
||||
use Engelsystem\Models\User\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class NewsFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = News::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'title' => $this->faker->text(50),
|
||||
'text' => $this->faker->realText(),
|
||||
'is_meeting' => $this->faker->boolean(),
|
||||
'is_pinned' => $this->faker->boolean(.1),
|
||||
'user_id' => User::factory(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Engelsystem\Models\Question;
|
||||
use Engelsystem\Models\User\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class QuestionFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = Question::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'text' => $this->faker->text(100),
|
||||
'answerer_id' => $this->faker->optional()->passthrough(User::factory()),
|
||||
'answer' => function (array $attributes) {
|
||||
return $attributes['answerer_id'] ? $this->faker->text() : null;
|
||||
},
|
||||
'answered_at' => function (array $attributes) {
|
||||
return $attributes['answerer_id'] ? Carbon::instance($this->faker->dateTimeThisMonth()) : null;
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Engelsystem\Models\Room;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class RoomFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = Room::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->unique()->firstName(),
|
||||
'map_url' => $this->faker->url(),
|
||||
'description' => $this->faker->text(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models\Shifts;
|
||||
|
||||
use Engelsystem\Models\Shifts\Schedule;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ScheduleFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = Schedule::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->words(4, true),
|
||||
'url' => $this->faker->parse('https://{{safeEmailDomain}}/{{slug}}.xml'),
|
||||
'shift_type' => $this->faker->numberBetween(1, 5),
|
||||
'minutes_before' => 15,
|
||||
'minutes_after' => 15,
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Engelsystem\Models;
|
||||
|
||||
use Engelsystem\Models\User\User;
|
||||
use Engelsystem\Models\Worklog;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class WorklogFactory extends Factory
|
||||
{
|
||||
/** @var string */
|
||||
protected $model = Worklog::class;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => User::factory(),
|
||||
'creator_id' => User::factory(),
|
||||
'hours' => $this->faker->randomFloat(2, 0.01, 10),
|
||||
'comment' => $this->faker->text(30),
|
||||
'worked_at' => $this->faker->dateTimeThisMonth(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit;
|
||||
|
||||
use Engelsystem\Models\Faq;
|
||||
use Engelsystem\Models\Message;
|
||||
use Engelsystem\Models\News;
|
||||
use Engelsystem\Models\NewsComment;
|
||||
use Engelsystem\Models\Question;
|
||||
use Engelsystem\Models\Room;
|
||||
use Engelsystem\Models\Shifts\Schedule;
|
||||
use Engelsystem\Models\User\Contact;
|
||||
use Engelsystem\Models\User\PasswordReset;
|
||||
use Engelsystem\Models\User\PersonalData;
|
||||
use Engelsystem\Models\User\Settings;
|
||||
use Engelsystem\Models\User\State;
|
||||
use Engelsystem\Models\User\User;
|
||||
use Engelsystem\Models\Worklog;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FactoriesTest extends TestCase
|
||||
{
|
||||
use HasDatabase;
|
||||
|
||||
/** @var string[] */
|
||||
protected $models = [
|
||||
User::class,
|
||||
Contact::class,
|
||||
PersonalData::class,
|
||||
Settings::class,
|
||||
State::class,
|
||||
PasswordReset::class,
|
||||
Worklog::class,
|
||||
News::class,
|
||||
NewsComment::class,
|
||||
Message::class,
|
||||
Faq::class,
|
||||
Question::class,
|
||||
Room::class,
|
||||
Schedule::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Test all existing model factories
|
||||
*/
|
||||
public function testFactories()
|
||||
{
|
||||
$this->initDatabase();
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
$instance = (new $model())->factory()->create();
|
||||
$this->assertInstanceOf(Model::class, $instance);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue