Skip to content

Commit

Permalink
Automatically set up Mockery for unit tests
Browse files Browse the repository at this point in the history
- Use provided PhpUnit listener to enforce verification of expectations.
- Include Mockery's trait to auto-close Mockery after each test.
  • Loading branch information
franzliedke committed Nov 20, 2019
1 parent 879b801 commit 4f1adba
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions tests/phpunit.unit.xml
Expand Up @@ -19,4 +19,7 @@
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
</listeners>
</phpunit>
Expand Up @@ -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
{
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Flarum\Foundation\ErrorHandling\ExceptionHandler\ValidationExceptionHandler;
use Flarum\Foundation\ValidationException;
use PHPUnit\Framework\TestCase;
use Flarum\Tests\unit\TestCase;

class ValidationExceptionHandlerTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Install/BaseUrlTest.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Settings/DatabaseSettingsRepositoryTest.php
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Settings/MemoryCacheSettingsRepositoryTest.php
Expand Up @@ -13,8 +13,8 @@

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
{
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/TestCase.php
@@ -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;
}

0 comments on commit 4f1adba

Please sign in to comment.