Update tests so repositories are not called. Saves on DB calls, speeds up tests.

This commit is contained in:
James Cole
2018-09-04 16:47:01 +02:00
parent ca04113aa7
commit d43fa3790d
23 changed files with 376 additions and 65 deletions

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\IsAdmin;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Mockery;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
@@ -54,6 +56,8 @@ class IsAdminTest extends TestCase
*/
public function testMiddleware(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-admin');
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
@@ -65,6 +69,8 @@ class IsAdminTest extends TestCase
*/
public function testMiddlewareAjax(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-admin', $server);
@@ -76,6 +82,9 @@ class IsAdminTest extends TestCase
*/
public function testMiddlewareNotOwner(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
$this->withoutExceptionHandling();
$this->be($this->emptyUser());
$response = $this->get('/_test/is-admin');
@@ -88,6 +97,9 @@ class IsAdminTest extends TestCase
*/
public function testMiddlewareOwner(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-admin');