2017-07-23 19:51:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Servers;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use Mockery as m;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Tests\TestCase;
|
2018-01-06 00:27:47 +00:00
|
|
|
use GuzzleHttp\Psr7\Response;
|
2017-07-23 19:51:18 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2017-08-05 22:26:30 +00:00
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2017-07-23 19:51:18 +00:00
|
|
|
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
2018-01-06 00:27:47 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
class ContainerRebuildServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2018-01-06 00:27:47 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2018-01-06 00:27:47 +00:00
|
|
|
protected $repository;
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \GuzzleHttp\Exception\RequestException
|
|
|
|
*/
|
|
|
|
protected $exception;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Models\Server
|
|
|
|
*/
|
|
|
|
protected $server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\ContainerRebuildService
|
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->exception = m::mock(RequestException::class)->makePartial();
|
|
|
|
$this->repository = m::mock(ServerRepositoryInterface::class);
|
2017-07-24 00:57:43 +00:00
|
|
|
|
2017-07-23 19:51:18 +00:00
|
|
|
$this->server = factory(Server::class)->make(['node_id' => 1]);
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->service = new ContainerRebuildService($this->repository);
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-06 00:27:47 +00:00
|
|
|
* Test that a server is marked for rebuild.
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2018-01-06 00:27:47 +00:00
|
|
|
public function testServerIsMarkedForRebuild()
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->repository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
|
|
|
->shouldReceive('rebuild')->withNoArgs()->once()->andReturn(new Response);
|
2017-07-23 19:51:18 +00:00
|
|
|
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->service->handle($this->server);
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that an exception thrown by guzzle is rendered as a displayable exception.
|
|
|
|
*
|
2018-01-06 00:27:47 +00:00
|
|
|
* @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
2017-07-23 19:51:18 +00:00
|
|
|
*/
|
2018-01-06 00:27:47 +00:00
|
|
|
public function testExceptionThrownByGuzzle()
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->repository->shouldReceive('setServer')->with($this->server)->once()->andThrow($this->exception);
|
2017-07-23 19:51:18 +00:00
|
|
|
|
2018-01-06 00:27:47 +00:00
|
|
|
$this->service->handle($this->server);
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
}
|