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
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4
13 changed files with 38 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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