Begin unit tests for repositories

This commit is contained in:
Dane Everitt 2017-08-26 19:58:24 -05:00
parent 72735c24f7
commit f451e4dc47
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
18 changed files with 734 additions and 43 deletions

View file

@ -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);