Added more factories

main
Igor Scheller 4 years ago committed by msquare
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(),
];
}
}

@ -6,6 +6,7 @@ namespace Engelsystem\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property int $id
@ -20,6 +21,8 @@ use Illuminate\Database\Eloquent\Builder;
*/
class Faq extends BaseModel
{
use HasFactory;
/** @var bool Enable timestamps */
public $timestamps = true;

@ -7,6 +7,7 @@ namespace Engelsystem\Models;
use Engelsystem\Models\User\User;
use Engelsystem\Models\User\UsesUserModel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
@ -29,6 +30,7 @@ use Illuminate\Support\Carbon;
*/
class Message extends BaseModel
{
use HasFactory;
use UsesUserModel;
/** @var bool enable timestamps */

@ -7,6 +7,7 @@ namespace Engelsystem\Models;
use Carbon\Carbon;
use Engelsystem\Models\User\UsesUserModel;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder as QueryBuilder;
@ -32,6 +33,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/
class News extends BaseModel
{
use HasFactory;
use UsesUserModel;
/** @var bool Enable timestamps */

@ -6,6 +6,7 @@ namespace Engelsystem\Models;
use Carbon\Carbon;
use Engelsystem\Models\User\UsesUserModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Builder as QueryBuilder;
@ -27,6 +28,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/
class NewsComment extends BaseModel
{
use HasFactory;
use UsesUserModel;
/** @var bool Enable timestamps */

@ -8,6 +8,7 @@ use Carbon\Carbon;
use Engelsystem\Models\User\User;
use Engelsystem\Models\User\UsesUserModel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Builder as QueryBuilder;
@ -29,6 +30,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/
class Question extends BaseModel
{
use HasFactory;
use UsesUserModel;
/** @var bool Enable timestamps */

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Engelsystem\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Query\Builder as QueryBuilder;
/**
@ -24,6 +25,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/
class Room extends BaseModel
{
use HasFactory;
/** @var bool Enable timestamps */
public $timestamps = true;

@ -5,6 +5,7 @@ namespace Engelsystem\Models\Shifts;
use Carbon\Carbon;
use Engelsystem\Models\BaseModel;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder as QueryBuilder;
@ -31,6 +32,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/
class Schedule extends BaseModel
{
use HasFactory;
/** @var bool enable timestamps */
public $timestamps = true;

@ -5,6 +5,7 @@ namespace Engelsystem\Models;
use Carbon\Carbon;
use Engelsystem\Models\User\User;
use Engelsystem\Models\User\UsesUserModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Builder as QueryBuilder;
@ -27,6 +28,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/
class Worklog extends BaseModel
{
use HasFactory;
use UsesUserModel;
/** @var bool Enable timestamps */

@ -34,12 +34,8 @@ class NewsTest extends TestCase
*/
public function testCreated()
{
$news = new NewsModel([
'title' => 'Foo',
'text' => 'Bar',
'user_id' => 1,
]);
$news->save();
/** @var NewsModel $news */
$news = NewsModel::factory(['title' => 'Foo'])->create();
$i = 0;
$this->mailer->expects($this->exactly(2))

@ -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…
Cancel
Save