Skip to content

Commit f6c144d

Browse files
committed
Unify service plan creation interface with other operators
1 parent 80b5aa9 commit f6c144d

File tree

3 files changed

+42
-48
lines changed

3 files changed

+42
-48
lines changed

src/Api/Operator/ServicePlan.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,44 @@
88
class ServicePlan extends \PleskX\Api\Operator
99
{
1010
/**
11-
* @param string $field
12-
* @param int|string $value
13-
*
11+
* @param array $properties
1412
* @return Struct\Info
1513
*/
16-
public function get($field, $value)
14+
public function create($properties)
1715
{
18-
$items = $this->_get($field, $value);
19-
20-
return reset($items);
16+
$response = $this->request(['add' => $properties]);
17+
return new Struct\Info($response);
2118
}
2219

2320
/**
24-
* @return Struct\Info[]
21+
* @param string $field
22+
* @param int|string $value
23+
* @return bool
2524
*/
26-
public function getAll()
25+
public function delete($field, $value)
2726
{
28-
return $this->_get();
27+
return $this->_delete($field, $value);
2928
}
3029

3130
/**
32-
* @param string $planName
31+
* @param string $field
32+
* @param int|string $value
33+
*
3334
* @return Struct\Info
3435
*/
35-
public function create($planName)
36+
public function get($field, $value)
3637
{
37-
$packet = $this->_client->getPacket();
38-
$info = $packet->addChild($this->_wrapperTag)->addChild('add');
39-
$info->addChild('name', $planName);
38+
$items = $this->_get($field, $value);
4039

41-
$response = $this->_client->request($packet);
42-
return new Struct\Info($response);
40+
return reset($items);
4341
}
4442

4543
/**
46-
* @param string $field
47-
* @param int|string $value
48-
* @return bool
44+
* @return Struct\Info[]
4945
*/
50-
public function delete($field, $value)
46+
public function getAll()
5147
{
52-
return $this->_delete($field, $value);
48+
return $this->_get();
5349
}
5450

5551
/**

tests/ServicePlanTest.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,36 @@ public function testDelete()
4343
$this->assertTrue($result);
4444
}
4545

46-
public function testRequestCreateServicePlan()
46+
public function testCreateComplexServicePlan()
4747
{
48-
$request = [
49-
'add' => [
50-
'name' => 'Service Plan Full Test',
51-
'limits' => [
52-
'overuse' => 'block',
48+
$properties = [
49+
'name' => 'Complex Service Plan',
50+
'limits' => [
51+
'overuse' => 'block',
52+
'limit' => [
53+
'name' => 'disk_space',
54+
'value' => 1024*1024*1024, // 1 GB
5355
],
54-
'preferences' => [
55-
'stat' => 6,
56-
'maillists' => 'true',
57-
],
58-
'hosting' => [
59-
'property' => [
60-
[
61-
'name' => 'ftp_quota',
62-
'value' => '-1',
63-
],
64-
[
65-
'name' => 'ssl',
66-
'value' => 'true',
67-
],
56+
],
57+
'preferences' => [
58+
'stat' => 6,
59+
'maillists' => 'true',
60+
],
61+
'hosting' => [
62+
'property' => [
63+
[
64+
'name' => 'ftp_quota',
65+
'value' => '-1',
66+
],
67+
[
68+
'name' => 'ssl',
69+
'value' => 'true',
6870
],
69-
],
70-
'performance' => [
71-
'bandwidth' => 1000,
72-
'max_connections' => 20,
7371
],
7472
],
7573
];
7674

77-
$servicePlan = static::$_client->servicePlan()->request($request);
75+
$servicePlan = static::$_client->servicePlan()->create($properties);
7876
$this->assertGreaterThan(0, $servicePlan->id);
7977

8078
static::$_client->servicePlan()->delete('id', $servicePlan->id);

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected static function _createWebspace()
8686
protected static function _createServicePlan()
8787
{
8888
$id = uniqid();
89-
$servicePlan = static::$_client->servicePlan()->create("test{$id}plan");
89+
$servicePlan = static::$_client->servicePlan()->create(['name' => "test{$id}plan"]);
9090

9191
self::$servicePlans[] = $servicePlan;
9292

0 commit comments

Comments
 (0)