Tests: TestCase: Initialize $this->app on every run

main
Igor Scheller 5 years ago
parent 1b3e3b1d65
commit e124b41977

@ -12,9 +12,9 @@ use Engelsystem\Http\Validation\Validator;
use Engelsystem\Models\User\Settings;
use Engelsystem\Models\User\User;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\TestCase;
use Illuminate\Support\Collection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;

@ -2,7 +2,6 @@
namespace Engelsystem\Test\Unit;
use Engelsystem\Application;
use Engelsystem\Database\Database;
use Engelsystem\Database\Migration\Migrate;
use Engelsystem\Database\Migration\MigrationServiceProvider;
@ -27,12 +26,11 @@ trait HasDatabase
$connection->getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->database = new Database($connection);
$app = new Application();
$app->instance(Database::class, $this->database);
$app->register(MigrationServiceProvider::class);
$this->app->instance(Database::class, $this->database);
$this->app->register(MigrationServiceProvider::class);
/** @var Migrate $migration */
$migration = $app->get('db.migration');
$migration = $this->app->get('db.migration');
$migration->initMigration();
$this->database

@ -4,7 +4,7 @@ namespace Engelsystem\Test\Unit\Http\SessionHandlers;
use Engelsystem\Http\SessionHandlers\DatabaseHandler;
use Engelsystem\Test\Unit\HasDatabase;
use PHPUnit\Framework\TestCase;
use Engelsystem\Test\Unit\TestCase;
class DatabaseHandlerTest extends TestCase
{
@ -90,6 +90,7 @@ class DatabaseHandlerTest extends TestCase
*/
protected function setUp(): void
{
parent::setUp();
$this->initDatabase();
}
}

@ -5,7 +5,7 @@ namespace Engelsystem\Test\Unit\Models;
use Carbon\Carbon;
use Engelsystem\Models\EventConfig;
use Engelsystem\Test\Unit\HasDatabase;
use PHPUnit\Framework\TestCase;
use Engelsystem\Test\Unit\TestCase;
class EventConfigTest extends TestCase
{
@ -102,7 +102,8 @@ class EventConfigTest extends TestCase
*/
protected function getEventConfig()
{
return new class extends EventConfig {
return new class extends EventConfig
{
/**
* @param string $value
* @param string $type
@ -122,6 +123,7 @@ class EventConfigTest extends TestCase
*/
protected function setUp(): void
{
parent::setUp();
$this->initDatabase();
}
}

@ -4,7 +4,7 @@ namespace Engelsystem\Test\Unit\Models;
use Engelsystem\Models\LogEntry;
use Engelsystem\Test\Unit\HasDatabase;
use PHPUnit\Framework\TestCase;
use Engelsystem\Test\Unit\TestCase;
use Psr\Log\LogLevel;
class LogEntryTest extends TestCase
@ -38,6 +38,7 @@ class LogEntryTest extends TestCase
*/
protected function setUp(): void
{
parent::setUp();
$this->initDatabase();
}
}

@ -5,8 +5,8 @@ namespace Engelsystem\Test\Unit\Models;
use Engelsystem\Models\User\HasUserModel;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\Models\User\Stub\HasUserModelImplementation;
use Engelsystem\Test\Unit\TestCase;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use PHPUnit\Framework\TestCase;
class HasUserModelTest extends TestCase
{
@ -28,6 +28,7 @@ class HasUserModelTest extends TestCase
*/
protected function setUp(): void
{
parent::setUp();
$this->initDatabase();
}
}

@ -10,7 +10,7 @@ use Engelsystem\Models\User\Settings;
use Engelsystem\Models\User\State;
use Engelsystem\Models\User\User;
use Engelsystem\Test\Unit\HasDatabase;
use PHPUnit\Framework\TestCase;
use Engelsystem\Test\Unit\TestCase;
class UserTest extends TestCase
{
@ -95,6 +95,7 @@ class UserTest extends TestCase
*/
protected function setUp(): void
{
parent::setUp();
$this->initDatabase();
}
}

@ -2,12 +2,16 @@
namespace Engelsystem\Test\Unit;
use Engelsystem\Application;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
abstract class TestCase extends PHPUnitTestCase
{
/** @var Application */
protected $app;
/**
* @param MockObject $object
* @param string $method
@ -34,4 +38,12 @@ abstract class TestCase extends PHPUnitTestCase
$invocation->willReturn($return);
}
}
/**
* Called before each test run
*/
protected function setUp(): void
{
$this->app = new Application(__DIR__ . '/../../');
}
}

Loading…
Cancel
Save