2017-08-16 03:21:47 +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-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Services;
|
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Tests\TestCase;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Services\Services\NestUpdateService;
|
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
|
|
|
class ServiceUpdateServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Services\Services\NestUpdateService
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
$this->repository = m::mock(NestRepositoryInterface::class);
|
2017-08-16 03:21:47 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
$this->service = new NestUpdateService($this->repository);
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the author key is removed from the data array before updating the record.
|
|
|
|
*/
|
|
|
|
public function testAuthorArrayKeyIsRemovedIfPassed()
|
|
|
|
{
|
|
|
|
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
|
|
|
->shouldReceive('update')->with(1, ['otherfield' => 'value'])->once()->andReturnNull();
|
|
|
|
|
|
|
|
$this->service->handle(1, ['author' => 'author1', 'otherfield' => 'value']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the function continues to work when no author key is passed.
|
|
|
|
*/
|
|
|
|
public function testServiceIsUpdatedWhenNoAuthorKeyIsPassed()
|
|
|
|
{
|
|
|
|
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
|
|
|
->shouldReceive('update')->with(1, ['otherfield' => 'value'])->once()->andReturnNull();
|
|
|
|
|
|
|
|
$this->service->handle(1, ['otherfield' => 'value']);
|
|
|
|
}
|
|
|
|
}
|