Files
pterodactyl-panel/tests/Unit/Services/Servers/ReinstallServerServiceTest.php
T

83 lines
2.4 KiB
PHP
Raw Normal View History

2017-07-23 14:51:18 -05:00
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-25 21:43:01 -05:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
2017-07-23 14:51:18 -05:00
*/
namespace Tests\Unit\Services\Servers;
2017-08-05 17:26:30 -05:00
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\Server;
2017-07-23 14:51:18 -05:00
use Illuminate\Database\ConnectionInterface;
2020-06-24 22:18:48 -07:00
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ReinstallServerService;
2020-06-24 22:18:48 -07:00
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
2017-07-23 14:51:18 -05:00
class ReinstallServerServiceTest extends TestCase
2017-07-23 14:51:18 -05:00
{
/**
2020-06-24 22:18:48 -07:00
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
2017-07-23 14:51:18 -05:00
*/
2020-06-24 22:18:48 -07:00
private $daemonServerRepository;
2017-07-23 14:51:18 -05:00
/**
* @var \Illuminate\Database\ConnectionInterface
*/
2020-06-24 22:18:48 -07:00
private $connection;
2017-07-23 14:51:18 -05:00
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
2020-06-24 22:18:48 -07:00
private $repository;
2017-07-23 14:51:18 -05:00
/**
* Setup tests.
*/
public function setUp(): void
2017-07-23 14:51:18 -05:00
{
parent::setUp();
2020-06-24 22:18:48 -07:00
$this->repository = m::mock(ServerRepository::class);
$this->connection = m::mock(ConnectionInterface::class);
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
2017-07-23 14:51:18 -05:00
}
/**
* Test that a server is reinstalled when it's model is passed to the function.
*/
public function testServerShouldBeReinstalledWhenModelIsPassed()
{
2020-06-24 22:18:48 -07:00
/** @var \Pterodactyl\Models\Server $server */
$server = factory(Server::class)->make(['id' => 123]);
$updated = clone $server;
$updated->installed = Server::STATUS_INSTALLING;
2017-07-23 14:51:18 -05:00
2020-06-24 22:18:48 -07:00
$this->connection->expects('transaction')->with(m::on(function ($closure) use ($updated) {
return $closure() instanceof Server;
}))->andReturn($updated);
2017-07-23 14:51:18 -05:00
2020-06-24 22:18:48 -07:00
$this->repository->expects('update')->with($server->id, [
'installed' => Server::STATUS_INSTALLING,
])->andReturns($updated);
2017-07-23 14:51:18 -05:00
2020-06-24 22:18:48 -07:00
$this->daemonServerRepository->expects('setServer')->with($server)->andReturnSelf();
$this->daemonServerRepository->expects('reinstall')->withNoArgs();
2017-07-23 14:51:18 -05:00
2020-06-24 22:18:48 -07:00
$this->assertSame($updated, $this->getService()->reinstall($server));
2017-07-23 14:51:18 -05:00
}
/**
2020-06-24 22:18:48 -07:00
* @return \Pterodactyl\Services\Servers\ReinstallServerService
2017-07-23 14:51:18 -05:00
*/
2020-06-24 22:18:48 -07:00
private function getService()
2017-07-23 14:51:18 -05:00
{
2020-06-24 22:18:48 -07:00
return new ReinstallServerService(
$this->connection, $this->daemonServerRepository, $this->repository
);
2017-07-23 14:51:18 -05:00
}
}