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
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue