Begin unit tests for repositories
This commit is contained in:
parent
72735c24f7
commit
f451e4dc47
18 changed files with 734 additions and 43 deletions
|
@ -26,7 +26,6 @@ namespace Pterodactyl\Repositories\Eloquent;
|
|||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
||||
|
||||
|
@ -48,6 +47,9 @@ class DatabaseHostRepository extends EloquentRepository implements DatabaseHostR
|
|||
return $this->getBuilder()->withCount('databases')->with('node')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getWithServers($id)
|
||||
{
|
||||
Assert::numeric($id, 'First argument passed to getWithServers must be numeric, recieved %s.');
|
||||
|
@ -59,23 +61,4 @@ class DatabaseHostRepository extends EloquentRepository implements DatabaseHostR
|
|||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteIfNoDatabases($id)
|
||||
{
|
||||
Assert::numeric($id, 'First argument passed to deleteIfNoDatabases must be numeric, recieved %s.');
|
||||
|
||||
$instance = $this->getBuilder()->withCount('databases')->find($id);
|
||||
if (! $instance) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
|
||||
if ($instance->databases_count > 0) {
|
||||
throw new DisplayException('Cannot delete a database host that has active databases attached to it.');
|
||||
}
|
||||
|
||||
return $instance->delete();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue