Skip to content

Commit a00b0c0

Browse files
committed
Add method to get Pricelist
Release 0.3
1 parent 2a5d3c3 commit a00b0c0

File tree

11 files changed

+147
-39
lines changed

11 files changed

+147
-39
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
/debian/php-subreg/
55
/debian/php-subreg.debhelper.log
66
/debian/php-subreg.substvars
7-
/debian/debhelper-build-stamp
7+
/debian/debhelper-build-stamp
8+
/tests/.phpunit.result.cache
9+
/.phpunit.result.cache

Examples/GetPriceList.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Subreg - RegisterDomain Example
4+
*
5+
* @author Vítězslav Dvořák <[email protected]>
6+
* @copyright (C) 2019 Spoje.Net
7+
*/
8+
9+
namespace Subreg;
10+
11+
require_once '../vendor/autoload.php';
12+
13+
\Ease\Shared::instanced()->loadConfig('../config.json');
14+
15+
$client = new Client(\Ease\Shared::instanced()->configuration);
16+
17+
18+
19+
print_r($client->pricelist());
20+

debian/changelog

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
php-subreg (0.2-1) UNRELEASED; urgency=medium
1+
php-subreg (0.3) unstable; urgency=medium
22

3-
* debianized
3+
* new support for Pricelist command
44

5-
-- Vítězslav Dvořák <[email protected]> Mon, 04 Mar 2019 00:01:29 +0100
5+
-- Vítězslav Dvořák <[email protected]> Wed, 29 May 2019 16:21:24 +0200

debian/files

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
php-subreg_0.2-1_all.buildinfo web optional
2-
php-subreg_0.2-1_all.deb web optional
1+
php-subreg_0.3_all.buildinfo web optional
2+
php-subreg_0.3_all.deb web optional

debian/fixversion.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VERSTR=`dpkg-parsechangelog --show-field Version`
33
COMPOSER_VERSTR=`echo ${VERSTR}|sed 's/-/./g'`
44
echo update debian/php-subreg/usr/share/php/Subreg/composer.json version to ${COMPOSER_VERSTR}
55
sed -i -e '/\"version\"/c\ \"version\": \"'${COMPOSER_VERSTR}'",' debian/php-subreg/usr/share/php/Ease/composer.json
6-
echo Update debian/php-subreg/usr/share/php/Ease/Atom.php version to ${VERSTR}
7-
sed -i -e "/static public \$libVersion/c\ static public \$frameworkVersion = '${VERSTR}';" debian/php-subreg/usr/share/php/Subreg/Client.php
6+
echo Update debian/php-subreg/usr/share/php/Subreg/Client.php version to ${VERSTR}
7+
sed -i -e "/static public \$libVersion/c\ static public \$libVersion = '${VERSTR}';" debian/php-subreg/usr/share/php/Subreg/Client.php
88
echo Update src/Ease/Atom.php version to ${VERSTR}
9-
sed -i -e "/static public \$libVersion/c\ static public \$frameworkVersion = '${VERSTR}';" src/Subreg/Client.php
9+
sed -i -e "/static public \$libVersion/c\ static public \$libVersion = '${VERSTR}';" src/Subreg/Client.php

nbproject/project.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_create_2e_tests=false
1+
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_create_2e_tests=true
22
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_enabled=true
33
auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_path=tests/bootstrap.php
44
auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_enabled=true
5-
auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_path=tests/configuration.xml
5+
auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_path=phpunit.xml
66
auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_enabled=false
77
auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_path=
8-
auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_enabled=false
9-
auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_path=
8+
auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_enabled=true
9+
auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_path=vendor/bin/phpunit
1010
auxiliary.org-netbeans-modules-php-phpunit.test_2e_groups_2e_ask=false
1111
auxiliary.org-netbeans-modules-php-phpunit.test_2e_run_2e_all=false
1212
auxiliary.org-netbeans-modules-php-phpunit.test_2e_run_2e_phpunit_2e_only=false

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit colors="true" bootstrap="./testing/bootstrap.php">
33
<testsuites>
44
<testsuite name="all">
5-
<directory>./testing</directory>
5+
<directory>./tests</directory>
66
</testsuite>
77
</testsuites>
88

src/Subreg/Client.php

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Client extends \Ease\Molecule
1919
* ClientLibrary version
2020
* @var string
2121
*/
22-
static public $frameworkVersion = '0.1';
22+
static public $libVersion = '0.3';
2323

