Added user related factories

main
Igor Scheller 4 years ago committed by msquare
parent 4ff44d141c
commit ec355d40f5

@ -49,6 +49,7 @@
}, },
"require-dev": { "require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.3.0", "dms/phpunit-arraysubset-asserts": "^0.3.0",
"fakerphp/faker": "^1.14.1",
"filp/whoops": "^2.12", "filp/whoops": "^2.12",
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6", "squizlabs/php_codesniffer": "^3.6",
@ -65,6 +66,7 @@
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Database\\Factories\\Engelsystem\\Models\\": "db/factories/",
"Engelsystem\\Test\\": "tests/" "Engelsystem\\Test\\": "tests/"
} }
} }

437
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,24 @@
<?php
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\Contact;
use Illuminate\Database\Eloquent\Factories\Factory;
class ContactFactory extends Factory
{
/** @var string */
protected $model = Contact::class;
/**
* @return array
*/
public function definition()
{
return [
'dect' => $this->faker->optional()->numberBetween(1000, 9999),
'email' => $this->faker->unique()->optional()->safeEmail(),
'mobile' => $this->faker->optional(.2)->phoneNumber(),
];
}
}

@ -0,0 +1,22 @@
<?php
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\PasswordReset;
use Illuminate\Database\Eloquent\Factories\Factory;
class PasswordResetFactory extends Factory
{
/** @var string */
protected $model = PasswordReset::class;
/**
* @return array
*/
public function definition()
{
return [
'token' => md5($this->faker->unique()->password()),
];
}
}

@ -0,0 +1,31 @@
<?php
namespace Database\Factories\Engelsystem\Models\User;
use Carbon\Carbon;
use Engelsystem\Models\User\PersonalData;
use Illuminate\Database\Eloquent\Factories\Factory;
class PersonalDataFactory extends Factory
{
/** @var string */
protected $model = PersonalData::class;
/**
* @return array
*/
public function definition()
{
$arrival = $this->faker->optional()->dateTimeThisMonth('2 weeks');
$departure = $this->faker->optional()->dateTimeThisMonth('2 weeks');
return [
'first_name' => $this->faker->optional(.7)->firstName(),
'last_name' => $this->faker->optional()->lastName(),
'pronoun' => $this->faker->optional(.3)->pronoun(),
'shirt_size' => $this->faker->optional(.9)->shirtSize(),
'planned_arrival_date' => $arrival ? Carbon::instance($arrival) : null,
'planned_departure_date' => $departure ? Carbon::instance($departure) : null,
];
}
}

@ -0,0 +1,26 @@
<?php
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\Settings;
use Illuminate\Database\Eloquent\Factories\Factory;
class SettingsFactory extends Factory
{
/** @var string */
protected $model = Settings::class;
/**
* @return array
*/
public function definition()
{
return [
'language' => $this->faker->locale(),
'theme' => $this->faker->numberBetween(1, 20),
'email_human' => $this->faker->boolean(),
'email_shiftinfo' => $this->faker->boolean(),
'email_news' => $this->faker->boolean(),
];
}
}

@ -0,0 +1,47 @@
<?php
namespace Database\Factories\Engelsystem\Models\User;
use Carbon\Carbon;
use Engelsystem\Models\User\State;
use Illuminate\Database\Eloquent\Factories\Factory;
class StateFactory extends Factory
{
/** @var string */
protected $model = State::class;
/**
* @return array
*/
public function definition()
{
$arrival = $this->faker->optional()->dateTimeThisMonth();
return [
'arrived' => (bool)$arrival,
'arrival_date' => $arrival ? Carbon::instance($arrival) : null,
'active' => $this->faker->boolean(.3),
'force_active' => $this->faker->boolean(.1),
'got_shirt' => $this->faker->boolean(),
'got_voucher' => $this->faker->numberBetween(0, 10),
];
}
/**
* Indicate that the user is arrived
*
* @return self
*/
public function arrived()
{
return $this->state(
function (array $attributes) {
return [
'arrived' => true,
'arrival_date' => Carbon::instance($this->faker->dateTimeThisMonth()),
];
}
);
}
}

