diff --git a/src/Api/Operator/Database.php b/src/Api/Operator/Database.php index 817adec5..4b4d6202 100644 --- a/src/Api/Operator/Database.php +++ b/src/Api/Operator/Database.php @@ -78,7 +78,7 @@ public function getAll(?string $field, $value): array $response = $this->getBy('get-db', $field, $value); $items = []; foreach ((array) $response->xpath('//result') as $xmlResult) { - if ($xmlResult) { + if ($xmlResult && isset($xmlResult->id) && (int) $xmlResult->id > 0) { $items[] = new Struct\Info($xmlResult); } } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 1b2b1c5f..2efcf747 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -225,4 +225,13 @@ private function createUser(array $params): \PleskX\Api\Struct\Database\UserInfo return $user; } + + public function testGetAllForWebspaceWithNoDatabases() + { + $webspace = static::$webspace; + $databases = static::$client->database()->getAll('webspace-id', $webspace->id); + + $this->assertIsArray($databases); + $this->assertEmpty($databases); + } }