Skip to content

Commit e240f02

Browse files
authored
Merge pull request #52 from mrsombre/fix-test-webspace
Fix test creating webspace with disabled PHP handler
2 parents 9908ec4 + 9cb9caf commit e240f02

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

tests/CustomerTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ public function testGetAll()
5858
]);
5959

6060
$customersInfo = static::$_client->customer()->getAll();
61-
$this->assertCount(2, $customersInfo);
62-
$this->assertEquals('John Smith', $customersInfo[0]->personalName);
63-
$this->assertEquals('customer-a', $customersInfo[0]->login);
61+
$this->assertIsArray($customersInfo);
62+
63+
$customersCheck = array_filter($customersInfo, function ($value) {
64+
return $value->personalName === 'John Smith' || $value->personalName === 'Mike Black';
65+
});
66+
$this->assertCount(2, $customersCheck);
6467

6568
static::$_client->customer()->delete('login', 'customer-a');
6669
static::$_client->customer()->delete('login', 'customer-b');

tests/WebspaceTest.php

+11-20
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ public function testDelete()
4646

4747
public function testRequestCreateWebspace()
4848
{
49-
$id = uniqid();
50-
$password = base64_encode(time());
51-
$name = "d{$id}.test";
52-
53-
$handler = static::$_client->phpHandler()->get(null, null);
49+
$handlers = static::$_client->phpHandler()->getAll();
50+
$enabledHandlers = array_filter($handlers, function ($handler) {
51+
return $handler->handlerStatus !== 'disabled';
52+
});
53+
$this->assertGreaterThan(0, count($enabledHandlers));
54+
$handler = current($enabledHandlers);
5455

5556
$request = [
5657
'add' => [
5758
'gen_setup' => [
58-
'name' => $name,
59+
'name' => 'webspace-test-full.test',
5960
'htype' => 'vrt_hst',
6061
'status' => '0',
6162
'ip_address' => [static::_getIpAddress()],
@@ -69,11 +70,11 @@ public function testRequestCreateWebspace()
6970
],
7071
[
7172
'name' => 'ftp_login',
72-
'value' => "u{$id}",
73+
'value' => 'testuser',
7374
],
7475
[
7576
'name' => 'ftp_password',
76-
'value' => $password,
77+
'value' => 'test-PWD*1',
7778
],
7879
],
7980
'ip_address' => static::_getIpAddress(),
@@ -120,17 +121,7 @@ public function testRequestCreateWebspace()
120121
],
121122
];
122123

123-
try {
124-
$webspace = static::$_client->webspace()->request($request);
125-
} catch (\Exception $e) {
126-
try {
127-
$webspaceInfo = static::$_client->webspace()->get('name', $name);
128-
static::$_client->webspace()->delete('guid', $webspaceInfo->guid);
129-
} catch (\Exception $e) {
130-
}
131-
132-
$this->fail($e->getMessage());
133-
}
124+
$webspace = static::$_client->webspace()->request($request);
134125

135126
$this->assertGreaterThan(0, $webspace->id);
136127

@@ -142,8 +133,8 @@ public function testGet()
142133
$webspace = static::_createWebspace();
143134
$webspaceInfo = static::$_client->webspace()->get('id', $webspace->id);
144135

136+
$this->assertInstanceOf(\PleskX\Api\Struct\Webspace\GeneralInfo::class, $webspaceInfo);
145137
$this->assertNotEmpty($webspaceInfo->name);
146138
$this->assertEquals(0, $webspaceInfo->realSize);
147-
148139
}
149140
}

0 commit comments

Comments
 (0)