Skip to content

Commit 9aa34c8

Browse files
committed
Checkin of current unit test progress
1 parent 23eb762 commit 9aa34c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3325
-37
lines changed

Api/Data/AddresscheckResponseInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types = 1);
2+
33
namespace Payone\Core\Api\Data;
44

55
interface AddresscheckResponseInterface

Helper/Api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public function sendApiRequest($sRequestUrl)
9898
return ["errormessage" => "Payone API request URL could not be parsed."];
9999
}
100100

101-
if (function_exists("curl_init")) {
101+
if ($this->connCurlPhp->isApplicable()) {
102102
// php native curl exists so we gonna use it for requesting
103103
$aResponse = $this->connCurlPhp->sendCurlPhpRequest($aParsedRequestUrl);
104-
} elseif (file_exists("/usr/local/bin/curl") || file_exists("/usr/bin/curl")) {
104+
} elseif ($this->connCurlCli->isApplicable()) {
105105
// cli version of curl exists on server
106106
$aResponse = $this->connCurlCli->sendCurlCliRequest($aParsedRequestUrl);
107107
} else {

Helper/Connection/CurlCli.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
*/
3232
class CurlCli
3333
{
34+
/**
35+
* Determine if this connection type can be used on the given server
36+
*
37+
* @return bool
38+
*/
39+
public function isApplicable()
40+
{
41+
if (file_exists("/usr/local/bin/curl") || file_exists("/usr/bin/curl")) {
42+
return true;
43+
}
44+
return false;
45+
}
46+
3447
/**
3548
* Send cli Curl request
3649
*
@@ -39,6 +52,10 @@ class CurlCli
3952
*/
4053
public function sendCurlCliRequest($aParsedRequestUrl)
4154
{
55+
if (!$this->isApplicable()) {
56+
return ["errormessage" => "Cli-Curl is not applicable on this server."];
57+
}
58+
4259
$sCurlPath = file_exists("/usr/local/bin/curl") ? "/usr/local/bin/curl" : "/usr/bin/curl";
4360

4461
$aResponse = [];

Helper/Connection/CurlPhp.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
*/
3232
class CurlPhp
3333
{
34+
/**
35+
* Determine if this connection type can be used on the given server
36+
*
37+
* @return bool
38+
*/
39+
public function isApplicable()
40+
{
41+
if (function_exists("curl_init")) {
42+
return true;
43+
}
44+
return false;
45+
}
46+
3447
/**
3548
* Send php Curl request
3649
*
@@ -39,6 +52,10 @@ class CurlPhp
3952
*/
4053
public function sendCurlPhpRequest($aParsedRequestUrl)
4154
{
55+
if (!$this->isApplicable()) {
56+
return ["errormessage" => "Php-Curl is not applicable on this server."];
57+
}
58+
4259
$aResponse = [];
4360

4461
$oCurl = curl_init($aParsedRequestUrl['scheme']."://".$aParsedRequestUrl['host'].$aParsedRequestUrl['path']);

Helper/Connection/Fsockopen.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
*/
3232
class Fsockopen
3333
{
34+
/**
35+
* Determine if this connection type can be used on the given server
36+
*
37+
* @return bool
38+
*/
39+
public function isApplicable()
40+
{
41+
if (function_exists("fsockopen")) {
42+
return true;
43+
}
44+
return false;
45+
}
46+
3447
/**
3548
* Get request header for fsockopen request
3649
*
@@ -80,6 +93,10 @@ protected function getSocketResponse($oFsockOpen)
8093
*/
8194
public function sendSocketRequest($aParsedRequestUrl)
8295
{
96+
if (!$this->isApplicable()) {
97+
return ["errormessage" => "Cli-Curl is not applicable on this server."];
98+
}
99+
83100
$iErrorNumber = '';
84101
$sErrorString = '';
85102

Helper/HostedIframe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function getHostedParams()
7373
$sHostedParams = $this->getConfigParam('cc_template', 'creditcard'); // get params from config
7474
if ($sHostedParams) { // params set in config?
7575
$aHostedParams = unserialize($sHostedParams); // create array from serialized string
76-
if ($aHostedParams) {
76+
if (is_array($aHostedParams) && !empty($aHostedParams)) {
7777
$this->aHostedParams = $aHostedParams;
7878
}
7979
}

Helper/Payment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function isCheckCvcActive()
134134
*/
135135
public function isMandateManagementActive()
136136
{
137-
return $this->getConfigParam('sepa_mandate_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment');
137+
return (bool)$this->getConfigParam('sepa_mandate_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment');
138138
}
139139

140140
/**
@@ -144,7 +144,7 @@ public function isMandateManagementActive()
144144
*/
145145
public function isMandateManagementDownloadActive()
146146
{
147-
return $this->getConfigParam('sepa_mandate_download_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment');
147+
return (bool)$this->getConfigParam('sepa_mandate_download_enabled', PayoneConfig::METHOD_DEBIT, 'payone_payment');
148148
}
149149

150150
/**

Helper/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function getBankaccountCheckRequest()
101101
*
102102
* @return string
103103
*/
104-
protected function getHostedIframeRequestCCHash()
104+
public function getHostedIframeRequestCCHash()
105105
{
106106
$sHash = md5(
107107
$this->getConfigParam('aid').
@@ -122,7 +122,7 @@ protected function getHostedIframeRequestCCHash()
122122
*
123123
* @return string
124124
*/
125-
protected function getBankaccountCheckRequestHash()
125+
public function getBankaccountCheckRequestHash()
126126
{
127127
$sHash = md5(
128128
$this->getConfigParam('aid').

Helper/Toolkit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public function isKeyValid($sKey)
122122
/**
123123
* Replace substitutes in a given text with the given replacements
124124
*
125-
* @param string $sText
126-
* @param string $aSubstitutionArray
127-
* @param int $iMaxLength
125+
* @param string $sText
126+
* @param string $aSubstitutionArray
127+
* @param int|bool $iMaxLength
128128
* @return string
129129
*/
130130
public function handleSubstituteReplacement($sText, $aSubstitutionArray, $iMaxLength = false)

Observer/OrderPaymentPlaceEnd.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Magento\Framework\Event\ObserverInterface;
3131
use Magento\Framework\Event\Observer;
3232
use Payone\Core\Helper\Consumerscore;
33+
use Magento\Sales\Model\Order\Payment;
3334

3435
/**
3536
* Event class to set the orderstatus to new and pending
@@ -61,6 +62,7 @@ public function __construct(Consumerscore $consumerscoreHelper)
6162
*/
6263
protected function handleOrderStatus(Observer $observer)
6364
{
65+
/** @var Payment $oPayment */
6466
$oPayment = $observer->getEvent()->getPayment();
6567
$oPaymentInstance = $oPayment->getMethodInstance();
6668
if (stripos($oPaymentInstance->getCode(), 'payone') !== false) {

Observer/PaymentMethodAssignData.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Magento\Framework\Event\ObserverInterface;
3030
use Magento\Framework\Event\Observer;
3131
use Payone\Core\Helper\Toolkit;
32+
use Magento\Payment\Model\InfoInterface;
3233

3334
/**
3435
* Event class to set the orderstatus to new and pending
@@ -62,7 +63,9 @@ public function execute(Observer $observer)
6263
{
6364
$blBoniAgreement = $this->toolkitHelper->getAdditionalDataEntry($observer->getData('data'), 'payone_boni_agreement');
6465
if ($blBoniAgreement !== null) {
65-
$observer->getPaymentModel()->setAdditionalInformation('payone_boni_agreement', (bool)$blBoniAgreement);
66+
/** @var InfoInterface $oPaymentInfo */
67+
$oPaymentInfo = $observer->getPaymentModel();
68+
$oPaymentInfo->setAdditionalInformation('payone_boni_agreement', (bool)$blBoniAgreement);
6669
}
6770
}
6871
}

Service/V1/Addresscheck.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,7 @@ protected function handleResponse(AddresscheckResponse $oResponse, AddressInterf
162162
* @param bool $blIsBillingAddress
163163
* @return AddresscheckResponse
164164
*/
165-
protected function handleAddresscheck(
166-
AddresscheckResponse $oResponse,
167-
AddressInterface $oAddress,
168-
$blIsBillingAddress
169-
) {
165+
protected function handleAddresscheck(AddresscheckResponse $oResponse, AddressInterface $oAddress, $blIsBillingAddress) {
170166
$aResponse = $this->addresscheck->getResponse($oAddress, $blIsBillingAddress);
171167
if (is_array($aResponse)) { // is a real response existing?
172168
$this->addScoreToSession($oAddress, $blIsBillingAddress);

Test/Unit/Helper/ApiTest.php

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
use Payone\Core\Helper\Api;
3030
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31-
use Magento\Framework\App\ObjectManager as MainObjectManager;
3231
use Magento\Store\Model\StoreManagerInterface;
3332
use Magento\Store\Api\Data\StoreInterface;
3433
use Payone\Core\Model\Methods\PayoneMethod;
@@ -62,6 +61,21 @@ class ApiTest extends \PHPUnit_Framework_TestCase
6261
*/
6362
private $scopeConfig;
6463

64+
/**
65+
* @var CurlPhp|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
private $connCurlPhp;
68+
69+
/**
70+
* @var CurlCli|\PHPUnit_Framework_MockObject_MockObject
71+
*/
72+
private $connCurlCli;
73+
74+
/**
75+
* @var Fsockopen|\PHPUnit_Framework_MockObject_MockObject
76+
*/
77+
private $connFsockopen;
78+
6579
protected function setUp()
6680
{
6781
$this->objectManager = new ObjectManager($this);
@@ -76,9 +90,9 @@ protected function setUp()
7690
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)->disableOriginalConstructor()->getMock();
7791
$storeManager->method('getStore')->willReturn($store);
7892

79-
$connCurlPhp = $this->getMockBuilder(CurlPhp::class)->disableOriginalConstructor()->getMock();
80-
$connCurlCli = $this->getMockBuilder(CurlCli::class)->disableOriginalConstructor()->getMock();
81-
$connFsockopen = $this->getMockBuilder(Fsockopen::class)->disableOriginalConstructor()->getMock();
93+
$this->connCurlPhp = $this->getMockBuilder(CurlPhp::class)->disableOriginalConstructor()->getMock();
94+
$this->connCurlCli = $this->getMockBuilder(CurlCli::class)->disableOriginalConstructor()->getMock();
95+
$this->connFsockopen = $this->getMockBuilder(Fsockopen::class)->disableOriginalConstructor()->getMock();
8296

8397
$sendOutput = [
8498
'status=APPROVED',
@@ -87,16 +101,16 @@ protected function setUp()
87101
'test',
88102
''
89103
];
90-
$connCurlPhp->method('sendCurlPhpRequest')->willReturn($sendOutput);
91-
$connCurlCli->method('sendCurlCliRequest')->willReturn($sendOutput);
92-
$connFsockopen->method('sendSocketRequest')->willReturn($sendOutput);
104+
$this->connCurlPhp->method('sendCurlPhpRequest')->willReturn($sendOutput);
105+
$this->connCurlCli->method('sendCurlCliRequest')->willReturn($sendOutput);
106+
$this->connFsockopen->method('sendSocketRequest')->willReturn($sendOutput);
93107

94108
$this->api = $this->objectManager->getObject(Api::class, [
95109
'context' => $context,
96110
'storeManager' => $storeManager,
97-
'connCurlPhp' => $connCurlPhp,
98-
'connCurlCli' => $connCurlCli,
99-
'connFsockopen' => $connFsockopen
111+
'connCurlPhp' => $this->connCurlPhp,
112+
'connCurlCli' => $this->connCurlCli,
113+
'connFsockopen' => $this->connFsockopen
100114
]);
101115
}
102116

@@ -193,8 +207,40 @@ public function testIfParseErrorIsReturnedCorrectly()
193207
$this->assertEquals($expected, $return);
194208
}
195209

196-
public function testSendApiRequestReturnValue()
210+
public function testSendApiRequestReturnValueCurlPhp()
211+
{
212+
$this->connCurlPhp->method('isApplicable')->willReturn(true);
213+
214+
$return = $this->api->sendApiRequest("http://payone.de");
215+
$expected = [
216+
'status' => 'APPROVED',
217+
'txid' => '42',
218+
'userid' => '0815',
219+
3 => 'test'
220+
];
221+
$this->assertEquals($expected, $return);
222+
}
223+
224+
public function testSendApiRequestReturnValueCurlCli()
197225
{
226+
$this->connCurlPhp->method('isApplicable')->willReturn(false);
227+
$this->connCurlCli->method('isApplicable')->willReturn(true);
228+
229+
$return = $this->api->sendApiRequest("http://payone.de");
230+
$expected = [
231+
'status' => 'APPROVED',
232+
'txid' => '42',
233+
'userid' => '0815',
234+
3 => 'test'
235+
];
236+
$this->assertEquals($expected, $return);
237+
}
238+
239+
public function testSendApiRequestReturnValueFsockopen()
240+
{
241+
$this->connCurlPhp->method('isApplicable')->willReturn(false);
242+
$this->connCurlCli->method('isApplicable')->willReturn(false);
243+
198244
$return = $this->api->sendApiRequest("http://payone.de");
199245
$expected = [
200246
'status' => 'APPROVED',

Test/Unit/Helper/BaseTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
use Payone\Core\Helper\Base;
3030
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31-
use Magento\Framework\App\ObjectManager as MainObjectManager;
3231
use Magento\Store\Model\StoreManagerInterface;
3332
use Magento\Store\Api\Data\StoreInterface;
3433
use Magento\Framework\App\Helper\Context;

Test/Unit/Helper/CheckoutTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
use Payone\Core\Helper\Checkout;
3030
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31-
use Magento\Framework\App\ObjectManager as MainObjectManager;
3231
use Magento\Checkout\Model\Type\Onepage;
3332
use Magento\Quote\Model\Quote;
3433
use Magento\Customer\Model\Session;

Test/Unit/Helper/ConfigExportTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
use Payone\Core\Helper\ConfigExport;
3030
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31-
use Magento\Framework\App\ObjectManager as MainObjectManager;
3231
use Magento\Store\Model\StoreManagerInterface;
3332
use Magento\Store\Api\Data\StoreInterface;
3433
use Magento\Framework\App\Helper\Context;

Test/Unit/Helper/ConfigTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
use Payone\Core\Helper\Config;
3030
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
31-
use Magento\Framework\App\ObjectManager as MainObjectManager;
3231
use Magento\Store\Model\StoreManagerInterface;
3332
use Magento\Store\Api\Data\StoreInterface;
3433
use Magento\Framework\App\Helper\Context;

0 commit comments

Comments
 (0)