From c5e38a5b1fed5cd29754ec73e6dc2bd9b5710a37 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 21 Nov 2019 00:51:11 +0100 Subject: [PATCH] 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. --- tests/phpunit.unit.xml | 3 +++ ...luminateValidationExceptionHandlerTest.php | 2 +- .../ValidationExceptionHandlerTest.php | 2 +- tests/unit/Install/BaseUrlTest.php | 4 ++-- .../DatabaseSettingsRepositoryTest.php | 2 +- .../MemoryCacheSettingsRepositoryTest.php | 2 +- tests/unit/TestCase.php | 20 +++++++++++++++++++ 7 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 tests/unit/TestCase.php diff --git a/tests/phpunit.unit.xml b/tests/phpunit.unit.xml index 770adad2b..eb4e32c11 100644 --- a/tests/phpunit.unit.xml +++ b/tests/phpunit.unit.xml @@ -19,4 +19,7 @@ ./src/ + + + diff --git a/tests/unit/Foundation/ErrorHandling/ExceptionHandler/IlluminateValidationExceptionHandlerTest.php b/tests/unit/Foundation/ErrorHandling/ExceptionHandler/IlluminateValidationExceptionHandlerTest.php index 028fa5e33..d06d289ef 100644 --- a/tests/unit/Foundation/ErrorHandling/ExceptionHandler/IlluminateValidationExceptionHandlerTest.php +++ b/tests/unit/Foundation/ErrorHandling/ExceptionHandler/IlluminateValidationExceptionHandlerTest.php @@ -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 { diff --git a/tests/unit/Foundation/ErrorHandling/ExceptionHandler/ValidationExceptionHandlerTest.php b/tests/unit/Foundation/ErrorHandling/ExceptionHandler/ValidationExceptionHandlerTest.php index 32062249d..d0179f05d 100644 --- a/tests/unit/Foundation/ErrorHandling/ExceptionHandler/ValidationExceptionHandlerTest.php +++ b/tests/unit/Foundation/ErrorHandling/ExceptionHandler/ValidationExceptionHandlerTest.php @@ -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 { diff --git a/tests/unit/Install/BaseUrlTest.php b/tests/unit/Install/BaseUrlTest.php index c4f1ca58d..b75543b7a 100644 --- a/tests/unit/Install/BaseUrlTest.php +++ b/tests/unit/Install/BaseUrlTest.php @@ -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 diff --git a/tests/unit/Settings/DatabaseSettingsRepositoryTest.php b/tests/unit/Settings/DatabaseSettingsRepositoryTest.php index b5bbb8fbd..2fb34c938 100644 --- a/tests/unit/Settings/DatabaseSettingsRepositoryTest.php +++ b/tests/unit/Settings/DatabaseSettingsRepositoryTest.php @@ -10,9 +10,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 { diff --git a/tests/unit/Settings/MemoryCacheSettingsRepositoryTest.php b/tests/unit/Settings/MemoryCacheSettingsRepositoryTest.php index 9856223dc..761e60558 100644 --- a/tests/unit/Settings/MemoryCacheSettingsRepositoryTest.php +++ b/tests/unit/Settings/MemoryCacheSettingsRepositoryTest.php @@ -11,8 +11,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 { diff --git a/tests/unit/TestCase.php b/tests/unit/TestCase.php new file mode 100644 index 000000000..8c87018b6 --- /dev/null +++ b/tests/unit/TestCase.php @@ -0,0 +1,20 @@ + + * + * 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; +}