Enabled foreign keys in sqlite tests, added missing fields to factories
This commit is contained in:
parent
0a0cf5265c
commit
39dbfabea7
|
@ -24,6 +24,7 @@ class AngelTypeFactory extends Factory
|
||||||
|
|
||||||
'restricted' => $this->faker->boolean(),
|
'restricted' => $this->faker->boolean(),
|
||||||
'requires_driver_license' => $this->faker->boolean(),
|
'requires_driver_license' => $this->faker->boolean(),
|
||||||
|
'requires_ifsg_certificate' => $this->faker->boolean(),
|
||||||
'shift_self_signup' => $this->faker->boolean(),
|
'shift_self_signup' => $this->faker->boolean(),
|
||||||
'show_on_dashboard' => $this->faker->boolean(),
|
'show_on_dashboard' => $this->faker->boolean(),
|
||||||
'hide_register' => $this->faker->boolean(),
|
'hide_register' => $this->faker->boolean(),
|
||||||
|
|
|
@ -18,6 +18,7 @@ class LocationFactory extends Factory
|
||||||
'name' => $this->faker->unique()->firstName(),
|
'name' => $this->faker->unique()->firstName(),
|
||||||
'map_url' => $this->faker->url(),
|
'map_url' => $this->faker->url(),
|
||||||
'description' => $this->faker->text(),
|
'description' => $this->faker->text(),
|
||||||
|
'dect' => $this->faker->optional()->numberBetween(1000, 9999),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Database\Factories\Engelsystem\Models;
|
namespace Database\Factories\Engelsystem\Models;
|
||||||
|
|
||||||
use Engelsystem\Models\OAuth;
|
use Engelsystem\Models\OAuth;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class OAuthFactory extends Factory
|
class OAuthFactory extends Factory
|
||||||
|
@ -18,11 +19,12 @@ class OAuthFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'provider' => $this->faker->unique()->word(),
|
'user_id' => User::factory(),
|
||||||
|
'provider' => $this->faker->unique()->word(),
|
||||||
'identifier' => $this->faker->unique()->word(),
|
'identifier' => $this->faker->unique()->word(),
|
||||||
'access_token' => $this->faker->unique()->word(),
|
'access_token' => $this->faker->unique()->word(),
|
||||||
'refresh_token' => $this->faker->unique()->word(),
|
'refresh_token' => $this->faker->unique()->word(),
|
||||||
'expires_at' => '2099-12-31',
|
'expires_at' => $this->faker->dateTimeInInterval('+5 days', '+3 months')->format('Y-m-d'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Database\Factories\Engelsystem\Models\User;
|
namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
use Engelsystem\Models\User\Contact;
|
use Engelsystem\Models\User\Contact;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class ContactFactory extends Factory
|
class ContactFactory extends Factory
|
||||||
|
@ -15,6 +16,7 @@ class ContactFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'user_id' => User::factory(),
|
||||||
'dect' => $this->faker->optional()->numberBetween(1000, 9999),
|
'dect' => $this->faker->optional()->numberBetween(1000, 9999),
|
||||||
'email' => $this->faker->unique()->optional()->safeEmail(),
|
'email' => $this->faker->unique()->optional()->safeEmail(),
|
||||||
'mobile' => $this->faker->optional(.2)->phoneNumber(),
|
'mobile' => $this->faker->optional(.2)->phoneNumber(),
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Database\Factories\Engelsystem\Models\User;
|
namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
use Engelsystem\Models\User\License;
|
use Engelsystem\Models\User\License;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class LicenseFactory extends Factory
|
class LicenseFactory extends Factory
|
||||||
|
@ -25,6 +26,7 @@ class LicenseFactory extends Factory
|
||||||
$ifsg_certificate_light = $this->faker->boolean(0.5) && !$ifsg_certificate;
|
$ifsg_certificate_light = $this->faker->boolean(0.5) && !$ifsg_certificate;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'user_id' => User::factory(),
|
||||||
'has_car' => $drive_car && $this->faker->boolean(.7),
|
'has_car' => $drive_car && $this->faker->boolean(.7),
|
||||||
'drive_forklift' => $drive_forklift,
|
'drive_forklift' => $drive_forklift,
|
||||||
'drive_car' => $drive_car,
|
'drive_car' => $drive_car,
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Database\Factories\Engelsystem\Models\User;
|
namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
use Engelsystem\Models\User\PasswordReset;
|
use Engelsystem\Models\User\PasswordReset;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class PasswordResetFactory extends Factory
|
class PasswordResetFactory extends Factory
|
||||||
|
@ -15,6 +16,7 @@ class PasswordResetFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'user_id' => User::factory(),
|
||||||
'token' => bin2hex(random_bytes(16)),
|
'token' => bin2hex(random_bytes(16)),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Engelsystem\Models\User\PersonalData;
|
use Engelsystem\Models\User\PersonalData;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class PersonalDataFactory extends Factory
|
class PersonalDataFactory extends Factory
|
||||||
|
@ -19,6 +20,7 @@ class PersonalDataFactory extends Factory
|
||||||
$departure = $this->faker->optional()->dateTimeThisMonth('2 weeks');
|
$departure = $this->faker->optional()->dateTimeThisMonth('2 weeks');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'user_id' => User::factory(),
|
||||||
'first_name' => $this->faker->optional(.7)->firstName(),
|
'first_name' => $this->faker->optional(.7)->firstName(),
|
||||||
'last_name' => $this->faker->optional()->lastName(),
|
'last_name' => $this->faker->optional()->lastName(),
|
||||||
'pronoun' => $this->faker->optional(.3)->pronoun(),
|
'pronoun' => $this->faker->optional(.3)->pronoun(),
|
||||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||||
namespace Database\Factories\Engelsystem\Models\User;
|
namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
use Engelsystem\Models\User\Settings;
|
use Engelsystem\Models\User\Settings;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class SettingsFactory extends Factory
|
class SettingsFactory extends Factory
|
||||||
|
@ -15,6 +16,7 @@ class SettingsFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'user_id' => User::factory(),
|
||||||
'language' => $this->faker->locale(),
|
'language' => $this->faker->locale(),
|
||||||
'theme' => $this->faker->numberBetween(1, 20),
|
'theme' => $this->faker->numberBetween(1, 20),
|
||||||
'email_human' => $this->faker->boolean(),
|
'email_human' => $this->faker->boolean(),
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Database\Factories\Engelsystem\Models\User;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Engelsystem\Models\User\State;
|
use Engelsystem\Models\User\State;
|
||||||
|
use Engelsystem\Models\User\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class StateFactory extends Factory
|
class StateFactory extends Factory
|
||||||
|
@ -18,6 +19,7 @@ class StateFactory extends Factory
|
||||||
$arrival = $this->faker->optional()->dateTimeThisMonth();
|
$arrival = $this->faker->optional()->dateTimeThisMonth();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
'user_id' => User::factory(),
|
||||||
'arrived' => (bool) $arrival,
|
'arrived' => (bool) $arrival,
|
||||||
'arrival_date' => $arrival ? Carbon::instance($arrival) : null,
|
'arrival_date' => $arrival ? Carbon::instance($arrival) : null,
|
||||||
'active' => $this->faker->boolean(.3),
|
'active' => $this->faker->boolean(.3),
|
||||||
|
|
|
@ -19,6 +19,7 @@ class UserFactory extends Factory
|
||||||
'password' => crypt(random_bytes(16), '$1$salt$'),
|
'password' => crypt(random_bytes(16), '$1$salt$'),
|
||||||
'email' => $this->faker->unique()->safeEmail(),
|
'email' => $this->faker->unique()->safeEmail(),
|
||||||
'api_key' => bin2hex(random_bytes(32)),
|
'api_key' => bin2hex(random_bytes(32)),
|
||||||
|
'updated_at' => $this->faker->dateTimeInInterval('-3 months', 'now'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,10 +279,11 @@ class NewsControllerTest extends ControllerTest
|
||||||
->willReturnSelf();
|
->willReturnSelf();
|
||||||
$this->app->instance('events.dispatcher', $eventDispatcher);
|
$this->app->instance('events.dispatcher', $eventDispatcher);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
(new News([
|
(new News([
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
'text' => '**foo**',
|
'text' => '**foo**',
|
||||||
'user_id' => 1,
|
'user_id' => $user->id,
|
||||||
]))->save();
|
]))->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,9 +249,6 @@ class NewsControllerTest extends ControllerTest
|
||||||
{
|
{
|
||||||
$this->request = $this->request->withAttribute('comment_id', 2)->withParsedBody(['delete' => '1']);
|
$this->request = $this->request->withAttribute('comment_id', 2)->withParsedBody(['delete' => '1']);
|
||||||
|
|
||||||
$this->addUser(1);
|
|
||||||
$this->addUser(2);
|
|
||||||
|
|
||||||
/** @var NewsController $controller */
|
/** @var NewsController $controller */
|
||||||
$controller = $this->app->get(NewsController::class);
|
$controller = $this->app->get(NewsController::class);
|
||||||
$controller->setValidator($this->app->get(Validator::class));
|
$controller->setValidator($this->app->get(Validator::class));
|
||||||
|
@ -268,8 +265,6 @@ class NewsControllerTest extends ControllerTest
|
||||||
$this->request = $this->request->withAttribute('comment_id', 1)->withParsedBody(['delete' => '1']);
|
$this->request = $this->request->withAttribute('comment_id', 1)->withParsedBody(['delete' => '1']);
|
||||||
$this->setExpects($this->response, 'redirectTo', ['http://localhost/news/1'], $this->response);
|
$this->setExpects($this->response, 'redirectTo', ['http://localhost/news/1'], $this->response);
|
||||||
|
|
||||||
$this->addUser(1);
|
|
||||||
|
|
||||||
/** @var NewsController $controller */
|
/** @var NewsController $controller */
|
||||||
$controller = $this->app->get(NewsController::class);
|
$controller = $this->app->get(NewsController::class);
|
||||||
$controller->setValidator($this->app->get(Validator::class));
|
$controller->setValidator($this->app->get(Validator::class));
|
||||||
|
@ -293,6 +288,9 @@ class NewsControllerTest extends ControllerTest
|
||||||
$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->addUser(1);
|
||||||
|
$this->addUser(2);
|
||||||
|
|
||||||
foreach ($this->data as $news) {
|
foreach ($this->data as $news) {
|
||||||
(new News($news))->save();
|
(new News($news))->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ trait HasDatabase
|
||||||
protected function initDatabase(): void
|
protected function initDatabase(): void
|
||||||
{
|
{
|
||||||
$dbManager = new CapsuleManager();
|
$dbManager = new CapsuleManager();
|
||||||
$dbManager->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
|
$dbManager->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'foreign_key_constraints' => true]);
|
||||||
$dbManager->bootEloquent();
|
$dbManager->bootEloquent();
|
||||||
|
|
||||||
$connection = $dbManager->getConnection();
|
$connection = $dbManager->getConnection();
|
||||||
|
|
|
@ -336,8 +336,9 @@ class UserTest extends ModelTest
|
||||||
*/
|
*/
|
||||||
public function testNewsComments(): void
|
public function testNewsComments(): void
|
||||||
{
|
{
|
||||||
|
News::factory()->create();
|
||||||
($user = new User($this->data))->save();
|
($user = new User($this->data))->save();
|
||||||
$newsComment = NewsComment::create(['news_id' => 0, 'text' => 'test comment', 'user_id' => $user->id]);
|
$newsComment = NewsComment::create(['news_id' => 1, 'text' => 'test comment', 'user_id' => $user->id]);
|
||||||
$comments = $user->newsComments;
|
$comments = $user->newsComments;
|
||||||
|
|
||||||
$this->assertCount(1, $comments);
|
$this->assertCount(1, $comments);
|
||||||
|
|
Loading…
Reference in New Issue