misc_pterodactyl-panel/tests/Unit/Services/Subusers/SubuserDeletionServiceTest.php

75 lines
2.3 KiB
PHP
Raw Normal View History

2017-08-26 18:31:18 +00:00
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
2017-08-26 18:31:18 +00:00
*/
namespace Tests\Unit\Services\Subusers;
use Mockery as m;
2017-08-27 19:55:25 +00:00
use Tests\TestCase;
2017-08-26 18:31:18 +00:00
use Pterodactyl\Models\Subuser;
2017-08-27 19:55:25 +00:00
use Illuminate\Database\ConnectionInterface;
2017-08-26 18:31:18 +00:00
use Pterodactyl\Services\Subusers\SubuserDeletionService;
2017-09-25 03:28:16 +00:00
use Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService;
2017-08-27 19:55:25 +00:00
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
2017-08-26 18:31:18 +00:00
class SubuserDeletionServiceTest extends TestCase
{
/**
2017-09-25 03:28:16 +00:00
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
2017-08-26 18:31:18 +00:00
*/
2017-11-03 21:52:18 +00:00
private $connection;
2017-08-26 18:31:18 +00:00
/**
2017-09-25 03:28:16 +00:00
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyDeletionService|\Mockery\Mock
2017-08-26 18:31:18 +00:00
*/
2017-11-03 21:52:18 +00:00
private $keyDeletionService;
2017-08-26 18:31:18 +00:00
/**
2017-09-25 03:28:16 +00:00
* @var \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface|\Mockery\Mock
2017-08-26 18:31:18 +00:00
*/
2017-11-03 21:52:18 +00:00
private $repository;
2017-08-26 18:31:18 +00:00
/**
* Setup tests.
*/
public function setUp()
{
parent::setUp();
$this->connection = m::mock(ConnectionInterface::class);
2017-09-25 03:28:16 +00:00
$this->keyDeletionService = m::mock(DaemonKeyDeletionService::class);
2017-08-26 18:31:18 +00:00
$this->repository = m::mock(SubuserRepositoryInterface::class);
}
/**
* Test that a subuser is deleted correctly.
*/
2017-11-03 21:52:18 +00:00
public function testSubuserIsDeleted()
2017-08-26 18:31:18 +00:00
{
$subuser = factory(Subuser::class)->make();
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
2017-09-25 03:28:16 +00:00
$this->keyDeletionService->shouldReceive('handle')->with($subuser->server_id, $subuser->user_id)->once()->andReturnNull();
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturnNull();
2017-08-26 18:31:18 +00:00
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
2017-11-03 21:52:18 +00:00
$this->getService()->handle($subuser);
2017-09-25 03:28:16 +00:00
$this->assertTrue(true);
2017-08-26 18:31:18 +00:00
}
/**
2017-11-03 21:52:18 +00:00
* Return an instance of the service with mocked dependencies for testing.
*
* @return \Pterodactyl\Services\Subusers\SubuserDeletionService
2017-08-26 18:31:18 +00:00
*/
2017-11-03 21:52:18 +00:00
private function getService(): SubuserDeletionService
2017-08-26 18:31:18 +00:00
{
2017-11-03 21:52:18 +00:00
return new SubuserDeletionService($this->connection, $this->keyDeletionService, $this->repository);
2017-08-26 18:31:18 +00:00
}
}