Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Api/Operator/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ public function getAll(?string $field, $value): array
$response = $this->getBy('get-db', $field, $value);
$items = [];
foreach ((array) $response->xpath('//result') as $xmlResult) {
if ($xmlResult) {
$items[] = new Struct\Info($xmlResult);
if (!$xmlResult) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three conditions in one if operator, plz

continue;
}

if (!isset($xmlResult->id) || (int) $xmlResult->id <= 0) {
continue;
}

$items[] = new Struct\Info($xmlResult);
}

return $items;
Expand Down
11 changes: 11 additions & 0 deletions tests/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,15 @@ private function createUser(array $params): \PleskX\Api\Struct\Database\UserInfo

return $user;
}

public function testGetAllForWebspaceWithNoDatabases()
{
$webspace = static::createWebspace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails because you are trying to create a second webspace, and the license doesn't allow it. The first one is already created in the precondition and available through the static::$webspace variable.

$databases = static::$client->database()->getAll('webspace-id', $webspace->id);

$this->assertIsArray($databases);
$this->assertEmpty($databases);

static::$client->webspace()->delete('id', $webspace->id);
}
}
Loading