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
6 changes: 5 additions & 1 deletion src/Api/Operator/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public function getAll(?string $field, $value): array
$items = [];
foreach ((array) $response->xpath('//result') as $xmlResult) {
if ($xmlResult) {
$items[] = new Struct\Info($xmlResult);
$info = new Struct\Info($xmlResult);
$vars = is_object($info) ? get_object_vars($info) : [];
Copy link
Member

Choose a reason for hiding this comment

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

The condition is always true. Plus, it's a very strange way of checking property existence. isset or property_exists should be more suitable.

if (!empty($vars['id']) && !empty($vars['name']) && !empty($vars['type'])) {
$items[] = $info;
}
}
}

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();
$databases = static::$client->database()->getAll('webspace-id', $webspace->id);

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

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