2017-08-05 22:20:07 +00:00
|
|
|
<?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
|
2017-08-05 22:20:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Nodes;
|
|
|
|
|
|
|
|
use Mockery as m;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Tests\TestCase;
|
2017-08-05 22:20:07 +00:00
|
|
|
use phpmock\phpunit\PHPMock;
|
2017-08-27 20:10:51 +00:00
|
|
|
use Pterodactyl\Services\Nodes\NodeCreationService;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
2017-08-05 22:20:07 +00:00
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class NodeCreationServiceTest extends TestCase
|
2017-08-05 22:20:07 +00:00
|
|
|
{
|
|
|
|
use PHPMock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-08-27 20:10:51 +00:00
|
|
|
* @var \Pterodactyl\Services\Nodes\NodeCreationService
|
2017-08-05 22:20:07 +00:00
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2017-08-05 22:20:07 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->repository = m::mock(NodeRepositoryInterface::class);
|
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
$this->service = new NodeCreationService($this->repository);
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a node is created and a daemon secret token is created.
|
|
|
|
*/
|
|
|
|
public function testNodeIsCreatedAndDaemonSecretIsGenerated()
|
|
|
|
{
|
2017-09-14 04:07:02 +00:00
|
|
|
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'str_random')
|
|
|
|
->expects($this->once())->willReturn('random_string');
|
2017-08-05 22:20:07 +00:00
|
|
|
|
|
|
|
$this->repository->shouldReceive('create')->with([
|
|
|
|
'name' => 'NodeName',
|
2017-09-14 04:07:02 +00:00
|
|
|
'daemonSecret' => 'random_string',
|
2017-08-05 22:20:07 +00:00
|
|
|
])->once()->andReturnNull();
|
|
|
|
|
|
|
|
$this->assertNull($this->service->handle(['name' => 'NodeName']));
|
|
|
|
}
|
|
|
|
}
|