Skip to content

Commit 10be4d0

Browse files
committed
creditCorrection and infoUser functions added
1 parent bfb8ff0 commit 10be4d0

File tree

5 files changed

+94
-34
lines changed

5 files changed

+94
-34
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
/debian/php-subreg.substvars
77
/debian/debhelper-build-stamp
88
/tests/.phpunit.result.cache
9-
/.phpunit.result.cache
9+
/.phpunit.result.cache
10+
/.phpunit.cache/
11+
/nbproject/

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
php-spojenet-subreg (1.1.0) UNRELEASED; urgency=medium
2+
3+
* creditCorrection and infoUser functions added
4+
5+
-- vitex <info@vitexsoftware.cz> Thu, 25 Jan 2024 20:24:48 +0100
6+
17
php-spojenet-subreg (1.0) unstable; urgency=medium
28

39
* new support for Pricelist command

phpunit.xml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" bootstrap="./testing/bootstrap.php">
3-
<testsuites>
4-
<testsuite name="all">
5-
<directory>./tests</directory>
6-
</testsuite>
7-
</testsuites>
8-
9-
<filter>
10-
<whitelist>
11-
<directory suffix=".php">src/Subreg</directory>
12-
</whitelist>
13-
</filter>
14-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<coverage/>
4+
<testsuites>
5+
<testsuite name="all">
6+
<directory>./tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
<source>
10+
<include>
11+
<directory suffix=".php">src/Subreg</directory>
12+
</include>
13+
</source>
1514
</phpunit>

src/Subreg/Client.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Subreg - Usage Example
55
*
66
* @author Vítězslav Dvořák <info@vitexsoftware.cz>
7-
* @copyright (C) 2018,2023 Spoje.Net
7+
* @copyright (C) 2018,2023-2024 Spoje.Net
88
*/
99

1010
namespace Subreg;
@@ -44,7 +44,7 @@ class Client extends \Ease\Molecule
4444

4545
/**
4646
* Last call status code
47-
* @var string|null ok|error
47+
* @var array|string|null ok|error
4848
*/
4949
public $lastStatus = null;
5050

@@ -83,7 +83,7 @@ public function __construct($config)
8383
*
8484
* @param string $additions Additional note text
8585
*
86-
* @return boolean was logged ?
86+
* @return bool was logged ?
8787
*/
8888
public function logBanner($additions = null)
8989
{
@@ -152,7 +152,7 @@ public function logError($errorData)
152152
/**
153153
* Perform Login to Server
154154
*
155-
* @return boolean success
155+
* @return bool success
156156
*/
157157
public function login()
158158
{
@@ -298,4 +298,36 @@ public function renewDomain(string $domain, int $years = 1)
298298
{
299299
return $this->call('Make_Order', ['order' => ['domain' => $domain, 'params' => ['period' => $years], 'type' => 'Renew_Domain']]);
300300
}
301+
302+
/**
303+
* Credit_Correction
304+
*
305+
* Correct credit amount of your sub-users. The amount you specify in this
306+
* command will be added to current amount. Use negative values for
307+
* subtracting credit. Please note that currency will depend on current
308+
* user setting.
309+
*
310+
* @see https://subreg.cz/manual/?cmd=Credit_Correction
311+
*
312+
* @param string $username Credit Holder Username
313+
* @param int $amount 10 or -2
314+
* @param string $reason For example "Invoice settle"
315+
*/
316+
public function creditCorrection($username, $amount, $reason)
317+
{
318+
return $this->call(
319+
'Credit_Correction',
320+
['username' => $username, 'amount' => strval($amount), 'reason' => $reason]
321+
);
322+
}
323+
324+
/**
325+
* Retrieve single sub-user
326+
*
327+
* @param int $id ID of the user
328+
*/
329+
public function infoUser(int $id)
330+
{
331+
return $this->call('Info_User', ['id' => $id]);
332+
}
301333
}

tests/src/Subreg/ClientTest.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
class ClientTest extends \Test\Ease\MoleculeTest
99
{
10+
1011
/**
1112
* @var Client
1213
*/
@@ -19,6 +20,7 @@ class ClientTest extends \Test\Ease\MoleculeTest
1920
protected function setUp(): void
2021
{
2122
$this->object = new \Subreg\Client(\Ease\Shared::instanced()->configuration);
23+
$this->object->login();
2224
}
2325

2426
/**
@@ -40,11 +42,12 @@ public function testConstructor()
4042
{
4143
$classname = get_class($this->object);
4244
// Get mock, without the constructor being called
43-
$mock = $this->getMockBuilder($classname)
44-
->disableOriginalConstructor()
45-
->getMockForAbstractClass();
45+
$mock = $this->getMockBuilder($classname)
46+
->disableOriginalConstructor()
47+
->getMockForAbstractClass();
4648
$mock->__construct(\Ease\Shared::instanced()->configuration);
47-
$this->assertNotEmpty($mock->token);
49+
$this->assertArrayHasKey('login', $this->object->config);
50+
$this->assertInstanceOf('\SoapClient', $this->object->soaper);
4851
}
4952

5053
/**
@@ -60,13 +63,15 @@ public function testLogBanner()
6063
*/
6164
public function testCall()
6265
{
63-
$fail = $this->object->call('NonExist');
66+
$fail = $this->object->call('NonExist');
6467
$this->assertEquals(['error' => [
6568
'errormsg' => 'Invalid method called',
6669
'errorcode' => [
67-
'major' => '500', 'minor' => '107']
70+
'major' => '500',
71+
'minor' => '107'
72+
]
6873
]
69-
], $fail);
74+
], $fail);
7075
$success = $this->object->call('Get_Credit');
7176
$this->arrayHasKey(array_key_exists('credit', $success));
7277
}
@@ -88,16 +93,15 @@ public function testLogError()
8893
public function testLogin()
8994
{
9095
$this->assertTrue($this->object->login());
96+
$this->assertNotEmpty($this->object->token);
9197
}
9298

