mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Update tests so repositories are not called. Saves on DB calls, speeds up tests.
This commit is contained in:
@@ -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');
|
||||
|
Reference in New Issue
Block a user