Fix tests
This commit is contained in:
parent
3bb9bf04e5
commit
c6112b4234
2 changed files with 10 additions and 44 deletions
|
@ -1,11 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Pterodactyl - Panel
|
|
||||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
||||||
*
|
|
||||||
* This software is licensed under the terms of the MIT license.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Pterodactyl\Services\Nodes;
|
namespace Pterodactyl\Services\Nodes;
|
||||||
|
|
||||||
|
@ -57,7 +50,7 @@ class NodeUpdateService
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Models\Node $node
|
* @param \Pterodactyl\Models\Node $node
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return \Pterodactyl\Models\Node|mixed
|
* @return \Pterodactyl\Models\Node
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Pterodactyl - Panel
|
|
||||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
||||||
*
|
|
||||||
* This software is licensed under the terms of the MIT license.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Tests\Unit\Services\Nodes;
|
namespace Tests\Unit\Services\Nodes;
|
||||||
|
|
||||||
|
@ -63,17 +56,17 @@ class NodeUpdateServiceTest extends TestCase
|
||||||
->expects($this->once())->willReturn('random_string');
|
->expects($this->once())->willReturn('random_string');
|
||||||
|
|
||||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
$this->repository->shouldReceive('update')->with($model->id, [
|
||||||
'name' => 'NewName',
|
'name' => 'NewName',
|
||||||
'daemonSecret' => 'random_string',
|
'daemonSecret' => 'random_string',
|
||||||
])->andReturn(true);
|
])->andReturn($model);
|
||||||
|
|
||||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
||||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||||
|
|
||||||
$response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
|
$response = $this->getService()->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
|
||||||
$this->assertTrue($response);
|
$this->assertInstanceOf(Node::class, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,37 +76,17 @@ class NodeUpdateServiceTest extends TestCase
|
||||||
{
|
{
|
||||||
$model = factory(Node::class)->make();
|
$model = factory(Node::class)->make();
|
||||||
|
|
||||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
|
||||||
'name' => 'NewName',
|
|
||||||
])->andReturn(true);
|
|
||||||
|
|
||||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
|
||||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
|
||||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
|
||||||
|
|
||||||
$response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName']);
|
|
||||||
$this->assertTrue($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdatedModelIsReturned()
|
|
||||||
{
|
|
||||||
$model = factory(Node::class)->make();
|
|
||||||
$updated = clone $model;
|
|
||||||
$updated->name = 'NewName';
|
|
||||||
|
|
||||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||||
$this->repository->shouldReceive('update')->with($model->id, [
|
$this->repository->shouldReceive('update')->with($model->id, [
|
||||||
'name' => $updated->name,
|
'name' => 'NewName',
|
||||||
])->andReturn($updated);
|
])->andReturn($model);
|
||||||
|
|
||||||
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
|
||||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||||
|
|
||||||
$response = $this->getService()->returnUpdatedModel()->handle($model, ['name' => $updated->name]);
|
$response = $this->getService()->handle($model, ['name' => 'NewName']);
|
||||||
$this->assertInstanceOf(Node::class, $response);
|
$this->assertInstanceOf(Node::class, $response);
|
||||||
$this->assertSame($updated, $response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +100,7 @@ class NodeUpdateServiceTest extends TestCase
|
||||||
$model = factory(Node::class)->make();
|
$model = factory(Node::class)->make();
|
||||||
|
|
||||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response);
|
$this->repository->shouldReceive('update')->andReturn($model);
|
||||||
|
|
||||||
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
|
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
|
||||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||||
|
@ -146,7 +119,7 @@ class NodeUpdateServiceTest extends TestCase
|
||||||
$model = factory(Node::class)->make();
|
$model = factory(Node::class)->make();
|
||||||
|
|
||||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||||
$this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response);
|
$this->repository->shouldReceive('update')->andReturn($model);
|
||||||
|
|
||||||
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
|
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue