Update repository base code to be cleaner and make use of PHP 7 features
This commit is contained in:
parent
0ec5a4e08c
commit
60eb60013c
96 changed files with 1048 additions and 1785 deletions
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Commands\User;
|
||||
|
||||
|
@ -60,7 +53,7 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
$user2 = factory(User::class)->make(),
|
||||
]);
|
||||
|
||||
$this->repository->shouldReceive('search')->with($user1->username)->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setSearchTerm')->with($user1->username)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
|
||||
|
||||
|
@ -82,9 +75,9 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
$user1 = factory(User::class)->make(),
|
||||
]);
|
||||
|
||||
$this->repository->shouldReceive('search')->with('noResults')->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn([]);
|
||||
$this->repository->shouldReceive('search')->with($user1->username)->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setSearchTerm')->with('noResults')->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn(collect());
|
||||
$this->repository->shouldReceive('setSearchTerm')->with($user1->username)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
|
||||
|
||||
|
@ -107,7 +100,7 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
$user1 = factory(User::class)->make(),
|
||||
]);
|
||||
|
||||
$this->repository->shouldReceive('search')->with($user1->username)->twice()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setSearchTerm')->with($user1->username)->twice()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->twice()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
|
||||
|
||||
|
@ -130,7 +123,7 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
$user1 = factory(User::class)->make(),
|
||||
]);
|
||||
|
||||
$this->repository->shouldReceive('search')->with($user1->username)->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setSearchTerm')->with($user1->username)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldNotReceive('handle');
|
||||
|
||||
|
@ -149,7 +142,7 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
$user1 = factory(User::class)->make(),
|
||||
]);
|
||||
|
||||
$this->repository->shouldReceive('search')->with($user1->username)->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setSearchTerm')->with($user1->username)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldReceive('handle')->with($user1)->once()->andReturnNull();
|
||||
|
||||
|
@ -169,7 +162,7 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
$user2 = factory(User::class)->make(),
|
||||
]);
|
||||
|
||||
$this->repository->shouldReceive('search')->with($user1->username)->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setSearchTerm')->with($user1->username)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
|
||||
$this->deletionService->shouldNotReceive('handle');
|
||||
|
||||
|
@ -184,8 +177,8 @@ class DeleteUserCommandTest extends CommandTestCase
|
|||
*/
|
||||
public function testNoInteractionWithNoResults()
|
||||
{
|
||||
$this->repository->shouldReceive('search')->with(123456)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn([]);
|
||||
$this->repository->shouldReceive('setSearchTerm')->with(123456)->once()->andReturnSelf()
|
||||
->shouldReceive('all')->withNoArgs()->once()->andReturn(collect());
|
||||
|
||||
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => 123456]);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class DisableTwoFactorCommandTest extends CommandTestCase
|
|||
{
|
||||
$user = factory(User::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'email'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'email'])->once()->andReturnSelf()
|
||||
->shouldReceive('findFirstWhere')->with([['email', '=', $user->email]])->once()->andReturn($user);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($user->id, [
|
||||
|
@ -68,7 +68,7 @@ class DisableTwoFactorCommandTest extends CommandTestCase
|
|||
{
|
||||
$user = factory(User::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'email'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'email'])->once()->andReturnSelf()
|
||||
->shouldReceive('findFirstWhere')->with([['email', '=', $user->email]])->once()->andReturn($user);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($user->id, [
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Tests\Unit\Http\Controllers\Admin;
|
|||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
use Pterodactyl\Http\Controllers\Admin\DatabaseController;
|
||||
|
@ -74,8 +75,8 @@ class DatabaseControllerTest extends TestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn('getAllWithNodes');
|
||||
$this->repository->shouldReceive('getWithViewDetails')->withNoArgs()->once()->andReturn('getWithViewDetails');
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn(collect(['getAllWithNodes']));
|
||||
$this->repository->shouldReceive('getWithViewDetails')->withNoArgs()->once()->andReturn(collect(['getWithViewDetails']));
|
||||
|
||||
$response = $this->getController()->index();
|
||||
|
||||
|
@ -83,8 +84,8 @@ class DatabaseControllerTest extends TestCase
|
|||
$this->assertViewNameEquals('admin.databases.index', $response);
|
||||
$this->assertViewHasKey('locations', $response);
|
||||
$this->assertViewHasKey('hosts', $response);
|
||||
$this->assertViewKeyEquals('locations', 'getAllWithNodes', $response);
|
||||
$this->assertViewKeyEquals('hosts', 'getWithViewDetails', $response);
|
||||
$this->assertViewKeyEquals('locations', collect(['getAllWithNodes']), $response);
|
||||
$this->assertViewKeyEquals('hosts', collect(['getWithViewDetails']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,8 +93,10 @@ class DatabaseControllerTest extends TestCase
|
|||
*/
|
||||
public function testViewController()
|
||||
{
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn('getAllWithNodes');
|
||||
$this->repository->shouldReceive('getWithServers')->with(1)->once()->andReturn('getWithServers');
|
||||
$model = factory(DatabaseHost::class)->make();
|
||||
|
||||
$this->locationRepository->shouldReceive('getAllWithNodes')->withNoArgs()->once()->andReturn(collect(['getAllWithNodes']));
|
||||
$this->repository->shouldReceive('getWithServers')->with(1)->once()->andReturn($model);
|
||||
|
||||
$response = $this->getController()->view(1);
|
||||
|
||||
|
@ -101,8 +104,8 @@ class DatabaseControllerTest extends TestCase
|
|||
$this->assertViewNameEquals('admin.databases.view', $response);
|
||||
$this->assertViewHasKey('locations', $response);
|
||||
$this->assertViewHasKey('host', $response);
|
||||
$this->assertViewKeyEquals('locations', 'getAllWithNodes', $response);
|
||||
$this->assertViewKeyEquals('host', 'getWithServers', $response);
|
||||
$this->assertViewKeyEquals('locations', collect(['getAllWithNodes']), $response);
|
||||
$this->assertViewKeyEquals('host', $model, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,15 +46,15 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->repository->shouldReceive('findWhere')->with([['user_id', '=', $model->id]])->once()->andReturn(['testkeys']);
|
||||
$this->repository->shouldReceive('findWhere')->with([['user_id', '=', $model->id]])->once()->andReturn(collect(['testkeys']));
|
||||
|
||||
$response = $this->getController()->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.api.index', $response);
|
||||
$this->assertViewHasKey('keys', $response);
|
||||
$this->assertViewKeyEquals('keys', ['testkeys'], $response);
|
||||
$this->assertViewKeyEquals('keys', collect(['testkeys']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testCreateController($admin)
|
||||
{
|
||||
$this->setRequestUser(factory(User::class)->make(['root_admin' => $admin]));
|
||||
$this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
|
||||
$response = $this->getController()->create($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
|
@ -87,7 +87,7 @@ class APIControllerTest extends ControllerTestCase
|
|||
public function testStoreController($admin)
|
||||
{
|
||||
$this->setRequestMockClass(ApiKeyFormRequest::class);
|
||||
$model = $this->setRequestUser(factory(User::class)->make(['root_admin' => $admin]));
|
||||
$model = $this->generateRequestUserModel(['root_admin' => $admin]);
|
||||
$keyModel = factory(APIKey::class)->make();
|
||||
|
||||
if ($admin) {
|
||||
|
@ -118,12 +118,12 @@ class APIControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testRevokeController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->repository->shouldReceive('deleteWhere')->with([
|
||||
['user_id', '=', $model->id],
|
||||
['token', '=', 'testKey123'],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$response = $this->getController()->revoke($this->request, 'testKey123');
|
||||
$this->assertIsResponse($response);
|
||||
|
|
|
@ -15,6 +15,7 @@ use Pterodactyl\Models\Server;
|
|||
use Tests\Assertions\ControllerAssertionsTrait;
|
||||
use Tests\Unit\Http\Controllers\ControllerTestCase;
|
||||
use Pterodactyl\Http\Controllers\Base\IndexController;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
|
@ -62,19 +63,19 @@ class IndexControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testIndexController()
|
||||
{
|
||||
$model = $this->setRequestUser();
|
||||
$paginator = m::mock(LengthAwarePaginator::class);
|
||||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->request->shouldReceive('input')->with('query')->once()->andReturn('searchTerm');
|
||||
$this->repository->shouldReceive('search')->with('searchTerm')->once()->andReturnSelf()
|
||||
->shouldReceive('filterUserAccessServers')->with(
|
||||
$model->id, $model->root_admin, 'all', ['user']
|
||||
)->once()->andReturn(['test']);
|
||||
$this->repository->shouldReceive('setSearchTerm')->with('searchTerm')->once()->andReturnSelf()
|
||||
->shouldReceive('filterUserAccessServers')->with($model, User::FILTER_LEVEL_ALL)
|
||||
->once()->andReturn($paginator);
|
||||
|
||||
$response = $this->controller->getIndex($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.index', $response);
|
||||
$this->assertViewHasKey('servers', $response);
|
||||
$this->assertViewKeyEquals('servers', ['test'], $response);
|
||||
$this->assertViewKeyEquals('servers', $paginator, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +83,7 @@ class IndexControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testStatusController()
|
||||
{
|
||||
$user = $this->setRequestUser();
|
||||
$user = $this->generateRequestUserModel();
|
||||
$server = factory(Server::class)->make(['suspended' => 0, 'installed' => 1]);
|
||||
|
||||
$this->repository->shouldReceive('findFirstWhere')->with([['uuidShort', '=', $server->uuidShort]])->once()->andReturn($server);
|
||||
|
@ -105,7 +106,7 @@ class IndexControllerTest extends ControllerTestCase
|
|||
*/
|
||||
public function testStatusControllerWhenServerNotInstalled()
|
||||
{
|
||||
$user = $this->setRequestUser();
|
||||
$user = $this->generateRequestUserModel();
|
||||
$server = factory(Server::class)->make(['suspended' => 0, 'installed' => 0]);
|
||||
|
||||
$this->repository->shouldReceive('findFirstWhere')->with([['uuidShort', '=', $server->uuidShort]])->once()->andReturn($server);
|
||||
|
|
|
@ -61,13 +61,13 @@ class SecurityControllerTest extends ControllerTestCase
|
|||
$model = $this->generateRequestUserModel();
|
||||
|
||||
$this->config->shouldReceive('get')->with('session.driver')->once()->andReturn('database');
|
||||
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(['sessions']);
|
||||
$this->repository->shouldReceive('getUserSessions')->with($model->id)->once()->andReturn(collect(['sessions']));
|
||||
|
||||
$response = $this->getController()->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('base.security', $response);
|
||||
$this->assertViewHasKey('sessions', $response);
|
||||
$this->assertViewKeyEquals('sessions', ['sessions'], $response);
|
||||
$this->assertViewKeyEquals('sessions', collect(['sessions']), $response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,7 +103,7 @@ class FileActionsControllerTest extends ControllerTestCase
|
|||
->shouldReceive('setAccessToken')->with('abc123')->once()->andReturnSelf()
|
||||
->shouldReceive('getContent')->with($file)->once()->andReturn('file contents');
|
||||
|
||||
$response = $controller->update($this->request, '1234', $file);
|
||||
$response = $controller->view($this->request, '1234', $file);
|
||||
$this->assertIsViewResponse($response);
|
||||
$this->assertViewNameEquals('server.files.edit', $response);
|
||||
$this->assertViewHasKey('file', $response);
|
||||
|
@ -134,7 +134,7 @@ class FileActionsControllerTest extends ControllerTestCase
|
|||
$this->repository->shouldReceive('setNode')->with($server->node_id)->once()->andThrow($this->getExceptionMock());
|
||||
|
||||
try {
|
||||
$controller->update($this->request, '1234', 'file.txt');
|
||||
$controller->view($this->request, '1234', 'file.txt');
|
||||
} catch (PterodactylException $exception) {
|
||||
$this->assertInstanceOf(DaemonConnectionException::class, $exception);
|
||||
$this->assertInstanceOf(RequestException::class, $exception->getPrevious());
|
||||
|
|
|
@ -76,7 +76,7 @@ class SubuserControllerTest extends ControllerTestCase
|
|||
$this->mockInjectJavascript();
|
||||
|
||||
$controller->shouldReceive('authorize')->with('list-subusers', $server)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('findWhere')->with([['server_id', '=', $server->id]])->once()->andReturn([]);
|
||||
$this->repository->shouldReceive('findWhere')->with([['server_id', '=', $server->id]])->once()->andReturn(collect());
|
||||
|
||||
$response = $controller->index($this->request);
|
||||
$this->assertIsViewResponse($response);
|
||||
|
|
|
@ -34,7 +34,7 @@ class DaemonAuthenticateTest extends MiddlewareTestCase
|
|||
$this->request->shouldReceive('route->getName')->withNoArgs()->once()->andReturn('random.name');
|
||||
$this->request->shouldReceive('header')->with('X-Access-Node')->twice()->andReturn($node->uuid);
|
||||
|
||||
$this->repository->shouldReceive('findWhere')->with(['daemonSecret' => $node->uuid])->once()->andReturn($node);
|
||||
$this->repository->shouldReceive('findFirstWhere')->with(['daemonSecret' => $node->uuid])->once()->andReturn($node);
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
$this->assertRequestHasAttribute('node');
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Repositories\Eloquent;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||
|
||||
class AllocationRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->builder = m::mock(Builder::class);
|
||||
$this->repository = m::mock(AllocationRepository::class)->makePartial();
|
||||
|
||||
$this->repository->shouldReceive('getBuilder')->withNoArgs()->andReturn($this->builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we are returning the correct model.
|
||||
*/
|
||||
public function testCorrectModelIsAssigned()
|
||||
{
|
||||
$this->assertEquals(Allocation::class, $this->repository->model());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that allocations can be assigned to a server correctly.
|
||||
*/
|
||||
public function testAllocationsAreAssignedToAServer()
|
||||
{
|
||||
$this->builder->shouldReceive('whereIn')->with('id', [1, 2])->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with(['server_id' => 10])->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->assignAllocationsToServer(10, [1, 2]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that allocations with a node relationship are returned.
|
||||
*/
|
||||
public function testAllocationsForANodeAreReturned()
|
||||
{
|
||||
$this->builder->shouldReceive('where')->with('node_id', 1)->once()->andReturnSelf()
|
||||
->shouldReceive('get')->once()->andReturn(factory(Allocation::class)->make());
|
||||
|
||||
$this->assertInstanceOf(Allocation::class, $this->repository->getAllocationsForNode(1));
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Repositories\Eloquent;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\APIKey;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
||||
|
||||
class ApiKeyRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ApiKeyRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->builder = m::mock(Builder::class);
|
||||
$this->repository = m::mock(ApiKeyRepository::class)->makePartial();
|
||||
|
||||
$this->repository->shouldReceive('getBuilder')->withNoArgs()->andReturn($this->builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we are returning the correct model.
|
||||
*/
|
||||
public function testCorrectModelIsAssigned()
|
||||
{
|
||||
$this->assertEquals(APIKey::class, $this->repository->model());
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Repositories\Eloquent;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\APIPermission;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Repositories\Eloquent\ApiPermissionRepository;
|
||||
|
||||
class ApiPermissionRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ApiPermissionRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->builder = m::mock(Builder::class);
|
||||
$this->repository = m::mock(ApiPermissionRepository::class)->makePartial();
|
||||
|
||||
$this->repository->shouldReceive('getBuilder')->withNoArgs()->andReturn($this->builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we are returning the correct model.
|
||||
*/
|
||||
public function testCorrectModelIsAssigned()
|
||||
{
|
||||
$this->assertEquals(APIPermission::class, $this->repository->model());
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Repositories\Eloquent;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
||||
|
||||
class DatabaseHostRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\DatabaseHostRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->builder = m::mock(Builder::class);
|
||||
$this->repository = m::mock(DatabaseHostRepository::class)->makePartial();
|
||||
|
||||
$this->repository->shouldReceive('getBuilder')->withNoArgs()->andReturn($this->builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we are returning the correct model.
|
||||
*/
|
||||
public function testCorrectModelIsAssigned()
|
||||
{
|
||||
$this->assertEquals(DatabaseHost::class, $this->repository->model());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test query to reutrn all of the default view data.
|
||||
*/
|
||||
public function testHostWithDefaultViewDataIsReturned()
|
||||
{
|
||||
$this->builder->shouldReceive('withCount')->with('databases')->once()->andReturnSelf()
|
||||
->shouldReceive('with')->with('node')->once()->andReturnSelf()
|
||||
->shouldReceive('get')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->assertNull($this->repository->getWithViewDetails());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test query to return host and servers.
|
||||
*/
|
||||
public function testHostIsReturnedWithServers()
|
||||
{
|
||||
$model = factory(DatabaseHost::class)->make();
|
||||
|
||||
$this->builder->shouldReceive('with')->with('databases.server')->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with(1, ['*'])->once()->andReturn($model);
|
||||
|
||||
$this->assertEquals($model, $this->repository->getWithServers(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception is found if no host is found when querying for servers.
|
||||
*
|
||||
* @expectedException \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function testExceptionIsThrownIfNoRecordIsFoundWithServers()
|
||||
{
|
||||
$this->builder->shouldReceive('with')->with('databases.server')->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with(1, ['*'])->once()->andReturnNull();
|
||||
|
||||
$this->repository->getWithServers(1);
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Repositories\Eloquent;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
||||
use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException;
|
||||
|
||||
class DatabaseRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\DatabaseRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->builder = m::mock(Builder::class);
|
||||
$this->repository = m::mock(DatabaseRepository::class)->makePartial()->shouldAllowMockingProtectedMethods();
|
||||
|
||||
$this->repository->shouldReceive('getBuilder')->withNoArgs()->andReturn($this->builder);
|
||||
$this->repository->shouldNotReceive('runStatement');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we are returning the correct model.
|
||||
*/
|
||||
public function testCorrectModelIsAssigned()
|
||||
{
|
||||
$this->assertEquals(Database::class, $this->repository->model());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a database can be created if it does not already exist.
|
||||
*/
|
||||
public function testDatabaseIsCreatedIfNotExists()
|
||||
{
|
||||
$data = [
|
||||
'server_id' => 1,
|
||||
'database_host_id' => 100,
|
||||
'database' => 'somename',
|
||||
];
|
||||
|
||||
$this->builder->shouldReceive('where')->with([
|
||||
['server_id', '=', array_get($data, 'server_id')],
|
||||
['database_host_id', '=', array_get($data, 'database_host_id')],
|
||||
['database', '=', array_get($data, 'database')],
|
||||
])->once()->andReturnSelf()
|
||||
->shouldReceive('count')->withNoArgs()->once()->andReturn(0);
|
||||
|
||||
$this->repository->shouldReceive('create')->with($data)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->createIfNotExists($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is thrown if a database already exists with the given name.
|
||||
*/
|
||||
public function testExceptionIsThrownIfDatabaseAlreadyExists()
|
||||
{
|
||||
$this->builder->shouldReceive('where->count')->once()->andReturn(1);
|
||||
$this->repository->shouldNotReceive('create');
|
||||
|
||||
try {
|
||||
$this->repository->createIfNotExists([]);
|
||||
} catch (DisplayException $exception) {
|
||||
$this->assertInstanceOf(DuplicateDatabaseNameException::class, $exception);
|
||||
$this->assertEquals('A database with those details already exists for the specified server.', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test SQL used to create a database.
|
||||
*/
|
||||
public function testCreateDatabaseStatement()
|
||||
{
|
||||
$query = sprintf('CREATE DATABASE IF NOT EXISTS `%s`', 'test_database');
|
||||
$this->repository->shouldReceive('runStatement')->with($query)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->createDatabase('test_database', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test SQL used to create a user.
|
||||
*/
|
||||
public function testCreateUserStatement()
|
||||
{
|
||||
$query = sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', 'test', '%', 'password');
|
||||
$this->repository->shouldReceive('runStatement')->with($query)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->createUser('test', '%', 'password', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a user is assigned the correct permissions on a database.
|
||||
*/
|
||||
public function testUserAssignmentToDatabaseStatement()
|
||||
{
|
||||
$query = sprintf('GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX, EXECUTE ON `%s`.* TO `%s`@`%s`', 'test_database', 'test', '%');
|
||||
$this->repository->shouldReceive('runStatement')->with($query)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->assignUserToDatabase('test_database', 'test', '%', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test SQL for flushing privileges.
|
||||
*/
|
||||
public function testFlushStatement()
|
||||
{
|
||||
$this->repository->shouldReceive('runStatement')->with('FLUSH PRIVILEGES')->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->flush('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test SQL to drop a database.
|
||||
*/
|
||||
public function testDropDatabaseStatement()
|
||||
{
|
||||
$query = sprintf('DROP DATABASE IF EXISTS `%s`', 'test_database');
|
||||
$this->repository->shouldReceive('runStatement')->with($query)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->dropDatabase('test_database', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test SQL to drop a user.
|
||||
*/
|
||||
public function testDropUserStatement()
|
||||
{
|
||||
$query = sprintf('DROP USER IF EXISTS `%s`@`%s`', 'test', '%');
|
||||
$this->repository->shouldReceive('runStatement')->with($query)->once()->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->repository->dropUser('test', '%', 'test'));
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Repositories\Eloquent;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
||||
|
||||
class LocationRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\LocationRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->builder = m::mock(Builder::class);
|
||||
$this->repository = m::mock(LocationRepository::class)->makePartial();
|
||||
|
||||
$this->repository->shouldReceive('getBuilder')->withNoArgs()->andReturn($this->builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we are returning the correct model.
|
||||
*/
|
||||
public function testCorrectModelIsAssigned()
|
||||
{
|
||||
$this->assertEquals(Location::class, $this->repository->model());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that all locations with associated node and server counts are returned.
|
||||
*/
|
||||
public function testAllLocationsWithDetailsAreReturned()
|
||||
{
|
||||
$this->builder->shouldReceive('withCount')->with('nodes', 'servers')->once()->andReturnSelf()
|
||||
->shouldReceive('get')->with(['*'])->once()->andReturnNull();
|
||||
|
||||
$this->assertNull($this->repository->getAllWithDetails());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that all locations with associated node are returned.
|
||||
*/
|
||||
public function testAllLocationsWithNodes()
|
||||
{
|
||||
$this->builder->shouldReceive('with')->with('nodes')->once()->andReturnSelf()
|
||||
->shouldReceive('get')->with(['*'])->once()->andReturnNull();
|
||||
|
||||
$this->assertNull($this->repository->getAllWithNodes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a single location with associated node is returned.
|
||||
*/
|
||||
public function testLocationWithNodeIsReturned()
|
||||
{
|
||||
$model = factory(Location::class)->make();
|
||||
|
||||
$this->builder->shouldReceive('with')->with('nodes.servers')->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with(1, ['*'])->once()->andReturn($model);
|
||||
|
||||
$response = $this->repository->getWithNodes(1);
|
||||
$this->assertInstanceOf(Location::class, $response);
|
||||
$this->assertEquals($model, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is thrown when getting location with nodes if no location is found.
|
||||
*
|
||||
* @expectedException \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function testExceptionIsThrownIfNoLocationIsFoundWithNodes()
|
||||
{
|
||||
$this->builder->shouldReceive('with')->with('nodes.servers')->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with(1, ['*'])->once()->andReturnNull();
|
||||
|
||||
$this->repository->getWithNodes(1);
|
||||
}
|
||||
}
|
|
@ -84,7 +84,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -123,7 +123,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -149,7 +149,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => 'my.alias.net',
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -177,7 +177,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -202,7 +202,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('insertIgnore')->with([
|
||||
[
|
||||
|
@ -212,7 +212,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -303,7 +303,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node, $data);
|
||||
|
|
|
@ -97,7 +97,7 @@ class DaemonKeyDeletionServiceTest extends TestCase
|
|||
['server_id', '=', $server->id],
|
||||
])->once()->andReturn($key);
|
||||
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
@ -121,7 +121,7 @@ class DaemonKeyDeletionServiceTest extends TestCase
|
|||
['server_id', '=', $server->id],
|
||||
])->once()->andReturn($key);
|
||||
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
@ -144,7 +144,7 @@ class DaemonKeyDeletionServiceTest extends TestCase
|
|||
['server_id', '=', $server->id],
|
||||
])->once()->andReturn($key);
|
||||
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andThrow($this->exception);
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
||||
|
|
|
@ -66,11 +66,11 @@ class DatabasePasswordServiceTest extends TestCase
|
|||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('update')->with($model->id, ['password' => 'enc123'])->once()->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('dropUser')->with($model->username, $model->remote)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('createUser')->with($model->username, $model->remote, 'test123')->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('assignUserToDatabase')->with($model->database, $model->username, $model->remote)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('flush')->withNoArgs()->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('dropUser')->with($model->username, $model->remote)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('createUser')->with($model->username, $model->remote, 'test123')->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('assignUserToDatabase')->with($model->database, $model->username, $model->remote)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('flush')->withNoArgs()->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturn(true);
|
||||
|
||||
$response = $this->getService()->handle($useModel ? $model : 1234, 'test123');
|
||||
$this->assertNotEmpty($response);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
namespace Tests\Unit\Services\Services\Options;
|
||||
|
||||
use Exception;
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Egg;
|
||||
|
|
|
@ -86,8 +86,8 @@ class EggUpdateImporterServiceTest extends TestCase
|
|||
'env_variable' => $variable->env_variable,
|
||||
], collect($variable)->except(['egg_id', 'env_variable'])->toArray())->once()->andReturnNull();
|
||||
|
||||
$this->variableRepository->shouldReceive('withColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn([$variable]);
|
||||
$this->variableRepository->shouldReceive('setColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn(collect([$variable]));
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -126,13 +126,13 @@ class EggUpdateImporterServiceTest extends TestCase
|
|||
'env_variable' => $variable1->env_variable,
|
||||
], collect($variable1)->except(['egg_id', 'env_variable'])->toArray())->once()->andReturnNull();
|
||||
|
||||
$this->variableRepository->shouldReceive('withColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn([$variable1, $variable2]);
|
||||
$this->variableRepository->shouldReceive('setColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn(collect([$variable1, $variable2]));
|
||||
|
||||
$this->variableRepository->shouldReceive('deleteWhere')->with([
|
||||
['egg_id', '=', $egg->id],
|
||||
['env_variable', '=', $variable2->env_variable],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testVariableIsUpdatedWhenValidEnvironmentVariableIsPassed()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([
|
||||
['env_variable', '=', 'TEST_VAR_123'],
|
||||
['egg_id', '=', $this->model->option_id],
|
||||
|
@ -116,7 +116,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testDataPassedIntoHandlerTakesLowerPriorityThanDataSet()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([
|
||||
['env_variable', '=', 'TEST_VAR_123'],
|
||||
['egg_id', '=', $this->model->option_id],
|
||||
|
@ -138,7 +138,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfEnvironmentVariableIsNotUnique()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([
|
||||
['env_variable', '=', 'TEST_VAR_123'],
|
||||
['egg_id', '=', $this->model->option_id],
|
||||
|
|
|
@ -62,14 +62,11 @@ class NodeDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testNodeIsDeletedIfNoServersAreAttached()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', 1]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with(1)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with(1)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle(1),
|
||||
'Assert that deletion returns a positive boolean value.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle(1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +76,7 @@ class NodeDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfServersAreAttachedToNode()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', 1]])->once()->andReturn(1);
|
||||
$this->translator->shouldReceive('trans')->with('exceptions.node.servers_attached')->once()->andReturnNull();
|
||||
$this->repository->shouldNotReceive('delete');
|
||||
|
@ -94,13 +91,10 @@ class NodeDeletionServiceTest extends TestCase
|
|||
{
|
||||
$node = factory(Node::class)->make();
|
||||
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', $node->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($node->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($node->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($node),
|
||||
'Assert that deletion returns a positive boolean value.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($node));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class PackDeletionServiceTest extends TestCase
|
|||
|
||||
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(0);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturn(1);
|
||||
$this->storage->shouldReceive('disk')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('deleteDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
@ -91,11 +91,11 @@ class PackDeletionServiceTest extends TestCase
|
|||
{
|
||||
$model = factory(Pack::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'uuid'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'uuid'])->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
|
||||
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(0);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturn(1);
|
||||
$this->storage->shouldReceive('disk')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('deleteDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
|
|
@ -85,7 +85,7 @@ class PackUpdateServiceTest extends TestCase
|
|||
{
|
||||
$model = factory(Pack::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'egg_id'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'egg_id'])->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
|
||||
'locked' => false,
|
||||
|
|
|
@ -116,7 +116,7 @@ class ServerCreationServiceTest extends TestCase
|
|||
'egg_id' => $model->egg_id,
|
||||
]))->once()->andReturn($model);
|
||||
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->with($model->id, [$model->allocation_id])->once()->andReturnNull();
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->with($model->id, [$model->allocation_id])->once()->andReturn(1);
|
||||
|
||||
$this->validatorService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_ADMIN)->once()->andReturnNull();
|
||||
$this->validatorService->shouldReceive('handle')->with($model->egg_id, [])->once()->andReturn(
|
||||
|
@ -129,7 +129,7 @@ class ServerCreationServiceTest extends TestCase
|
|||
'variable_id' => 123,
|
||||
'variable_value' => 'var1-value',
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->configurationStructureService->shouldReceive('handle')->with($model)->once()->andReturn(['test' => 'struct']);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
|
||||
|
@ -154,7 +154,7 @@ class ServerCreationServiceTest extends TestCase
|
|||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('create')->once()->andReturn($model);
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->once()->andReturnNull();
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->once()->andReturn(1);
|
||||
$this->validatorService->shouldReceive('setUserLevel')->once()->andReturnNull();
|
||||
$this->validatorService->shouldReceive('handle')->once()->andReturn(collect([]));
|
||||
$this->configurationStructureService->shouldReceive('handle')->once()->andReturn([]);
|
||||
|
|
|
@ -116,13 +116,13 @@ class ServerDeletionServiceTest extends TestCase
|
|||
->shouldReceive('delete')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->databaseRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->databaseRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([
|
||||
['server_id', '=', $this->model->id],
|
||||
])->once()->andReturn(collect([(object) ['id' => 50]]));
|
||||
|
||||
$this->databaseManagementService->shouldReceive('delete')->with(50)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model);
|
||||
|
@ -140,13 +140,13 @@ class ServerDeletionServiceTest extends TestCase
|
|||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnNull();
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->databaseRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->databaseRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([
|
||||
['server_id', '=', $this->model->id],
|
||||
])->once()->andReturn(collect([(object) ['id' => 50]]));
|
||||
|
||||
$this->databaseManagementService->shouldReceive('delete')->with(50)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->withForce()->handle($this->model);
|
||||
|
@ -176,21 +176,21 @@ class ServerDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testIntegerCanBePassedInPlaceOfServerModel()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'uuid'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'uuid'])->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->model->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->model->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andReturnNull();
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andReturn(1);
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->databaseRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->databaseRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([
|
||||
['server_id', '=', $this->model->id],
|
||||
])->once()->andReturn(collect([(object) ['id' => 50]]));
|
||||
|
||||
$this->databaseManagementService->shouldReceive('delete')->with(50)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model->id);
|
||||
|
|
|
@ -49,10 +49,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 0]);
|
||||
$server = factory(Server::class)->make(['node_id' => 1, 'owner_id' => $user->id]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($server, $user)->once()->andReturn('server_token');
|
||||
|
@ -74,10 +74,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 1]);
|
||||
$server = factory(Server::class)->make(['node_id' => 1, 'owner_id' => $user->id + 1]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($server, $user)->once()->andReturn('server_token');
|
||||
|
@ -110,7 +110,7 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
{
|
||||
$user = factory(User::class)->make();
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->getService()->handle($user->username, 'wrongpassword', 1, '1234');
|
||||
|
@ -123,7 +123,7 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfNoUserAccountIsFound()
|
||||
{
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', 'something']])->once()->andThrow(new RecordNotFoundException);
|
||||
|
||||
$this->getService()->handle('something', 'password', 1, '1234');
|
||||
|
@ -140,10 +140,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 0]);
|
||||
$server = factory(Server::class)->make(['node_id' => 1, 'owner_id' => $user->id + 1]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->getService()->handle($user->username, 'password', 1, $server->uuidShort);
|
||||
|
@ -160,10 +160,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 0]);
|
||||
$server = factory(Server::class)->make(['node_id' => 2, 'owner_id' => $user->id]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->getService()->handle($user->username, 'password', 1, $server->uuidShort);
|
||||
|
|
|
@ -48,7 +48,7 @@ class PermissionCreationServiceTest extends TestCase
|
|||
->shouldReceive('insert')->with([
|
||||
['subuser_id' => 1, 'permission' => 'reset-sftp'],
|
||||
['subuser_id' => 1, 'permission' => 'view-sftp'],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
|
||||
$this->service->handle(1, $permissions);
|
||||
$this->assertTrue(true);
|
||||
|
|
|
@ -55,7 +55,7 @@ class SubuserDeletionServiceTest extends TestCase
|
|||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->keyDeletionService->shouldReceive('handle')->with($subuser->server_id, $subuser->user_id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->getService()->handle($subuser);
|
||||
|
|
|
@ -86,7 +86,7 @@ class SubuserUpdateServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('loadServerAndUserRelations')->with($subuser)->once()->andReturn($subuser);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturn(1);
|
||||
$this->permissionService->shouldReceive('handle')->with($subuser->id, ['some-permission'])->once()->andReturnNull();
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($subuser->server, $subuser->user, false)->once()->andReturn('test123');
|
||||
|
@ -112,7 +112,7 @@ class SubuserUpdateServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('loadServerAndUserRelations')->with($subuser)->once()->andReturn($subuser);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturn(1);
|
||||
$this->permissionService->shouldReceive('handle')->with($subuser->id, [])->once()->andReturnNull();
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($subuser->server, $subuser->user, false)->once()->andReturn('test123');
|
||||
|
|
|
@ -68,14 +68,11 @@ class UserDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testUserIsDeletedIfNoServersAreAttachedToAccount()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($this->user->id),
|
||||
'Assert that service responds true.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($this->user->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,7 +82,7 @@ class UserDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfServersAreAttachedToAccount()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(1);
|
||||
$this->translator->shouldReceive('trans')->with('admin/user.exceptions.user_has_servers')->once()->andReturnNull();
|
||||
|
||||
|
@ -97,13 +94,10 @@ class UserDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testModelCanBePassedInPlaceOfUserId()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($this->user),
|
||||
'Assert that service responds true.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($this->user));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue