1
0
mirror of https://github.com/flarum/core.git synced 2025-07-25 10:41:24 +02:00

Extract pure unit tests so that they can run fast

- Move to separate directory (base for a separate test suite)
- Inherit directly from PhpUnit
- Configure test suite with dedicated XML file
This commit is contained in:
Franz Liedke
2019-01-01 21:11:29 +01:00
parent 6484dc4982
commit ba16ebe61f
13 changed files with 38 additions and 42 deletions

View File

@@ -11,12 +11,8 @@
syntaxCheck="false"> syntaxCheck="false">
<testsuites> <testsuites>
<testsuite name="installation"> <testsuite name="Flarum Unit Tests">
<directory suffix="Test.php">./tests/Install</directory> <directory suffix="Test.php">./unit</directory>
</testsuite>
<testsuite name="all">
<directory suffix="Test.php">./tests</directory>
<exclude>./tests/Install</exclude>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\FloodingExceptionHandler; use Flarum\Api\ExceptionHandler\FloodingExceptionHandler;
use Flarum\Post\Exception\FloodingException; use Flarum\Post\Exception\FloodingException;
use Flarum\Tests\Test\TestCase; use PHPUnit\Framework\TestCase;
class FloodingExceptionHandlerTest extends TestCase class FloodingExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new FloodingExceptionHandler; $this->handler = new FloodingExceptionHandler;
} }

View File

@@ -9,21 +9,21 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler; use Flarum\Api\ExceptionHandler\IlluminateValidationExceptionHandler;
use Flarum\Tests\Test\TestCase;
use Illuminate\Translation\ArrayLoader; use Illuminate\Translation\ArrayLoader;
use Illuminate\Translation\Translator; use Illuminate\Translation\Translator;
use Illuminate\Validation\Factory; use Illuminate\Validation\Factory;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use PHPUnit\Framework\TestCase;
class IlluminateValidationExceptionHandlerTest extends TestCase class IlluminateValidationExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new IlluminateValidationExceptionHandler; $this->handler = new IlluminateValidationExceptionHandler;
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\Exception\InvalidAccessTokenException; use Flarum\Api\Exception\InvalidAccessTokenException;
use Flarum\Api\ExceptionHandler\InvalidAccessTokenExceptionHandler; use Flarum\Api\ExceptionHandler\InvalidAccessTokenExceptionHandler;
use Flarum\Tests\Test\TestCase; use PHPUnit\Framework\TestCase;
class InvalidAccessTokenExceptionHandlerTest extends TestCase class InvalidAccessTokenExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new InvalidAccessTokenExceptionHandler; $this->handler = new InvalidAccessTokenExceptionHandler;
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler; use Flarum\Api\ExceptionHandler\InvalidConfirmationTokenExceptionHandler;
use Flarum\Tests\Test\TestCase;
use Flarum\User\Exception\InvalidConfirmationTokenException; use Flarum\User\Exception\InvalidConfirmationTokenException;
use PHPUnit\Framework\TestCase;
class InvalidConfirmationTokenExceptionHandlerTest extends TestCase class InvalidConfirmationTokenExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new InvalidConfirmationTokenExceptionHandler; $this->handler = new InvalidConfirmationTokenExceptionHandler;
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\MethodNotAllowedExceptionHandler; use Flarum\Api\ExceptionHandler\MethodNotAllowedExceptionHandler;
use Flarum\Http\Exception\MethodNotAllowedException; use Flarum\Http\Exception\MethodNotAllowedException;
use Flarum\Tests\Test\TestCase; use PHPUnit\Framework\TestCase;
class MethodNotAllowedExceptionHandlerTest extends TestCase class MethodNotAllowedExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new MethodNotAllowedExceptionHandler(); $this->handler = new MethodNotAllowedExceptionHandler();
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\ModelNotFoundExceptionHandler; use Flarum\Api\ExceptionHandler\ModelNotFoundExceptionHandler;
use Flarum\Tests\Test\TestCase;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use PHPUnit\Framework\TestCase;
class ModelNotFoundExceptionHandlerTest extends TestCase class ModelNotFoundExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new ModelNotFoundExceptionHandler; $this->handler = new ModelNotFoundExceptionHandler;
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler; use Flarum\Api\ExceptionHandler\PermissionDeniedExceptionHandler;
use Flarum\Tests\Test\TestCase;
use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\Exception\PermissionDeniedException;
use PHPUnit\Framework\TestCase;
class PermissionDeniedExceptionHandlerTest extends TestCase class PermissionDeniedExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new PermissionDeniedExceptionHandler; $this->handler = new PermissionDeniedExceptionHandler;
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\RouteNotFoundExceptionHandler; use Flarum\Api\ExceptionHandler\RouteNotFoundExceptionHandler;
use Flarum\Http\Exception\RouteNotFoundException; use Flarum\Http\Exception\RouteNotFoundException;
use Flarum\Tests\Test\TestCase; use PHPUnit\Framework\TestCase;
class RouteNotFoundExceptionHandlerTest extends TestCase class RouteNotFoundExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new RouteNotFoundExceptionHandler(); $this->handler = new RouteNotFoundExceptionHandler();
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\TokenMismatchExceptionHandler; use Flarum\Api\ExceptionHandler\TokenMismatchExceptionHandler;
use Flarum\Http\Exception\TokenMismatchException; use Flarum\Http\Exception\TokenMismatchException;
use Flarum\Tests\Test\TestCase; use PHPUnit\Framework\TestCase;
class TokenMismatchExceptionHandlerTest extends TestCase class TokenMismatchExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new TokenMismatchExceptionHandler; $this->handler = new TokenMismatchExceptionHandler;
} }