9399
/**
94100
* @covers Subreg\Client::checkDomain
95101
*/
96102
public function testCheckDomain()
97103
{
98-
$checkResult = $this->object->checkDomain('spoje.net');
99-
$this->assertTrue(array_key_exists('name', $checkResult) && array_key_exists('price',
100-
$checkResult));
104+
$this->assertIsArray($this->object->checkDomain('php-subreg.cz'));
101105
}
102106

103107
/**
@@ -107,7 +111,7 @@ public function testDomainsList()
107111
{
108112
$domainlist = $this->object->domainsList();
109113
$this->assertTrue(array_key_exists('domains', $domainlist) && array_key_exists('count',
110-
$domainlist));
114+
$domainlist));
111115
}
112116

113117
/**
@@ -124,21 +128,21 @@ public function testPricelist()
124128
*/
125129
public function testGetPricelist()
126130
{
127-
$pricelist = $this->object->getPricelist('???');
128-
$this->assertTrue(array_key_exists('cz', $pricelist));
131+
$pricelist = $this->object->getPricelist('MYPRICELIST');
132+
$this->assertTrue(array_key_exists('error', $pricelist));
129133
}
130134

131135
/**
132136
* @covers Subreg\Client::registerDomain
133137
*/
134138
public function testRegisterDomain()
135139
{
136-
$unexistentDomain = strtolower(\Ease\Sand::randomString()).'.cz';
140+
$unexistentDomain = strtolower(\Ease\Functions::randomString()) . '.cz';
137141

138142
$nsHosts = array("ns.spoje.net", "ns2.spoje.net");
139143

140144
$result = $this->object->registerDomain($unexistentDomain, 'G-000001',
141-
'G-000001', 'G-000001', 'ukulele', $nsHosts);
145+
'G-000001', 'G-000001', 'ukulele', $nsHosts);
142146

143147
$this->assertTrue(array_key_exists('orderid', $result));
144148
}
@@ -148,6 +152,23 @@ public function testRegisterDomain()
148152
*/
149153
public function testRenewDomain()
150154
{
151-
$this->assertArrayHasKey('orderid',$this->object->renewDomain('vitexsoftware.cz',1));
155+
$this->assertIsArray($this->object->renewDomain('php-subreg.cz', 1));
156+
}
157+
158+
/**
159+
* @covers Subreg\Client::creditCorrection
160+
*/
161+
public function testcreditCorrection()
162+
{
163+
$this->assertIsArray($this->object->creditCorrection('php-subreg', '+1', 'PHPUnit Test'));
164+
}
165+
166+
/**
167+
* @covers Subreg\Client::infoUser
168+
*/
169+
public function testinfoUser()
170+
{
171+
$userInfo = $this->object->infoUser(1); // Not Exists
172+
$this->assertTrue(array_key_exists('error', $userInfo));
152173
}
153174
}

0 commit comments

Comments
 (0)