Skip to content

Commit e92adf8

Browse files
author
has.well
committed
update tests and test cases to php 8
1 parent 9f6d96a commit e92adf8

16 files changed

+135
-98
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
composer.lock
33
composer.phar
4-
/vendor/
4+
/vendor/
5+
*.cache

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ branches:
1515
only:
1616
master
1717
before_install:
18-
- composer install
18+
- travis_retry composer install --no-interaction --prefer-source
1919
script: vendor/bin/phpunit --bootstrap vendor/autoload.php tests

autoload.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require(dirname(__FILE__) . '/lib/Api/Order/Atol.php');
2121
require(dirname(__FILE__) . '/lib/Api/Order/Capture.php');
2222
require(dirname(__FILE__) . '/lib/Api/Order/Reverse.php');
23+
require(dirname(__FILE__) . '/lib/Api/Order/Settlements.php');
2324
require(dirname(__FILE__) . '/lib/Api/Order/Status.php');
2425
require(dirname(__FILE__) . '/lib/Api/Order/TransactionList.php');
2526
require(dirname(__FILE__) . '/lib/Api/P2pcredit/Credit.php');
@@ -51,4 +52,4 @@
5152
require(dirname(__FILE__) . '/lib/Response/PcidssResponse.php');
5253

5354
/** Result(callback) classes */
54-
require(dirname(__FILE__) . '/lib/Result/Result.php');
55+
require(dirname(__FILE__) . '/lib/Result/Result.php');

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"ext-json": "*"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "~4.8"
19+
"phpunit/phpunit": "~5|~8|~9"
2020
},
2121
"autoload": {
2222
"psr-4": {

examples/Order/capture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@
7474
<?php
7575
} catch (\Exception $e) {
7676
echo "Fail: " . $e->getMessage();
77-
}
77+
}

examples/configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
define('SDK_ROOTPATH', __DIR__);
1010
require_once SDK_ROOTPATH . '/../vendor/autoload.php';
1111
\Cloudipsp\Configuration::setMerchantId(1396424);
12-
\Cloudipsp\Configuration::setSecretKey('test');
12+
\Cloudipsp\Configuration::setSecretKey('test');

lib/HttpClient/HttpCurl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class HttpCurl implements ClientInterface
2525
* @param string $url
2626
* @param array $headers
2727
* @param array $params
28-
* @return array
28+
* @return string
2929
* @throws Exception\HttpClientException
3030
*/
31-
public function request($method, $url, $headers = [], $params)
31+
public function request($method, $url, $headers = [], $params = [])
3232
{
3333
$method = strtoupper($method);
3434
if (!$this->curlEnabled())
@@ -60,4 +60,4 @@ private function curlEnabled()
6060
{
6161
return function_exists('curl_init');
6262
}
63-
}
63+
}

tests/CheckoutTest.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ class CheckoutTest extends TestCase
3434
)
3535
];
3636

37+
/**
38+
* Setup config
39+
*/
3740
private function setTestConfig()
3841
{
39-
\Cloudipsp\Configuration::setMerchantId($this->mid);
40-
\Cloudipsp\Configuration::setSecretKey($this->secret_key);
41-
\Cloudipsp\Configuration::setApiVersion('1.0');
42+
Configuration::setMerchantId($this->mid);
43+
Configuration::setSecretKey($this->secret_key);
44+
Configuration::setApiVersion('1.0');
4245
}
4346

4447
/**
@@ -48,8 +51,8 @@ public function testUrl()
4851
{
4952
$this->setTestConfig();
5053
foreach ($this->request_types as $type) {
51-
\Cloudipsp\Configuration::setRequestType($type);
52-
$result = \Cloudipsp\Checkout::url($this->fullTestData)->getData();
54+
Configuration::setRequestType($type);
55+
$result = Checkout::url($this->fullTestData)->getData();
5356
$this->validateCheckoutUrlResult($result);
5457
}
5558
}
@@ -60,11 +63,9 @@ public function testUrl()
6063
public function testToken()
6164
{
6265
$this->setTestConfig();
63-
//foreach ($this->request_types as $type) {
64-
\Cloudipsp\Configuration::setRequestType('json');
65-
$result = \Cloudipsp\Checkout::token($this->fullTestData)->getData();
66-
$this->validateTokenResult($result);
67-
// }
66+
Configuration::setRequestType('json');
67+
$result = Checkout::token($this->fullTestData)->getData();
68+
$this->validateTokenResult($result);
6869
}
6970

7071
/**
@@ -73,16 +74,37 @@ public function testToken()
7374
public function testForm()
7475
{
7576
$this->setTestConfig();
76-
$result = \Cloudipsp\Checkout::form($this->fullTestData);
77-
$this->assertInternalType('string', $result, "Got a " . gettype($result) . " instead of a string");
77+
$result = Checkout::form($this->fullTestData);
78+
$this->assertIsMyString($result, "Got a " . gettype($result) . " instead of a string");
7879
}
7980

81+
/**
82+
* Checking correct result for token request
83+
* @param $result
84+
*/
8085
private function validateTokenResult($result)
8186
{
8287
$this->assertNotEmpty($result['token'], 'payment_id is empty');
83-
$this->assertInternalType('string', $result['token'], "Got a " . gettype($result['token']) . " instead of a string");
88+
$this->assertIsMyString($result['token'], "Got a " . gettype($result['token']) . " instead of a string");
89+
}
90+
91+
/**
92+
* @param $string
93+
* @param $message
94+
*/
95+
private function assertIsMyString($string, $message)
96+
{
97+
if (method_exists(get_parent_class($this), 'assertIsString')) {
98+
$this->assertIsString($string, $message);
99+
} else {
100+
$this->assertInternalType('string', $string, $message);
101+
}
84102
}
85103