View File

@@ -9,18 +9,18 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Api\ExceptionHandler; namespace Flarum\Tests\unit\Api\ExceptionHandler;
use Exception; use Exception;
use Flarum\Api\ExceptionHandler\ValidationExceptionHandler; use Flarum\Api\ExceptionHandler\ValidationExceptionHandler;
use Flarum\Foundation\ValidationException; use Flarum\Foundation\ValidationException;
use Flarum\Tests\Test\TestCase; use PHPUnit\Framework\TestCase;
class ValidationExceptionHandlerTest extends TestCase class ValidationExceptionHandlerTest extends TestCase
{ {
private $handler; private $handler;
public function init() public function setUp()
{ {
$this->handler = new ValidationExceptionHandler; $this->handler = new ValidationExceptionHandler;
} }

View File

@@ -9,19 +9,19 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Settings; namespace Flarum\Tests\unit\Settings;
use Flarum\Settings\DatabaseSettingsRepository; use Flarum\Settings\DatabaseSettingsRepository;
use Flarum\Tests\Test\TestCase;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Mockery as m; use Mockery as m;
use PHPUnit\Framework\TestCase;
class DatabaseSettingsRepositoryTest extends TestCase class DatabaseSettingsRepositoryTest extends TestCase
{ {
private $connection; private $connection;
private $repository; private $repository;
public function init() public function setUp()
{ {
$this->connection = m::mock(ConnectionInterface::class); $this->connection = m::mock(ConnectionInterface::class);
$this->repository = new DatabaseSettingsRepository($this->connection); $this->repository = new DatabaseSettingsRepository($this->connection);

View File

@@ -9,19 +9,19 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Flarum\Tests\Settings; namespace Flarum\Tests\unit\Settings;
use Flarum\Settings\MemoryCacheSettingsRepository; use Flarum\Settings\MemoryCacheSettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Tests\Test\TestCase;
use Mockery as m; use Mockery as m;
use PHPUnit\Framework\TestCase;
class MemoryCacheSettingsRepositoryTest extends TestCase class MemoryCacheSettingsRepositoryTest extends TestCase
{ {
private $baseRepository; private $baseRepository;
private $repository; private $repository;
public function init() public function setUp()
{ {
$this->baseRepository = m::mock(SettingsRepositoryInterface::class); $this->baseRepository = m::mock(SettingsRepositoryInterface::class);
$this->repository = new MemoryCacheSettingsRepository($this->baseRepository); $this->repository = new MemoryCacheSettingsRepository($this->baseRepository);