@ -0,0 +1,25 @@
<?php
namespace Database\Factories\Engelsystem\Models\User;
use Engelsystem\Models\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class UserFactory extends Factory
{
/** @var string */
protected $model = User::class;
/**
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->unique()->userName(),
'password' => password_hash($this->faker->password(), PASSWORD_DEFAULT),
'email' => $this->faker->unique()->safeEmail(),
'api_key' => md5($this->faker->unique()->password()),
];
}
}

@ -6,6 +6,7 @@ use Engelsystem\Config\Config;
use Engelsystem\Container\Container; use Engelsystem\Container\Container;
use Engelsystem\Container\ServiceProvider; use Engelsystem\Container\ServiceProvider;
use Illuminate\Container\Container as IlluminateContainer; use Illuminate\Container\Container as IlluminateContainer;
use Illuminate\Contracts\Container\Container as IlluminateContainerContract;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\MiddlewareInterface;
@ -50,6 +51,7 @@ class Application extends Container
$this->instance(Container::class, $this); $this->instance(Container::class, $this);
$this->instance(Application::class, $this); $this->instance(Application::class, $this);
$this->instance(IlluminateContainer::class, $this); $this->instance(IlluminateContainer::class, $this);
$this->instance(IlluminateContainerContract::class, $this);
$this->bind(ContainerInterface::class, self::class); $this->bind(ContainerInterface::class, self::class);
} }

@ -334,7 +334,7 @@ class Stats
$query->having($this->raw($having), '<=', $bucket); $query->having($this->raw($having), '<=', $bucket);
} }
$return[$bucket] = $query->count($this->raw($count)); $return[$bucket] = count($query->get($this->raw($count)));
} }
return $return; return $return;

@ -2,6 +2,7 @@
namespace Engelsystem\Models\User; namespace Engelsystem\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
/** /**
@ -15,6 +16,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/ */
class Contact extends HasUserModel class Contact extends HasUserModel
{ {
use HasFactory;
/** @var string The table associated with the model */ /** @var string The table associated with the model */
protected $table = 'users_contact'; protected $table = 'users_contact';

@ -3,6 +3,7 @@
namespace Engelsystem\Models\User; namespace Engelsystem\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
/** /**
@ -14,6 +15,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/ */
class PasswordReset extends HasUserModel class PasswordReset extends HasUserModel
{ {
use HasFactory;
/** @var bool enable timestamps for created_at */ /** @var bool enable timestamps for created_at */
public $timestamps = true; public $timestamps = true;

@ -3,6 +3,7 @@
namespace Engelsystem\Models\User; namespace Engelsystem\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
/** /**
@ -22,6 +23,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/ */
class PersonalData extends HasUserModel class PersonalData extends HasUserModel
{ {
use HasFactory;
/** @var string The table associated with the model */ /** @var string The table associated with the model */
protected $table = 'users_personal_data'; protected $table = 'users_personal_data';

@ -2,6 +2,7 @@
namespace Engelsystem\Models\User; namespace Engelsystem\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
/** /**
@ -19,6 +20,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/ */
class Settings extends HasUserModel class Settings extends HasUserModel
{ {
use HasFactory;
/** @var string The table associated with the model */ /** @var string The table associated with the model */
protected $table = 'users_settings'; protected $table = 'users_settings';

@ -3,6 +3,7 @@
namespace Engelsystem\Models\User; namespace Engelsystem\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
/** /**
@ -22,6 +23,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/ */
class State extends HasUserModel class State extends HasUserModel
{ {
use HasFactory;
/** @var string The table associated with the model */ /** @var string The table associated with the model */
protected $table = 'users_state'; protected $table = 'users_state';

@ -11,6 +11,7 @@ use Engelsystem\Models\OAuth;
use Engelsystem\Models\Question; use Engelsystem\Models\Question;
use Engelsystem\Models\Worklog; use Engelsystem\Models\Worklog;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
@ -57,6 +58,8 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
*/ */
class User extends BaseModel class User extends BaseModel
{ {
use HasFactory;
/** @var bool enable timestamps */ /** @var bool enable timestamps */
public $timestamps = true; public $timestamps = true;

@ -283,15 +283,7 @@ class NewsControllerTest extends ControllerTest
*/ */
protected function addUser() protected function addUser()
{ {
$user = new User([ $user = User::factory(['id' => 42])->create();
'name' => 'foo',
'password' => '',
'email' => '',
'api_key' => '',
'last_login_at' => null,
]);
$user->forceFill(['id' => 42]);
$user->save();
$this->auth->expects($this->any()) $this->auth->expects($this->any())
->method('user') ->method('user')

@ -241,14 +241,7 @@ class QuestionsControllerTest extends ControllerTest
$this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class); $this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class);
$this->user = new User([ $this->user = User::factory()->create();
'name' => 'foo',
'password' => '',
'email' => '',
'api_key' => '',
'last_login_at' => null,
]);
$this->user->save();
$this->setExpects($this->auth, 'user', null, $this->user, $this->any()); $this->setExpects($this->auth, 'user', null, $this->user, $this->any());
(new Question([ (new Question([

@ -185,22 +185,9 @@ class AuthControllerTest extends TestCase
*/ */
protected function createUser(): User protected function createUser(): User
{ {
$user = new User([ return User::factory(['id' => 42])
'name' => 'foo', ->has(Settings::factory(['language' => 'de_DE']))
'password' => '', ->create();
'email' => '',
'api_key' => '',
'last_login_at' => null,
]);
$user->forceFill(['id' => 42]);
$user->save();
$settings = new Settings(['language' => 'de_DE', 'theme' => '']);
$settings->user()
->associate($user)
->save();
return $user;
} }
/** /**

@ -269,15 +269,7 @@ class NewsControllerTest extends TestCase
*/ */
protected function addUser() protected function addUser()
{ {
$user = new User([ $user = User::factory()->create(['id' => 42]);
'name' => 'foo',
'password' => '',
'email' => '',
'api_key' => '',
'last_login_at' => null,
]);
$user->forceFill(['id' => 42]);
$user->save();
$this->auth->expects($this->any()) $this->auth->expects($this->any())
->method('user') ->method('user')

@ -494,36 +494,15 @@ class OAuthControllerTest extends TestCase
$this->app->instance('session', $this->session); $this->app->instance('session', $this->session);
$this->authenticatedUser = new User([ $this->authenticatedUser = User::factory()->create();
'name' => 'foo',
'password' => '',
'email' => 'foo@localhost',
'api_key' => '',
'last_login_at' => null,
]);
$this->authenticatedUser->save();
(new OAuth(['provider' => 'testprovider', 'identifier' => 'provider-user-identifier'])) (new OAuth(['provider' => 'testprovider', 'identifier' => 'provider-user-identifier']))
->user() ->user()
->associate($this->authenticatedUser) ->associate($this->authenticatedUser)
->save(); ->save();
$this->otherUser = new User([ $this->otherUser = User::factory()->create();
'name' => 'bar',
'password' => '', $this->otherAuthenticatedUser = User::factory()->create();
'email' => 'bar@localhost',
'api_key' => '',
'last_login_at' => null,
]);
$this->otherUser->save();
$this->otherAuthenticatedUser = new User([
'name' => 'baz',
'password' => '',
'email' => 'baz@localhost',
'api_key' => '',
'last_login_at' => null,
]);
$this->otherAuthenticatedUser->save();
(new OAuth(['provider' => 'testprovider', 'identifier' => 'provider-baz-identifier'])) (new OAuth(['provider' => 'testprovider', 'identifier' => 'provider-baz-identifier']))
->user() ->user()
->associate($this->otherAuthenticatedUser) ->associate($this->otherAuthenticatedUser)

@ -256,15 +256,7 @@ class PasswordResetControllerTest extends TestCase
*/ */
protected function createUser(): User protected function createUser(): User
{ {
$user = new User([ return User::factory()->create(['email' => 'foo@bar.batz']);
'name' => 'foo',
'password' => '',
'email' => 'foo@bar.batz',
'api_key' => '',
]);
$user->save();
return $user;
} }
/** /**

@ -90,14 +90,7 @@ class QuestionsControllerTest extends ControllerTest
*/ */
public function testDeleteNotOwn() public function testDeleteNotOwn()
{ {
$otherUser = new User([ $otherUser = User::factory()->create();
'name' => 'bar',
'password' => '',
'email' => '.',
'api_key' => '',
'last_login_at' => null,
]);
$otherUser->save();
(new Question([ (new Question([
'user_id' => $otherUser->id, 'user_id' => $otherUser->id,
'text' => 'Lorem?', 'text' => 'Lorem?',
@ -189,14 +182,7 @@ class QuestionsControllerTest extends ControllerTest
$this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class); $this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class);
$this->user = new User([ $this->user = User::factory()->create();
'name' => 'foo',
'password' => '',
'email' => '',
'api_key' => '',
'last_login_at' => null,
]);
$this->user->save();
$this->setExpects($this->auth, 'user', null, $this->user, $this->any()); $this->setExpects($this->auth, 'user', null, $this->user, $this->any());
(new Question([ (new Question([

@ -313,12 +313,6 @@ class SettingsControllerTest extends TestCase
$this->auth = $this->createMock(Authenticator::class); $this->auth = $this->createMock(Authenticator::class);
$this->app->instance(Authenticator::class, $this->auth); $this->app->instance(Authenticator::class, $this->auth);
$this->user = new User([ $this->user = User::factory()->create();
'name' => 'testuser',
'email' => 'test@engelsystem.de',
'password' => 'xxx',
'api_key' => 'xxx'
]);
$this->user->save();
} }
} }

@ -3,7 +3,6 @@
namespace Engelsystem\Test\Unit\Events\Listener; namespace Engelsystem\Test\Unit\Events\Listener;
use Engelsystem\Events\Listener\News; use Engelsystem\Events\Listener\News;
use Engelsystem\Helpers\Authenticator;
use Engelsystem\Mail\EngelsystemMailer; use Engelsystem\Mail\EngelsystemMailer;
use Engelsystem\Models\News as NewsModel; use Engelsystem\Models\News as NewsModel;
use Engelsystem\Models\User\Settings; use Engelsystem\Models\User\Settings;
@ -80,22 +79,12 @@ class NewsTest extends TestCase
$this->mailer = $this->createMock(EngelsystemMailer::class); $this->mailer = $this->createMock(EngelsystemMailer::class);
$this->app->instance(EngelsystemMailer::class, $this->mailer); $this->app->instance(EngelsystemMailer::class, $this->mailer);
$this->user = new User([ $this->user = User::factory()
'name' => 'test', ->has(Settings::factory([
'password' => '',
'email' => 'foo@bar.baz',
'api_key' => '',
]);
$this->user->save();
$settings = new Settings([
'language' => '', 'language' => '',
'theme' => 1, 'theme' => 1,
'email_news' => true, 'email_news' => true,
]); ]))
$settings->user() ->create();
->associate($this->user)
->save();
} }
} }

@ -0,0 +1,30 @@
<?php
namespace Engelsystem\Test\Unit;
use Faker\Provider\Base;
class FakerProvider extends Base
{
/** @var string[] */
protected static $pronouns = ['fae', 'ae', 'e', 'ey', 'he', 'per', 'she', 'tey', 'they', 've', 'xe', 'ze', 'zie'];
/** @var string[] */
protected static $shirtSizes = ['S', 'S-G', 'M', 'M-G', 'L', 'L-G', 'XL', 'XL-G', '2XL', '3XL', '4XL'];
/**
* @return string
*/
public function pronoun()
{
return static::randomElement(static::$pronouns);
}
/**
* @return string
*/
public function shirtSize(): string
{
return static::randomElement(static::$shirtSizes);
}
}

@ -165,18 +165,15 @@ class AuthenticatorTest extends ServiceProviderTest
$session = $this->createMock(Session::class); $session = $this->createMock(Session::class);
$userRepository = new User(); $userRepository = new User();
(new User([ User::factory([
'name' => 'lorem', 'name' => 'lorem',
'password' => password_hash('testing', PASSWORD_DEFAULT), 'password' => password_hash('testing', PASSWORD_DEFAULT),
'email' => 'lorem@foo.bar', 'email' => 'lorem@foo.bar',
'api_key' => '', ])->create();
]))->save(); User::factory([
(new User([
'name' => 'ipsum', 'name' => 'ipsum',
'password' => '', 'password' => '',
'email' => 'ipsum@foo.bar', ])->create();
'api_key' => '',
]))->save();
$auth = new Authenticator($request, $session, $userRepository); $auth = new Authenticator($request, $session, $userRepository);
$this->assertNull($auth->authenticate('not-existing', 'foo')); $this->assertNull($auth->authenticate('not-existing', 'foo'));
@ -192,13 +189,11 @@ class AuthenticatorTest extends ServiceProviderTest
{ {
$this->initDatabase(); $this->initDatabase();
$password = password_hash('testing', PASSWORD_ARGON2I); $password = password_hash('testing', PASSWORD_ARGON2I);
$user = new User([ /** @var User $user */
$user = User::factory([
'name' => 'lorem', 'name' => 'lorem',
'password' => $password, 'password' => $password,
'email' => 'lorem@foo.bar', ])->create();
'api_key' => '',
]);
$user->save();
/** @var Authenticator|MockObject $auth */ /** @var Authenticator|MockObject $auth */
$auth = $this->getMockBuilder(Authenticator::class) $auth = $this->getMockBuilder(Authenticator::class)
@ -221,12 +216,11 @@ class AuthenticatorTest extends ServiceProviderTest
public function testSetPassword() public function testSetPassword()
{ {
$this->initDatabase(); $this->initDatabase();
$user = new User([ /** @var User $user */
$user = User::factory([
'name' => 'ipsum', 'name' => 'ipsum',
'password' => '', 'password' => '',
'email' => 'ipsum@foo.bar', ])->create();
'api_key' => '',
]);
$user->save(); $user->save();
$auth = $this->getAuthenticator(); $auth = $this->getAuthenticator();

@ -18,7 +18,7 @@ class UserAwareLoggerTest extends ServiceProviderTest
*/ */
public function testLog() public function testLog()
{ {
$user = (new User())->forceFill(['id' => 1, 'name' => 'admin']); $user = User::factory(['id' => 1, 'name' => 'admin'])->make();
/** @var LogEntry|MockObject $logEntry */ /** @var LogEntry|MockObject $logEntry */
$logEntry = $this->getMockBuilder(LogEntry::class) $logEntry = $this->getMockBuilder(LogEntry::class)

@ -47,21 +47,10 @@ class EngelsystemMailerTest extends TestCase
{ {
$this->initDatabase(); $this->initDatabase();
$settings = new Settings([ $user = User::factory(['email' => 'foo@bar.baz'])
'language' => 'de_DE', ->has(Settings::factory(['language' => 'de_DE']))
'theme' => '', ->has(Contact::factory(['email' => null]))
]); ->create();
$contact = new Contact(['email' => null]);
$user = new User([
'id' => 42,
'name' => 'username',
'email' => 'foo@bar.baz',
'password' => '',
'api_key' => '',
]);
$user->save();
$settings->user()->associate($user)->save();
$contact->user()->associate($user)->save();
/** @var Renderer|MockObject $view */ /** @var Renderer|MockObject $view */
$view = $this->createMock(Renderer::class); $view = $this->createMock(Renderer::class);

@ -40,15 +40,13 @@ class SetLocaleTest extends TestCase
/** @var ResponseInterface|MockObject $response */ /** @var ResponseInterface|MockObject $response */
$response = $this->getMockForAbstractClass(ResponseInterface::class); $response = $this->getMockForAbstractClass(ResponseInterface::class);
$user = User::create([ /** @var User $user */
$user = User::factory([
'name' => 'user', 'name' => 'user',
'password' => '',
'email' => 'foo@bar.baz', 'email' => 'foo@bar.baz',
'api_key' => '', ])
]); ->has(Settings::factory(['language' => 'uf_UF']))
$settings = new Settings(['language' => 'uf_UF', 'theme' => '']); ->create();
$settings->user()->associate($user);
$settings->save();
$locale = 'te_ST'; $locale = 'te_ST';

@ -34,19 +34,8 @@ class MessageTest extends ModelTest
{ {
parent::setUp(); parent::setUp();
$this->user1 = User::create([ $this->user1 = User::factory()->create();
'name' => 'user1', $this->user2 = User::factory()->create();
'password' => '',
'email' => 'user1@example.com',
'api_key' => '',
]);
$this->user2 = User::create([
'name' => 'user2',
'password' => '',
'email' => 'user2@example.com',
'api_key' => '',
]);
$this->message1 = Message::create([ $this->message1 = Message::create([
'user_id' => $this->user1->id, 'user_id' => $this->user1->id,

@ -29,12 +29,7 @@ class NewsCommentsTest extends ModelTest
{ {
parent::setUp(); parent::setUp();
$this->user = User::create([ $this->user = User::factory()->create();
'name' => 'lorem',
'password' => '',
'email' => 'lorem@example.com',
'api_key' => '',
]);
$this->news = News::create([ $this->news = News::create([
'title' => 'test title', 'title' => 'test title',

@ -25,13 +25,7 @@ class NewsTest extends ModelTest
{ {
parent::setUp(); parent::setUp();
$this->user = (new User())->create([ $this->user = User::factory()->create();
'name' => 'lorem',
'password' => '',
'email' => 'foo@bar.batz',
'api_key' => '',
]);
$this->newsData = [ $this->newsData = [
'title' => 'test title', 'title' => 'test title',
'text' => 'test text', 'text' => 'test text',

@ -28,23 +28,8 @@ class QuestionTest extends ModelTest
{ {
parent::setUp(); parent::setUp();
$this->user1 = User::create( $this->user1 = User::factory()->create();
[ $this->user2 = User::factory()->create();
'name' => 'user1',
'password' => '',
'email' => 'user1@example.com',
'api_key' => '',
]
);
$this->user2 = User::create(
[
'name' => 'user2',
'password' => '',
'email' => 'user2@example.com',
'api_key' => '',
]
);
} }
/** /**

@ -15,18 +15,8 @@ class WorklogTest extends ModelTest
*/ */
public function testCreator(): void public function testCreator(): void
{ {
$user1 = User::create([ $user1 = User::factory()->create();
'name' => 'user1', $user2 = User::factory()->create();
'password' => '',
'email' => 'user1@example.com',
'api_key' => '',
]);
$user2 = User::create([
'name' => 'user2',
'password' => '',
'email' => 'user2@example.com',
'api_key' => '',
]);
$worklog = new Worklog(); $worklog = new Worklog();
$worklog->user()->associate($user1); $worklog->user()->associate($user1);

@ -34,7 +34,7 @@ class AuthenticationTest extends ExtensionTest
{ {
/** @var Authenticator|MockObject $auth */ /** @var Authenticator|MockObject $auth */
$auth = $this->createMock(Authenticator::class); $auth = $this->createMock(Authenticator::class);
$user = new User(); $user = User::factory()->make();
$auth->expects($this->exactly(4)) $auth->expects($this->exactly(4))
->method('user') ->method('user')

@ -3,9 +3,9 @@
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions; namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Test\Unit\TestCase;
use Exception; use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Twig\Node\Node as TwigNode; use Twig\Node\Node as TwigNode;
use Twig\TwigFunction; use Twig\TwigFunction;

@ -20,7 +20,7 @@ class GlobalsTest extends ExtensionTest
$auth = $this->createMock(Authenticator::class); $auth = $this->createMock(Authenticator::class);
/** @var Request|MockObject $request */ /** @var Request|MockObject $request */
$request = $this->createMock(Request::class); $request = $this->createMock(Request::class);
$user = new User(); $user = User::factory()->make();
$auth->expects($this->exactly(2)) $auth->expects($this->exactly(2))
->method('user') ->method('user')

@ -3,6 +3,8 @@
namespace Engelsystem\Test\Unit; namespace Engelsystem\Test\Unit;
use Engelsystem\Application; use Engelsystem\Application;
use Faker\Factory as FakerFactory;
use Faker\Generator;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder; use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
use PHPUnit\Framework\TestCase as PHPUnitTestCase; use PHPUnit\Framework\TestCase as PHPUnitTestCase;
@ -45,5 +47,9 @@ abstract class TestCase extends PHPUnitTestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->app = new Application(__DIR__ . '/../../'); $this->app = new Application(__DIR__ . '/../../');
$faker = FakerFactory::create();
$faker->addProvider(new FakerProvider($faker));
$this->app->instance(Generator::class, $faker);
} }
} }

Loading…
Cancel
Save