Skip to content

Commit a1f9fe7

Browse files
committed
Add tests for Service Plan Addons
1 parent 2ea3564 commit a1f9fe7

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

src/Api/Operator/ServicePlanAddon.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
2-
// Copyright 1999-2022. Plesk International GmbH.
2+
// Copyright 1999-2023. Plesk International GmbH.
33

44
namespace PleskX\Api\Operator;
55

66
use PleskX\Api\Struct\ServicePlanAddon as Struct;
77

88
class ServicePlanAddon extends \PleskX\Api\Operator
99
{
10-
1110
public function create(array $properties): Struct\Info
1211
{
1312
$response = $this->request(['add' => $properties]);

tests/AbstractTestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ abstract class AbstractTestCase extends TestCase
1313

1414
private static array $webspaces = [];
1515
private static array $servicePlans = [];
16+
private static array $servicePlanAddons = [];
1617

1718
public static function setUpBeforeClass(): void
1819
{
@@ -54,6 +55,14 @@ public static function tearDownAfterClass(): void
5455
} catch (\Exception $e) {
5556
}
5657
}
58+
59+
foreach (self::$servicePlanAddons as $servicePlanAddon) {
60+
try {
61+
static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
62+
// phpcs:ignore
63+
} catch (\Exception $e) {
64+
}
65+
}
5766
}
5867

5968
protected static function getIpAddress(): string
@@ -91,4 +100,14 @@ protected static function createServicePlan(): \PleskX\Api\Struct\ServicePlan\In
91100

92101
return $servicePlan;
93102
}
103+
104+
protected static function createServicePlanAddon(): \PleskX\Api\Struct\ServicePlanAddon\Info
105+
{
106+
$id = uniqid();
107+
$servicePlanAddon = static::$client->servicePlanAddon()->create(['name' => "test{$id}planaddon"]);
108+
109+
self::$servicePlanAddons[] = $servicePlanAddon;
110+
111+
return $servicePlanAddon;
112+
}
94113
}

tests/ServicePlanAddonTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
// Copyright 1999-2023. Plesk International GmbH.
3+
4+
namespace PleskXTest;
5+
6+
class ServicePlanAddonTest extends AbstractTestCase
7+
{
8+
public function testGet()
9+
{
10+
$servicePlanAddon = static::createServicePlanAddon();
11+
$servicePlanAddonInfo = static::$client->servicePlanAddon()->get('id', $servicePlanAddon->id);
12+
13+
$this->assertNotEmpty($servicePlanAddonInfo->name);
14+
$this->assertSame($servicePlanAddon->id, $servicePlanAddonInfo->id);
15+
}
16+
17+
public function testGetAll()
18+
{
19+
static::createServicePlanAddon();
20+
static::createServicePlanAddon();
21+
static::createServicePlanAddon();
22+
23+
$servicePlanAddons = static::$client->servicePlanAddon()->getAll();
24+
$this->assertIsArray($servicePlanAddons);
25+
$this->assertGreaterThan(2, count($servicePlanAddons));
26+
$this->assertNotEmpty($servicePlanAddons[0]->name);
27+
}
28+
29+
public function testCreate()
30+
{
31+
$servicePlanAddon = static::createServicePlanAddon();
32+
$this->assertGreaterThan(0, $servicePlanAddon->id);
33+
34+
static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
35+
}
36+
37+
public function testDelete()
38+
{
39+
$servicePlanAddon = static::createServicePlanAddon();
40+
$result = static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
41+
42+
$this->assertTrue($result);
43+
}
44+
45+
public function testCreateComplex()
46+
{
47+
$properties = [
48+
'name' => 'Complex Service Plan Addon',
49+
'limits' => [
50+
'limit' => [
51+
'name' => 'disk_space',
52+
'value' => 1024 * 1024 * 1024, // 1 GB
53+
],
54+
],
55+
];
56+
57+
$servicePlanAddon = static::$client->servicePlanAddon()->create($properties);
58+
$this->assertGreaterThan(0, $servicePlanAddon->id);
59+
60+
static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
61+
}
62+
}

0 commit comments

Comments
 (0)