diff --git a/src/Api/Operator/DatabaseServer.php b/src/Api/Operator/DatabaseServer.php index 1d5247cb..e80e28b5 100644 --- a/src/Api/Operator/DatabaseServer.php +++ b/src/Api/Operator/DatabaseServer.php @@ -37,6 +37,19 @@ public function getAll(): array return $this->getBy(); } + public function getDefault(string $type): Struct\Info + { + $packet = $this->client->getPacket(); + $getTag = $packet->addChild($this->wrapperTag)->addChild('get-default'); + $filterTag = $getTag->addChild('filter'); + /** @psalm-suppress UndefinedPropertyAssignment */ + $filterTag->type = $type; + + $response = $this->client->request($packet); + + return new Struct\Info($response); + } + /** * @param string|null $field * @param int|string|null $value diff --git a/tests/DatabaseServerTest.php b/tests/DatabaseServerTest.php index 0865d665..61737252 100644 --- a/tests/DatabaseServerTest.php +++ b/tests/DatabaseServerTest.php @@ -26,4 +26,11 @@ public function testGetAll() $this->assertGreaterThan(0, count($dbServers)); $this->assertEquals('localhost', $dbServers[0]->host); } + + public function testGetDefault() + { + $dbServer = static::$client->databaseServer()->getDefault('mysql'); + $this->assertEquals('mysql', $dbServer->type); + $this->assertGreaterThan(0, $dbServer->id); + } } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 6fe19003..bb4a2f78 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -8,11 +8,13 @@ class DatabaseTest extends AbstractTestCase { private static \PleskX\Api\Struct\Webspace\Info $webspace; + private static \PleskX\Api\Struct\DatabaseServer\Info $databaseServer; public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); static::$webspace = static::createWebspace(); + static::$databaseServer = static::$client->databaseServer()->getDefault('mysql'); } public function testCreate() @@ -20,8 +22,8 @@ public function testCreate() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); static::$client->database()->delete('id', $database->id); } @@ -31,8 +33,8 @@ public function testCreateUser() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $user = $this->createUser([ 'db-id' => $database->id, @@ -48,8 +50,8 @@ public function testUpdateUser() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $user = $this->createUser([ 'db-id' => $database->id, @@ -71,15 +73,15 @@ public function testGetById() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $db = static::$client->database()->get('id', $database->id); $this->assertEquals('test1', $db->name); - $this->assertEquals('mysql', $db->type); + $this->assertEquals(static::$databaseServer->type, $db->type); $this->assertEquals(static::$webspace->id, $db->webspaceId); - $this->assertEquals(1, $db->dbServerId); + $this->assertEquals(static::$databaseServer->id, $db->dbServerId); static::$client->database()->delete('id', $database->id); } @@ -89,20 +91,20 @@ public function testGetAllByWebspaceId() $db1 = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $db2 = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test2', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $databases = static::$client->database()->getAll('webspace-id', static::$webspace->id); $this->assertEquals('test1', $databases[0]->name); $this->assertEquals('test2', $databases[1]->name); $this->assertEquals(static::$webspace->id, $databases[0]->webspaceId); - $this->assertEquals(1, $databases[1]->dbServerId); + $this->assertEquals(static::$databaseServer->id, $databases[1]->dbServerId); static::$client->database()->delete('id', $db1->id); static::$client->database()->delete('id', $db2->id); @@ -113,8 +115,8 @@ public function testGetUserById() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $user = $this->createUser([ @@ -136,14 +138,14 @@ public function testGetAllUsersByDbId() $db1 = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $db2 = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test2', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $user1 = $this->createUser([ 'db-id' => $db1->id, @@ -180,8 +182,8 @@ public function testDelete() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $result = static::$client->database()->delete('id', $database->id); $this->assertTrue($result); @@ -192,8 +194,8 @@ public function testDeleteUser() $database = $this->createDatabase([ 'webspace-id' => static::$webspace->id, 'name' => 'test1', - 'type' => 'mysql', - 'db-server-id' => 1, + 'type' => static::$databaseServer->type, + 'db-server-id' => static::$databaseServer->id, ]); $user = $this->createUser([ 'db-id' => $database->id,