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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
|
||||
class DatabaseRepository extends EloquentRepository implements DatabaseRepositoryInterface
|
||||
|
@ -67,13 +67,13 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
public function createIfNotExists(array $data)
|
||||
{
|
||||
$instance = $this->getBuilder()->where([
|
||||
['server_id', $data['server_id']],
|
||||
['database_host_id', $data['database_host_id']],
|
||||
['database', $data['database']],
|
||||
['server_id', '=', array_get($data, 'server_id')],
|
||||
['database_host_id', '=', array_get($data, 'database_host_id')],
|
||||
['database', '=', array_get($data, 'database')],
|
||||
])->count();
|
||||
|
||||
if ($instance > 0) {
|
||||
throw new DisplayException('A database with those details already exists for the specified server.');
|
||||
throw new DuplicateDatabaseNameException('A database with those details already exists for the specified server.');
|
||||
}
|
||||
|
||||
return $this->create($data);
|
||||
|
|
|
@ -49,6 +49,7 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @todo remove this, do logic in service
|
||||
*/
|
||||
public function deleteIfNoNodes($id)
|
||||
{
|
||||
|
|
Reference in a new issue