Skip to content

Commit 9161910

Browse files
committed
Final test before PR from hell.
1 parent b602ea1 commit 9161910

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Tests\Unit\Services\Eggs;
4+
5+
use Mockery as m;
6+
use Tests\TestCase;
7+
use Pterodactyl\Models\Egg;
8+
use Pterodactyl\Services\Eggs\EggConfigurationService;
9+
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
10+
11+
class EggConfigurationServiceTest extends TestCase
12+
{
13+
/**
14+
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface|\Mockery\Mock
15+
*/
16+
protected $repository;
17+
18+
/**
19+
* @var \Pterodactyl\Services\Eggs\EggConfigurationService
20+
*/
21+
protected $service;
22+
23+
/**
24+
* Setup tests.
25+
*/
26+
public function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->repository = m::mock(EggRepositoryInterface::class);
31+
32+
$this->service = new EggConfigurationService($this->repository);
33+
}
34+
35+
/**
36+
* Test that the correct array is returned.
37+
*/
38+
public function testCorrectArrayIsReturned()
39+
{
40+
$egg = factory(Egg::class)->make([
41+
'config_startup' => '{"test": "start"}',
42+
'config_stop' => 'test',
43+
'config_files' => '{"test": "file"}',
44+
'config_logs' => '{"test": "logs"}',
45+
]);
46+
47+
$response = $this->service->handle($egg);
48+
$this->assertNotEmpty($response);
49+
$this->assertTrue(is_array($response), 'Assert response is an array.');
50+
$this->assertArrayHasKey('startup', $response);
51+
$this->assertArrayHasKey('stop', $response);
52+
$this->assertArrayHasKey('configs', $response);
53+
$this->assertArrayHasKey('log', $response);
54+
$this->assertArrayHasKey('query', $response);
55+
$this->assertEquals('start', object_get($response['startup'], 'test'));
56+
$this->assertEquals('test', 'test');
57+
$this->assertEquals('file', object_get($response['configs'], 'test'));
58+
$this->assertEquals('logs', object_get($response['log'], 'test'));
59+
$this->assertEquals('none', $response['query']);
60+
}
61+
62+
/**
63+
* Test that an integer referencing a model can be passed in place of the model.
64+
*/
65+
public function testFunctionHandlesIntegerPassedInPlaceOfModel()
66+
{
67+
$egg = factory(Egg::class)->make([
68+
'config_startup' => '{"test": "start"}',
69+
'config_stop' => 'test',
70+
'config_files' => '{"test": "file"}',
71+
'config_logs' => '{"test": "logs"}',
72+
]);
73+
74+
$this->repository->shouldReceive('getWithCopyAttributes')->with($egg->id)->once()->andReturn($egg);
75+
76+
$response = $this->service->handle($egg->id);
77+
$this->assertNotEmpty($response);
78+
$this->assertTrue(is_array($response), 'Assert response is an array.');
79+
$this->assertArrayHasKey('startup', $response);
80+
$this->assertArrayHasKey('stop', $response);
81+
$this->assertArrayHasKey('configs', $response);
82+
$this->assertArrayHasKey('log', $response);
83+
$this->assertArrayHasKey('query', $response);
84+
$this->assertEquals('start', object_get($response['startup'], 'test'));
85+
$this->assertEquals('test', 'test');
86+
$this->assertEquals('file', object_get($response['configs'], 'test'));
87+
$this->assertEquals('logs', object_get($response['log'], 'test'));
88+
$this->assertEquals('none', $response['query']);
89+
}
90+
}

0 commit comments

Comments
 (0)