diff --git a/tests/Unit/Controllers/Admin/FaqControllerTest.php b/tests/Unit/Controllers/Admin/FaqControllerTest.php
index 65366dc4..ea99b85d 100644
--- a/tests/Unit/Controllers/Admin/FaqControllerTest.php
+++ b/tests/Unit/Controllers/Admin/FaqControllerTest.php
@@ -2,44 +2,22 @@
namespace Engelsystem\Test\Unit\Controllers\Admin;
-use Engelsystem\Config\Config;
use Engelsystem\Controllers\Admin\FaqController;
-use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Exceptions\ValidationException;
-use Engelsystem\Http\Request;
-use Engelsystem\Http\Response;
-use Engelsystem\Http\UrlGenerator;
-use Engelsystem\Http\UrlGeneratorInterface;
use Engelsystem\Http\Validation\Validator;
use Engelsystem\Models\Faq;
-use Engelsystem\Test\Unit\HasDatabase;
-use Engelsystem\Test\Unit\TestCase;
+use Engelsystem\Test\Unit\Controllers\ControllerTest;
use Illuminate\Support\Collection;
-use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Log\LoggerInterface;
-use Psr\Log\Test\TestLogger;
use Symfony\Component\HttpFoundation\Session\Session;
-use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
-class FaqControllerTest extends TestCase
+class FaqControllerTest extends ControllerTest
{
- use HasDatabase;
-
/** @var array */
protected $data = [
'question' => 'Foo?',
'text' => 'Bar!',
];
- /** @var TestLogger */
- protected $log;
-
- /** @var Response|MockObject */
- protected $response;
-
- /** @var Request */
- protected $request;
-
/**
* @covers \Engelsystem\Controllers\Admin\FaqController::__construct
* @covers \Engelsystem\Controllers\Admin\FaqController::edit
@@ -185,22 +163,6 @@ class FaqControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
- $this->initDatabase();
-
- $this->request = Request::create('http://localhost');
- $this->app->instance('request', $this->request);
-
- $this->response = $this->createMock(Response::class);
- $this->app->instance(Response::class, $this->response);
-
- $this->log = new TestLogger();
- $this->app->instance(LoggerInterface::class, $this->log);
-
- $this->app->instance('session', new Session(new MockArraySessionStorage()));
-
- $this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class);
-
- $this->app->instance('config', new Config());
(new Faq([
'question' => 'Lorem',
diff --git a/tests/Unit/Controllers/Admin/NewsControllerTest.php b/tests/Unit/Controllers/Admin/NewsControllerTest.php
index 04012b0d..7edee5ae 100644
--- a/tests/Unit/Controllers/Admin/NewsControllerTest.php
+++ b/tests/Unit/Controllers/Admin/NewsControllerTest.php
@@ -2,31 +2,19 @@
namespace Engelsystem\Test\Unit\Controllers\Admin;
-use Engelsystem\Config\Config;
use Engelsystem\Controllers\Admin\NewsController;
use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Exceptions\ValidationException;
-use Engelsystem\Http\Request;
-use Engelsystem\Http\Response;
-use Engelsystem\Http\UrlGenerator;
-use Engelsystem\Http\UrlGeneratorInterface;
use Engelsystem\Http\Validation\Validator;
use Engelsystem\Models\News;
use Engelsystem\Models\User\User;
-use Engelsystem\Test\Unit\HasDatabase;
-use Engelsystem\Test\Unit\TestCase;
+use Engelsystem\Test\Unit\Controllers\ControllerTest;
use Illuminate\Support\Collection;
use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Http\Message\ServerRequestInterface;
-use Psr\Log\LoggerInterface;
-use Psr\Log\Test\TestLogger;
use Symfony\Component\HttpFoundation\Session\Session;
-use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
-class NewsControllerTest extends TestCase
+class NewsControllerTest extends ControllerTest
{
- use HasDatabase;
-
/** @var Authenticator|MockObject */
protected $auth;
@@ -40,15 +28,6 @@ class NewsControllerTest extends TestCase
]
];
- /** @var TestLogger */
- protected $log;
-
- /** @var Response|MockObject */
- protected $response;
-
- /** @var Request */
- protected $request;
-
/**
* @covers \Engelsystem\Controllers\Admin\NewsController::edit
* @covers \Engelsystem\Controllers\Admin\NewsController::showEdit
@@ -295,42 +274,6 @@ class NewsControllerTest extends TestCase
$this->assertEquals('news.delete.success', $messages[0]);
}
- /**
- * Setup environment
- */
- public function setUp(): void
- {
- parent::setUp();
- $this->initDatabase();
-
- $this->request = Request::create('http://localhost');
- $this->app->instance('request', $this->request);
- $this->app->instance(Request::class, $this->request);
- $this->app->instance(ServerRequestInterface::class, $this->request);
-
- $this->response = $this->createMock(Response::class);
- $this->app->instance(Response::class, $this->response);
-
- $this->log = new TestLogger();
- $this->app->instance(LoggerInterface::class, $this->log);
-
- $this->app->instance('session', new Session(new MockArraySessionStorage()));
-
- $this->auth = $this->createMock(Authenticator::class);
- $this->app->instance(Authenticator::class, $this->auth);
-
- $this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class);
-
- $this->app->instance('config', new Config());
-
- (new News([
- 'title' => 'Foo',
- 'text' => 'foo',
- 'is_meeting' => false,
- 'user_id' => 1,
- ]))->save();
- }
-
/**
* Creates a new user
*/
@@ -350,4 +293,22 @@ class NewsControllerTest extends TestCase
->method('user')
->willReturn($user);
}
+
+ /**
+ * Setup environment
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->auth = $this->createMock(Authenticator::class);
+ $this->app->instance(Authenticator::class, $this->auth);
+
+ (new News([
+ 'title' => 'Foo',
+ 'text' => 'foo',
+ 'is_meeting' => false,
+ 'user_id' => 1,
+ ]))->save();
+ }
}
diff --git a/tests/Unit/Controllers/ControllerTest.php b/tests/Unit/Controllers/ControllerTest.php
new file mode 100644
index 00000000..0f107a3e
--- /dev/null
+++ b/tests/Unit/Controllers/ControllerTest.php
@@ -0,0 +1,65 @@
+initDatabase();
+
+ $this->request = Request::create('http://localhost');
+ $this->app->instance('request', $this->request);
+ $this->app->instance(Request::class, $this->request);
+ $this->app->instance(ServerRequestInterface::class, $this->request);
+
+ $this->response = $this->createMock(Response::class);
+ $this->app->instance(Response::class, $this->response);
+
+ $this->log = new TestLogger();
+ $this->app->instance(LoggerInterface::class, $this->log);
+
+ $this->session = new Session(new MockArraySessionStorage());
+ $this->app->instance('session', $this->session);
+
+ $this->app->bind(UrlGeneratorInterface::class, UrlGenerator::class);
+
+ $this->config = new Config();
+ $this->app->instance('config', $this->config);
+ }
+}