Automatically set up Mockery for unit tests

- Use provided PhpUnit listener to enforce verification of expectations.
- Include Mockery's trait to auto-close Mockery after each test.
This commit is contained in:
Franz Liedke 2019-11-21 00:51:11 +01:00
parent 879b801600
commit 4f1adba387
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4
7 changed files with 29 additions and 6 deletions

View File

@ -19,4 +19,7 @@
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
</listeners>
</phpunit>

View File

@ -12,11 +12,11 @@
namespace Flarum\Tests\unit\Foundation\ErrorHandling\ExceptionHandler;
use Flarum\Foundation\ErrorHandling\ExceptionHandler\IlluminateValidationExceptionHandler;
use Flarum\Tests\unit\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
{

View File

@ -13,7 +13,7 @@ namespace Flarum\Tests\unit\Foundation\ErrorHandling\ExceptionHandler;
use Flarum\Foundation\ErrorHandling\ExceptionHandler\ValidationExceptionHandler;
use Flarum\Foundation\ValidationException;
use PHPUnit\Framework\TestCase;
use Flarum\Tests\unit\TestCase;
class ValidationExceptionHandlerTest extends TestCase
{

View File

@ -9,10 +9,10 @@
* file that was distributed with this source code.
*/
namespace Flarum\Tests\unit;
namespace Flarum\Tests\unit\Install;
use Flarum\Install\BaseUrl;
use PHPUnit\Framework\TestCase;
use Flarum\Tests\unit\TestCase;
use Zend\Diactoros\Uri;
class BaseUrlTest extends TestCase

View File

@ -12,9 +12,9 @@
namespace Flarum\Tests\unit\Settings;
use Flarum\Settings\DatabaseSettingsRepository;
use Flarum\Tests\unit\TestCase;
use Illuminate\Database\ConnectionInterface;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class DatabaseSettingsRepositoryTest extends TestCase
{

View File

@ -13,8 +13,8 @@ namespace Flarum\Tests\unit\Settings;
use Flarum\Settings\MemoryCacheSettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Tests\unit\TestCase;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class MemoryCacheSettingsRepositoryTest extends TestCase
{

20
tests/unit/TestCase.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Tests\unit;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
// Ensure Mockery is always torn down automatically after each test.
use MockeryPHPUnitIntegration;
}