misc_pterodactyl-panel/tests/Unit/Services/Servers/ReinstallServerServiceTest.php

83 lines
2.4 KiB
PHP
Raw Normal View History

<?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
*/
namespace Tests\Unit\Services\Servers;
2017-08-05 22:26:30 +00:00
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\Server;
use Illuminate\Database\ConnectionInterface;
2020-06-25 05:18:48 +00:00
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ReinstallServerService;
2020-06-25 05:18:48 +00:00
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
class ReinstallServerServiceTest extends TestCase
{
/**
2020-06-25 05:18:48 +00:00
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
2020-06-25 05:18:48 +00:00
private $daemonServerRepository;
/**
* @var \Illuminate\Database\ConnectionInterface
*/
2020-06-25 05:18:48 +00:00
private $connection;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
2020-06-25 05:18:48 +00:00
private $repository;
/**
* Setup tests.
*/
public function setUp(): void
{
parent::setUp();
2020-06-25 05:18:48 +00:00
$this->repository = m::mock(ServerRepository::class);
$this->connection = m::mock(ConnectionInterface::class);
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
}
/**
* Test that a server is reinstalled when it's model is passed to the function.
*/
public function testServerShouldBeReinstalledWhenModelIsPassed()
{
2020-06-25 05:18:48 +00:00
/** @var \Pterodactyl\Models\Server $server */
$server = factory(Server::class)->make(['id' => 123]);
$updated = clone $server;
$updated->installed = Server::STATUS_INSTALLING;
2020-06-25 05:18:48 +00:00
$this->connection->expects('transaction')->with(m::on(function ($closure) use ($updated) {
return $closure() instanceof Server;
}))->andReturn($updated);
2020-06-25 05:18:48 +00:00
$this->repository->expects('update')->with($server->id, [
'installed' => Server::STATUS_INSTALLING,
])->andReturns($updated);
2020-06-25 05:18:48 +00:00
$this->daemonServerRepository->expects('setServer')->with($server)->andReturnSelf();
$this->daemonServerRepository->expects('reinstall')->withNoArgs();
2020-06-25 05:18:48 +00:00
$this->assertSame($updated, $this->getService()->reinstall($server));
}
/**
2020-06-25 05:18:48 +00:00
* @return \Pterodactyl\Services\Servers\ReinstallServerService
*/
2020-06-25 05:18:48 +00:00
private function getService()
{
2020-06-25 05:18:48 +00:00
return new ReinstallServerService(
$this->connection, $this->daemonServerRepository, $this->repository
);
}
}