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

73 lines
1.9 KiB
PHP
Raw Normal View History

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