2424
/**
2525
* Object Configuration
@@ -74,6 +74,20 @@ public function __construct($config)
7474
$this->login();
7575
}
7676

77+
/**
78+
* Add Info about used user, server and libraries
79+
*
80+
* @param string $additions Additional note text
81+
*
82+
* @return boolean was logged ?
83+
*/
84+
public function logBanner($additions = null)
85+
{
86+
return $this->addStatusMessage('API '.str_replace('://',
87+
'://'.$this->config['login'].'@', $this->config['uri']).' php-subreg v'.self::$libVersion.' EasePHP Framework v'.\Ease\Atom::$frameworkVersion.' '.$additions,
88+
'debug');
89+
}
90+
7791
/**
7892
* API Call
7993
*
@@ -92,19 +106,24 @@ public function call($command, $params = [])
92106
}
93107
$responseRaw = $this->soaper->__call($command, ['data' => $params]);
94108

109+
95110
if (isset($responseRaw['status'])) {
96111
$this->lastStatus = $responseRaw['status'];
97-
if ($this->lastStatus == 'error') {
98-
$this->logError($responseRaw['error']);
112+
switch ($responseRaw['status']) {
113+
case 'ok':
114+
if (array_key_exists('data', $responseRaw)) {
115+
$this->lastResult = $responseRaw['data'];
116+
} else {
117+
$this->lastResult = $this->lastStatus;
118+
}
119+
break;
120+
case 'error':
121+
$this->logError($responseRaw['error']);
122+
$this->lastResult = ['error' => $responseRaw['error']];
123+
break;
99124
}
100125
}
101126

102-
if (array_key_exists('data', $responseRaw)) {
103-
$this->lastResult = $responseRaw['data'];
104-
} else {
105-
$this->lastResult = $this->lastStatus;
106-
}
107-
108127
return $this->lastResult;
109128
}
110129

@@ -222,4 +241,16 @@ public function domainsList()
222241
{
223242
return $this->call('Domains_List');
224243
}
244+
245+
/**
246+
* Get pricelist from your account
247+
*
248+
* @link https://subreg.cz/manual/?cmd=Pricelist Command: Pricelist
249+
*
250+
* @return array
251+
*/
252+
public function pricelist()
253+
{
254+
return $this->call('Pricelist');
255+
}
225256
}

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
define('EASE_LOGGER', 'syslog');
2525
}
2626

27-
\Ease\Shared::instanced()->loadConfig('../config.json',true);
27+
\Ease\Shared::instanced()->loadConfig('config.json',true);
2828

tests/configuration.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/src/Subreg/ClientTest.php

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,107 @@ protected function tearDown(): void
3030

3131
}
3232

33+
/**
34+
* Test Constructor
35+
*
36+
* @depends testLogBanner
37+
* @covers Subreg\Client::__construct
38+
*/
39+
public function testConstructor()
40+
{
41+
$classname = get_class($this->object);
42+
// Get mock, without the constructor being called
43+
$mock = $this->getMockBuilder($classname)
44+
->disableOriginalConstructor()
45+
->getMockForAbstractClass();
46+
$mock->__construct(\Ease\Shared::instanced()->configuration);
47+
$this->assertNotEmpty($mock->token);
48+
}
49+
50+
/**
51+
* @covers Subreg\Client::logBanner
52+
*/
53+
public function testLogBanner()
54+
{
55+
$this->assertTrue($this->object->logBanner(addslashes(get_class($this))));
56+
}
57+
3358
/**
3459
* @covers Subreg\Client::call
3560
*/
3661
public function testCall()
3762
{
38-
$this->object->call('Get_Credit');
63+
$fail = $this->object->call('NonExist');
64+
$this->assertEquals(['error' => [
65+
'errormsg' => 'Invalid method called',
66+
'errorcode' => [
67+
'major' => '500', 'minor' => '107']
68+
]
69+
], $fail);
70+
$success = $this->object->call('Get_Credit');
71+
$this->arrayHasKey(array_key_exists('credit', $success));
3972
}
4073

4174
/**
4275
* @covers Subreg\Client::logError
4376
*/
4477
public function testLogError()
4578
{
46-
$this->object->logError(['errorcode' => ['major' => 999, 'minor' => 000],
47-
'errormsg' => 'some error message']);
79+
$error = ['errorcode' => ['major' => 999, 'minor' => 000],
80+
'errormsg' => 'some error message'];
81+
$this->object->logError($error);
82+
$this->assertEquals($error, $this->object->lastError);
4883
}
4984

5085
/**
5186
* @covers Subreg\Client::login
5287
*/
5388
public function testLogin()
5489
{
55-
$this->object->login();
90+
$this->assertTrue($this->object->login());
5691
}
5792

5893
/**
5994
* @covers Subreg\Client::checkDomain
6095
*/
6196
public function testCheckDomain()
6297
{
63-
return $this->object->checkDomain('spoje.net');
98+
$checkResult = $this->object->checkDomain('spoje.net');
99+
$this->assertTrue(array_key_exists('name', $checkResult) && array_key_exists('price',
100+
$checkResult));
64101
}
65102

66103
/**
67-
* @covers Subreg\Client::domainList
104+
* @covers Subreg\Client::domainsList
68105
*/
69106
public function testDomainsList()
70107
{
71-
return $this->object->domainsList();
108+
$domainlist = $this->object->domainsList();
109+
$this->assertTrue(array_key_exists('domains', $domainlist) && array_key_exists('count',
110+
$domainlist));
111+
}
112+
113+
/**
114+
* @covers Subreg\Client::pricelist
115+
*/
116+
public function testPricelist()
117+
{
118+
$pricelist = $this->object->pricelist();
119+
$this->assertTrue(array_key_exists('cz', $pricelist));
120+
}
121+
122+
/**
123+
* @covers Subreg\Client::registerDomain
124+
*/
125+
public function testRegisterDomain()
126+
{
127+
$unexistentDomain = strtolower(\Ease\Sand::randomString()).'.cz';
128+
129+
$nsHosts = array("ns.spoje.net", "ns2.spoje.net");
130+
131+
$result = $this->object->registerDomain($unexistentDomain, 'G-000001',
132+
'G-000001', 'G-000001', 'ukulele', $nsHosts);
133+
134+
$this->assertTrue( array_key_exists('orderid', $result));
72135
}
73136
}

0 commit comments

Comments
 (0)