Fix existing tests

This commit is contained in:
Dane Everitt 2017-10-08 15:44:28 -05:00
parent 6e02e9491a
commit 159ad3079f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 40 additions and 51 deletions

View file

@ -13,6 +13,7 @@ use Exception;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\Pack;
use Tests\Traits\MocksUuids;
use Illuminate\Http\UploadedFile;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Database\ConnectionInterface;
@ -23,18 +24,20 @@ use Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException;
class PackCreationServiceTest extends TestCase
{
use MocksUuids;
/**
* @var \Illuminate\Database\ConnectionInterface
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
*/
protected $connection;
/**
* @var \Illuminate\Http\UploadedFile
* @var \Illuminate\Http\UploadedFile|\Mockery\Mock
*/
protected $file;
/**
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface|\Mockery\Mock
*/
protected $repository;
@ -44,15 +47,10 @@ class PackCreationServiceTest extends TestCase
protected $service;
/**
* @var \Illuminate\Contracts\Filesystem\Factory
* @var \Illuminate\Contracts\Filesystem\Factory|\Mockery\Mock
*/
protected $storage;
/**
* @var \Ramsey\Uuid\Uuid
*/
protected $uuid;
/**
* Setup tests.
*/
@ -64,7 +62,6 @@ class PackCreationServiceTest extends TestCase
$this->file = m::mock(UploadedFile::class);
$this->repository = m::mock(PackRepositoryInterface::class);
$this->storage = m::mock(Factory::class);
$this->uuid = m::mock('overload:\Ramsey\Uuid\Uuid');
$this->service = new PackCreationService($this->connection, $this->storage, $this->repository);
}
@ -77,17 +74,15 @@ class PackCreationServiceTest extends TestCase
$model = factory(Pack::class)->make();
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
$this->uuid->shouldReceive('uuid4')->withNoArgs()->once()->andReturn($model->uuid);
$this->repository->shouldReceive('create')->with([
'uuid' => $model->uuid,
'uuid' => $this->getKnownUuid(),
'selectable' => false,
'visible' => false,
'locked' => false,
'test-data' => 'value',
])->once()->andReturn($model);
$this->storage->shouldReceive('disk')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('makeDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
$this->storage->shouldReceive('disk->makeDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
$response = $this->service->handle(['test-data' => 'value']);
@ -107,17 +102,15 @@ class PackCreationServiceTest extends TestCase
$this->file->shouldReceive('isValid')->withNoArgs()->once()->andReturn(true);
$this->file->shouldReceive('getMimeType')->withNoArgs()->once()->andReturn($mime);
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
$this->uuid->shouldReceive('uuid4')->withNoArgs()->once()->andReturn($model->uuid);
$this->repository->shouldReceive('create')->with([
'uuid' => $model->uuid,
'uuid' => $this->getKnownUuid(),
'selectable' => false,
'visible' => false,
'locked' => false,
'test-data' => 'value',
])->once()->andReturn($model);
$this->storage->shouldReceive('disk')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('makeDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
$this->storage->shouldReceive('disk->makeDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
$this->file->shouldReceive('storeAs')->with('packs/' . $model->uuid, 'archive.tar.gz')->once()->andReturnNull();
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();

View file

@ -20,12 +20,12 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class PackUpdateServiceTest extends TestCase
{
/**
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface|\Mockery\Mock
*/
protected $repository;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
*/
protected $serverRepository;
@ -53,8 +53,7 @@ class PackUpdateServiceTest extends TestCase
public function testPackIsUpdated()
{
$model = factory(Pack::class)->make();
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($model->id, [
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
'locked' => false,
'visible' => false,
'selectable' => false,
@ -67,13 +66,13 @@ class PackUpdateServiceTest extends TestCase
/**
* Test that an exception is thrown if the pack option ID is changed while servers are using the pack.
*/
public function testExceptionIsThrownIfModifyingOptionIdWhenServersAreAttached()
public function testExceptionIsThrownIfModifyingEggIdWhenServersAreAttached()
{
$model = factory(Pack::class)->make();
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(1);
try {
$this->service->handle($model, ['option_id' => 0]);
$this->service->handle($model, ['egg_id' => 0]);
} catch (HasActiveServersException $exception) {
$this->assertEquals(trans('exceptions.packs.update_has_servers'), $exception->getMessage());
}
@ -86,10 +85,9 @@ class PackUpdateServiceTest extends TestCase
{
$model = factory(Pack::class)->make();
$this->repository->shouldReceive('withColumns')->with(['id', 'option_id'])->once()->andReturnSelf()
$this->repository->shouldReceive('withColumns')->with(['id', 'egg_id'])->once()->andReturnSelf()
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('update')->with($model->id, [
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
'locked' => false,
'visible' => false,
'selectable' => false,

View file

@ -27,17 +27,17 @@ class TemplateUploadServiceTest extends TestCase
const JSON_FILE_CONTENTS = '{"test_content": "value"}';
/**
* @var \ZipArchive
* @var \ZipArchive|\Mockery\Mock
*/
protected $archive;
/**
* @var \Pterodactyl\Services\Packs\PackCreationService
* @var \Pterodactyl\Services\Packs\PackCreationService|\Mockery\Mock
*/
protected $creationService;
/**
* @var \Illuminate\Http\UploadedFile
* @var \Illuminate\Http\UploadedFile|\Mockery\Mock
*/
protected $file;
@ -70,10 +70,9 @@ class TemplateUploadServiceTest extends TestCase
$this->file->shouldReceive('isValid')->withNoArgs()->once()->andReturn(true);
$this->file->shouldReceive('getMimeType')->withNoArgs()->twice()->andReturn($mime);
$this->file->shouldReceive('getSize')->withNoArgs()->once()->andReturn(128);
$this->file->shouldReceive('openFile')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('fread')->with(128)->once()->andReturn(self::JSON_FILE_CONTENTS);
$this->file->shouldReceive('openFile->fread')->with(128)->once()->andReturn(self::JSON_FILE_CONTENTS);
$this->creationService->shouldReceive('handle')->with(['test_content' => 'value', 'option_id' => 1])
$this->creationService->shouldReceive('handle')->with(['test_content' => 'value', 'egg_id' => 1])
->once()->andReturn(factory(Pack::class)->make());
$this->assertInstanceOf(Pack::class, $this->service->handle(1, $this->file));
@ -94,7 +93,7 @@ class TemplateUploadServiceTest extends TestCase
$this->archive->shouldReceive('locateName')->with('import.json')->once()->andReturn(true);
$this->archive->shouldReceive('locateName')->with('archive.tar.gz')->once()->andReturn(true);
$this->archive->shouldReceive('getFromName')->with('import.json')->once()->andReturn(self::JSON_FILE_CONTENTS);
$this->creationService->shouldReceive('handle')->with(['test_content' => 'value', 'option_id' => 1])
$this->creationService->shouldReceive('handle')->with(['test_content' => 'value', 'egg_id' => 1])
->once()->andReturn($model);
$this->archive->shouldReceive('extractTo')->with(storage_path('app/packs/' . $model->uuid), 'archive.tar.gz')
->once()->andReturn(true);