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-08 04:29:08 +00:00
|
|
|
use Pterodactyl\Services\Nests\NestUpdateService;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
2017-10-08 04:29:08 +00:00
|
|
|
class NestUpdateServiceTest extends TestCase
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-10-08 04:29:08 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface|\Mockery\Mock
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-10-08 04:29:08 +00:00
|
|
|
* @var \Pterodactyl\Services\Nests\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()
|
|
|
|
{
|
2018-01-05 22:33:50 +00:00
|
|
|
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
2017-08-16 03:21:47 +00:00
|
|
|
->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()
|
|
|
|
{
|
2018-01-05 22:33:50 +00:00
|
|
|
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
2017-08-16 03:21:47 +00:00
|
|
|
->shouldReceive('update')->with(1, ['otherfield' => 'value'])->once()->andReturnNull();
|
|
|
|
|
|
|
|
$this->service->handle(1, ['otherfield' => 'value']);
|
|
|
|
}
|
|
|
|
}
|