104+
/**
105+
* Checking correct result of get checkout url
106+
* @param $result
107+
*/
86108
private function validateCheckoutUrlResult($result)
87109
{
88110
$this->assertNotEmpty($result['checkout_url'], 'checkout_url is empty');

tests/ConfigurationTest.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,68 @@ class ConfigurationTest extends TestCase
88
{
99
public function testGetApiUrl()
1010
{
11-
$this->assertEquals('https://api.fondy.eu/api', \Cloudipsp\Configuration::getApiUrl());
12-
\Cloudipsp\Configuration::setApiUrl('api.saas.com');
11+
$this->assertEquals('https://api.fondy.eu/api', Configuration::getApiUrl());
12+
Configuration::setApiUrl('api.saas.com');
1313
$this->assertEquals(
1414
'https://api.saas.com/api',
15-
\Cloudipsp\Configuration::getApiUrl()
15+
Configuration::getApiUrl()
1616
);
17-
\Cloudipsp\Configuration::setApiUrl('api.fondy.eu');
17+
Configuration::setApiUrl('api.fondy.eu');
1818
$this->assertEquals(
1919
'https://api.fondy.eu/api',
20-
\Cloudipsp\Configuration::getApiUrl()
20+
Configuration::getApiUrl()
2121
);
2222
}
2323

2424
public function testSetApiVersion()
2525
{
2626
$this->assertEquals(
2727
'1.0',
28-
\Cloudipsp\Configuration::getApiVersion()
28+
Configuration::getApiVersion()
2929
);
30-
\Cloudipsp\Configuration::setApiVersion('2.0');
30+
Configuration::setApiVersion('2.0');
3131
$this->assertEquals(
3232
'2.0',
33-
\Cloudipsp\Configuration::getApiVersion()
33+
Configuration::getApiVersion()
3434
);
3535
}
3636

3737
public function testSetHttpClient()
3838
{
39-
\Cloudipsp\Configuration::setHttpClient('HttpGuzzle');
40-
$this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpGuzzle', \Cloudipsp\Configuration::getHttpClient());
41-
\Cloudipsp\Configuration::setHttpClient('HttpCurl');
42-
$this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpCurl', \Cloudipsp\Configuration::getHttpClient());
43-
$this->setExpectedException('PHPUnit_Framework_Error_Notice');
44-
$this->assertFalse(\Cloudipsp\Configuration::setHttpClient('Unknown'));
39+
Configuration::setHttpClient('HttpGuzzle');
40+
$this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpGuzzle', Configuration::getHttpClient());
41+
Configuration::setHttpClient('HttpCurl');
42+
$this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpCurl', Configuration::getHttpClient());
43+
if (method_exists(get_parent_class($this), 'expectNotice')){
44+
$this->expectNotice();
45+
} else {
46+
$this->expectException('PHPUnit_Framework_Error_Notice');
47+
}
48+
$this->assertFalse(Configuration::setHttpClient('Unknown'));
4549
}
4650

4751
public function testSetHttpClientClass()
4852
{
49-
\Cloudipsp\Configuration::setHttpClient(new \Cloudipsp\HttpClient\HttpCurl());
50-
$this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpCurl', \Cloudipsp\Configuration::getHttpClient());
53+
Configuration::setHttpClient(new HttpClient\HttpCurl());
54+
$this->assertInstanceOf('\\Cloudipsp\\HttpClient\\HttpCurl', Configuration::getHttpClient());
5155
}
5256

5357
public function testSetSecretKey()
5458
{
55-
\Cloudipsp\Configuration::setSecretKey('something-secret');
56-
$this->assertEquals('something-secret', \Cloudipsp\Configuration::getSecretKey());
59+
Configuration::setSecretKey('something-secret');
60+
$this->assertEquals('something-secret', Configuration::getSecretKey());
5761
}
5862

5963

6064
public function testSetMerchantId()
6165
{
62-
\Cloudipsp\Configuration::setMerchantId(123);
63-
$this->assertEquals(123, \Cloudipsp\Configuration::getMerchantId());
66+
Configuration::setMerchantId(123);
67+
$this->assertEquals(123, Configuration::getMerchantId());
6468
}
6569

6670
public function testSetCreditKey()
6771
{
68-
\Cloudipsp\Configuration::setCreditKey('something-secret');
69-
$this->assertEquals('something-secret', \Cloudipsp\Configuration::getCreditKey());
72+
Configuration::setCreditKey('something-secret');
73+
$this->assertEquals('something-secret', Configuration::getCreditKey());
7074
}
7175
}

tests/OrderTest.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public function __construct($name = null, array $data = array(), $dataName = '')
3737

3838
private function setTestConfig()
3939
{
40-
\Cloudipsp\Configuration::setMerchantId($this->mid);
41-
\Cloudipsp\Configuration::setSecretKey($this->secret_key);
42-
\Cloudipsp\Configuration::setApiVersion('1.0');
40+
Configuration::setMerchantId($this->mid);
41+
Configuration::setSecretKey($this->secret_key);
42+
Configuration::setApiVersion('1.0');
4343
}
4444

4545
/**
@@ -48,7 +48,7 @@ private function setTestConfig()
4848
public function testStatus()
4949
{
5050
$this->setTestConfig();
51-
$data = \Cloudipsp\Order::status($this->orderID);
51+
$data = Order::status($this->orderID);
5252
$result = $data->getData();
5353
$this->assertNotEmpty($result['order_id'], 'order_id is empty');
5454
$this->assertNotEmpty($result['order_status'], 'order_status is empty');
@@ -67,9 +67,9 @@ public function testCapture()
6767
'amount' => 1000,
6868
'order_id' => $this->orderID['order_id']
6969
];
70-
$data = \Cloudipsp\Order::capture($captureData);
70+
$data = Order::capture($captureData);
7171
$result = $data->getData();
72-
$this->assertInternalType('array', $result);
72+
$this->assertIsMyArray($result);
7373
$this->assertEquals($result['capture_status'], 'captured');
7474
}
7575

@@ -84,7 +84,7 @@ public function testReverse()
8484
'amount' => 1000,
8585
'order_id' => $this->orderID['order_id']
8686
];
87-
$data = \Cloudipsp\Order::reverse($reverseData);
87+
$data = Order::reverse($reverseData);
8888
$result = $data->getData();
8989
$this->assertNotEmpty($result['order_id'], 'order_id is empty');
9090
$this->assertEquals($result['response_status'], 'success');
@@ -97,23 +97,25 @@ public function testReverse()
9797
public function testTransactionList()
9898
{
9999
$this->setTestConfig();
100-
$data = \Cloudipsp\Order::transactionList($this->orderID);
100+
$data = Order::transactionList($this->orderID);
101101
$result = $data->getData();
102-
$this->assertInternalType('array', $result);
103-
$this->assertContains('payment_id', $result[0]);
102+
$this->assertIsMyArray($result);
103+
$this->assertEquals('approved', $result[0]['transaction_status']);
104104

105105
}
106106

107107
/**
108-
* @throws Exception\ApiException
108+
* @param $array
109+
* @param $message
109110
*/
110-
/*public function testAtolLogs()
111+
private function assertIsMyArray($array, $message = '')
111112
{
112-
$this->setTestConfig();
113-
$data = \Cloudipsp\Order::atolLogs($this->orderID);
114-
$result = $data->getData();
115-
$this->assertInternalType('array', $result);
116-
}*/
113+
if (method_exists(get_parent_class($this), 'assertIsArray')) {
114+
$this->assertIsArray($array, $message);
115+
} else {
116+
$this->assertInternalType('array', $array, $message);
117+
}
118+
}
117119

118120
/**
119121
* @param $data
@@ -122,7 +124,7 @@ public function testTransactionList()
122124
*/
123125
private function createOrder($data)
124126
{
125-
$data = \Cloudipsp\Pcidss::start($data);
127+
$data = Pcidss::start($data);
126128
return $data->getData()['order_id'];
127129
}
128130
}

0 commit comments

Comments
 (0)