From f99e0a229f1b1cf49005ad6083bfa8d894fc81c3 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 11 May 2020 19:57:25 +0200 Subject: [PATCH] Tests: Added ModelTest class --- tests/Unit/Models/EventConfigTest.php | 15 +------------ tests/Unit/Models/LogEntryTest.php | 15 +------------ tests/Unit/Models/MessageTest.php | 7 +------ tests/Unit/Models/ModelTest.php | 21 +++++++++++++++++++ tests/Unit/Models/NewsCommentsTest.php | 7 +------ tests/Unit/Models/NewsTest.php | 7 +------ tests/Unit/Models/QuestionTest.php | 7 +------ .../Unit/Models/Shifts/ScheduleShiftTest.php | 16 ++------------ tests/Unit/Models/Shifts/ScheduleTest.php | 16 ++------------ tests/Unit/Models/User/UserTest.php | 15 ++----------- tests/Unit/Models/User/UsesUserModelTest.php | 16 ++------------ 11 files changed, 35 insertions(+), 107 deletions(-) create mode 100644 tests/Unit/Models/ModelTest.php diff --git a/tests/Unit/Models/EventConfigTest.php b/tests/Unit/Models/EventConfigTest.php index 4ab2fc75..dbe40e1f 100644 --- a/tests/Unit/Models/EventConfigTest.php +++ b/tests/Unit/Models/EventConfigTest.php @@ -4,13 +4,9 @@ namespace Engelsystem\Test\Unit\Models; use Carbon\Carbon; use Engelsystem\Models\EventConfig; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; -class EventConfigTest extends TestCase +class EventConfigTest extends ModelTest { - use HasDatabase; - /** * @covers \Engelsystem\Models\EventConfig::setValueAttribute */ @@ -117,13 +113,4 @@ class EventConfigTest extends TestCase } }; } - - /** - * Prepare test - */ - protected function setUp(): void - { - parent::setUp(); - $this->initDatabase(); - } } diff --git a/tests/Unit/Models/LogEntryTest.php b/tests/Unit/Models/LogEntryTest.php index d4cef2e0..35db9435 100644 --- a/tests/Unit/Models/LogEntryTest.php +++ b/tests/Unit/Models/LogEntryTest.php @@ -3,14 +3,10 @@ namespace Engelsystem\Test\Unit\Models; use Engelsystem\Models\LogEntry; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; use Psr\Log\LogLevel; -class LogEntryTest extends TestCase +class LogEntryTest extends ModelTest { - use HasDatabase; - /** * @covers \Engelsystem\Models\LogEntry::filter */ @@ -34,13 +30,4 @@ class LogEntryTest extends TestCase $this->assertCount(3, LogEntry::filter(LogLevel::INFO)); $this->assertCount(1, LogEntry::filter('Oops')); } - - /** - * Prepare test - */ - protected function setUp(): void - { - parent::setUp(); - $this->initDatabase(); - } } diff --git a/tests/Unit/Models/MessageTest.php b/tests/Unit/Models/MessageTest.php index 7fb3e028..13975771 100644 --- a/tests/Unit/Models/MessageTest.php +++ b/tests/Unit/Models/MessageTest.php @@ -6,16 +6,12 @@ namespace Engelsystem\Test\Unit\Models; use Engelsystem\Models\Message; use Engelsystem\Models\User\User; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; /** * This class provides tests covering the Message model and its relations. */ -class MessageTest extends TestCase +class MessageTest extends ModelTest { - use HasDatabase; - /** @var User */ private $user1; @@ -37,7 +33,6 @@ class MessageTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->initDatabase(); $this->user1 = User::create([ 'name' => 'user1', diff --git a/tests/Unit/Models/ModelTest.php b/tests/Unit/Models/ModelTest.php new file mode 100644 index 00000000..680e47ec --- /dev/null +++ b/tests/Unit/Models/ModelTest.php @@ -0,0 +1,21 @@ +initDatabase(); + } +} diff --git a/tests/Unit/Models/NewsCommentsTest.php b/tests/Unit/Models/NewsCommentsTest.php index 1749e988..46d05bf8 100644 --- a/tests/Unit/Models/NewsCommentsTest.php +++ b/tests/Unit/Models/NewsCommentsTest.php @@ -7,16 +7,12 @@ namespace Engelsystem\Test\Unit\Models; use Engelsystem\Models\News; use Engelsystem\Models\NewsComment; use Engelsystem\Models\User\User; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; /** * This class provides tests for the NewsComments model. */ -class NewsCommentsTest extends TestCase +class NewsCommentsTest extends ModelTest { - use HasDatabase; - /** @var User */ private $user; @@ -32,7 +28,6 @@ class NewsCommentsTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->initDatabase(); $this->user = User::create([ 'name' => 'lorem', diff --git a/tests/Unit/Models/NewsTest.php b/tests/Unit/Models/NewsTest.php index ca933686..40177560 100644 --- a/tests/Unit/Models/NewsTest.php +++ b/tests/Unit/Models/NewsTest.php @@ -6,16 +6,12 @@ namespace Engelsystem\Test\Unit\Models; use Engelsystem\Models\News; use Engelsystem\Models\User\User; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; /** * This class provides tests for the News model. */ -class NewsTest extends TestCase +class NewsTest extends ModelTest { - use HasDatabase; - /** @var array */ private $newsData; @@ -28,7 +24,6 @@ class NewsTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->initDatabase(); $this->user = (new User())->create([ 'name' => 'lorem', diff --git a/tests/Unit/Models/QuestionTest.php b/tests/Unit/Models/QuestionTest.php index 2aeb5cd8..0965c32e 100644 --- a/tests/Unit/Models/QuestionTest.php +++ b/tests/Unit/Models/QuestionTest.php @@ -6,14 +6,10 @@ namespace Engelsystem\Test\Unit\Models; use Engelsystem\Models\Question; use Engelsystem\Models\User\User; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; use Illuminate\Support\Str; -class QuestionTest extends TestCase +class QuestionTest extends ModelTest { - use HasDatabase; - /** * @var User */ @@ -30,7 +26,6 @@ class QuestionTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->initDatabase(); $this->user1 = User::create( [ diff --git a/tests/Unit/Models/Shifts/ScheduleShiftTest.php b/tests/Unit/Models/Shifts/ScheduleShiftTest.php index b615f90d..e8626993 100644 --- a/tests/Unit/Models/Shifts/ScheduleShiftTest.php +++ b/tests/Unit/Models/Shifts/ScheduleShiftTest.php @@ -4,14 +4,11 @@ namespace Engelsystem\Test\Unit\Models\Shifts; use Engelsystem\Models\Shifts\Schedule; use Engelsystem\Models\Shifts\ScheduleShift; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; +use Engelsystem\Test\Unit\Models\ModelTest; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class ScheduleShiftTest extends TestCase +class ScheduleShiftTest extends ModelTest { - use HasDatabase; - /** * @covers \Engelsystem\Models\Shifts\ScheduleShift::schedule */ @@ -29,13 +26,4 @@ class ScheduleShiftTest extends TestCase $this->assertInstanceOf(BelongsTo::class, $scheduleShift->schedule()); $this->assertEquals($schedule->id, $scheduleShift->schedule->id); } - - /** - * Prepare test - */ - protected function setUp(): void - { - parent::setUp(); - $this->initDatabase(); - } } diff --git a/tests/Unit/Models/Shifts/ScheduleTest.php b/tests/Unit/Models/Shifts/ScheduleTest.php index 34988afd..22ba6083 100644 --- a/tests/Unit/Models/Shifts/ScheduleTest.php +++ b/tests/Unit/Models/Shifts/ScheduleTest.php @@ -4,13 +4,10 @@ namespace Engelsystem\Test\Unit\Models\Shifts; use Engelsystem\Models\Shifts\Schedule; use Engelsystem\Models\Shifts\ScheduleShift; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; +use Engelsystem\Test\Unit\Models\ModelTest; -class ScheduleTest extends TestCase +class ScheduleTest extends ModelTest { - use HasDatabase; - /** * @covers \Engelsystem\Models\Shifts\Schedule::scheduleShifts */ @@ -25,13 +22,4 @@ class ScheduleTest extends TestCase $this->assertCount(3, $schedule->scheduleShifts); } - - /** - * Prepare test - */ - protected function setUp(): void - { - parent::setUp(); - $this->initDatabase(); - } } diff --git a/tests/Unit/Models/User/UserTest.php b/tests/Unit/Models/User/UserTest.php index 18a0afb5..aa5d0369 100644 --- a/tests/Unit/Models/User/UserTest.php +++ b/tests/Unit/Models/User/UserTest.php @@ -13,15 +13,13 @@ use Engelsystem\Models\User\PersonalData; use Engelsystem\Models\User\Settings; use Engelsystem\Models\User\State; use Engelsystem\Models\User\User; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; +use Engelsystem\Test\Unit\Models\ModelTest; use Exception; use Illuminate\Support\Str; -class UserTest extends TestCase +class UserTest extends ModelTest { use ArraySubsetAsserts; - use HasDatabase; /** @var string[] */ protected $data = [ @@ -207,13 +205,4 @@ class UserTest extends TestCase $this->assertContains($question1->id, $answers); $this->assertContains($question2->id, $answers); } - - /** - * Prepare test - */ - protected function setUp(): void - { - parent::setUp(); - $this->initDatabase(); - } } diff --git a/tests/Unit/Models/User/UsesUserModelTest.php b/tests/Unit/Models/User/UsesUserModelTest.php index 24d92b36..028c8b30 100644 --- a/tests/Unit/Models/User/UsesUserModelTest.php +++ b/tests/Unit/Models/User/UsesUserModelTest.php @@ -4,14 +4,11 @@ namespace Engelsystem\Test\Unit\Models\User; use Engelsystem\Models\BaseModel; use Engelsystem\Models\User\UsesUserModel; -use Engelsystem\Test\Unit\HasDatabase; -use Engelsystem\Test\Unit\TestCase; +use Engelsystem\Test\Unit\Models\ModelTest; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class UsesUserModelTest extends TestCase +class UsesUserModelTest extends ModelTest { - use HasDatabase; - /** * @covers \Engelsystem\Models\User\UsesUserModel::user */ @@ -25,13 +22,4 @@ class UsesUserModelTest extends TestCase $this->assertInstanceOf(BelongsTo::class, $model->user()); } - - /** - * Prepare test - */ - protected function setUp(): void - { - parent::setUp(); - $this->initDatabase(); - } }