forked from LiveCarta/PayPal-PHP-SDK
Functional Tests Improvements and Refactoring
- Updated Functional Tests to refactor common code in one file - Re-sets the credentials to make sure previous tests doesnt change it for testing
This commit is contained in:
@@ -93,7 +93,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
WebhookEventListTest::getJson()
|
||||
WebhookEventTypeListTest::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->subscribedEventTypes("webhookId", $mockApiContext, $mockPPRestCall);
|
||||
@@ -112,7 +112,7 @@ class WebhookEventTypeTest extends \PHPUnit_Framework_TestCase
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
WebhookEventListTest::getJson()
|
||||
WebhookEventTypeListTest::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->availableEventTypes($mockApiContext, $mockPPRestCall);
|
||||
|
||||
@@ -12,6 +12,7 @@ use PayPal\Common\PPModel;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Rest\IResource;
|
||||
use PayPal\Api\CreateProfileResponse;
|
||||
use PayPal\Test\Functional\Setup;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\WebProfile;
|
||||
|
||||
@@ -27,8 +28,6 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public $response;
|
||||
|
||||
public $mode = 'mock';
|
||||
|
||||
public $mockPPRestCall;
|
||||
|
||||
public function setUp()
|
||||
@@ -46,21 +45,7 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
if (array_key_exists('body', $this->operation['response'])) {
|
||||
$this->response = json_encode($this->operation['response']['body']);
|
||||
}
|
||||
|
||||
$this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
|
||||
if ($this->mode != 'sandbox') {
|
||||
|
||||
// Mock PPRest Caller if mode set to mock
|
||||
$this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
$this->response
|
||||
));
|
||||
}
|
||||
Setup::SetUpForFunctionalTests($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +79,7 @@ class BillingAgreementsFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testExecute($agreement)
|
||||
{
|
||||
if ($this->mode == 'sandbox') {
|
||||
if (Setup::$mode == 'sandbox') {
|
||||
$this->markTestSkipped('Not executable on sandbox environment. Needs human interaction');
|
||||
}
|
||||
$links = $agreement->getLinks();
|
||||
|
||||
@@ -5,10 +5,13 @@ namespace PayPal\Test\Functional\Api;
|
||||
use PayPal\Api\Patch;
|
||||
use PayPal\Api\PatchRequest;
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Common\PPModel;
|
||||
use PayPal\Core\PPCredentialManager;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Rest\IResource;
|
||||
use PayPal\Api\CreateProfileResponse;
|
||||
use PayPal\Test\Functional\Setup;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\WebProfile;
|
||||
|
||||
@@ -30,6 +33,8 @@ class BillingPlansFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public $mockPPRestCall;
|
||||
|
||||
public $context;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$className = $this->getClassName();
|
||||
@@ -46,20 +51,7 @@ class BillingPlansFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
$this->response = json_encode($this->operation['response']['body']);
|
||||
}
|
||||
|
||||
$this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
|
||||
if ($this->mode != 'sandbox') {
|
||||
|
||||
// Mock PPRest Caller if mode set to mock
|
||||
$this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
$this->response
|
||||
));
|
||||
}
|
||||
Setup::SetUpForFunctionalTests($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ use PayPal\Api\Notification;
|
||||
use PayPal\Api\PaymentDetail;
|
||||
use PayPal\Api\RefundDetail;
|
||||
use PayPal\Api\Search;
|
||||
use PayPal\Test\Functional\Setup;
|
||||
|
||||
/**
|
||||
* Class Invoice
|
||||
@@ -22,8 +23,6 @@ class InvoiceFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public $response;
|
||||
|
||||
public $mode = 'mock';
|
||||
|
||||
public $mockPPRestCall;
|
||||
|
||||
public function setUp()
|
||||
@@ -42,20 +41,7 @@ class InvoiceFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
$this->response = json_encode($this->operation['response']['body']);
|
||||
}
|
||||
|
||||
$this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
|
||||
if ($this->mode != 'sandbox') {
|
||||
|
||||
// Mock PPRest Caller if mode set to mock
|
||||
$this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
$this->response
|
||||
));
|
||||
}
|
||||
Setup::SetUpForFunctionalTests($this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use PayPal\Common\PPModel;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Rest\IResource;
|
||||
use PayPal\Api\CreateProfileResponse;
|
||||
use PayPal\Test\Functional\Setup;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\WebProfile;
|
||||
|
||||
@@ -28,8 +29,6 @@ class PaymentsFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public $response;
|
||||
|
||||
public $mode = 'mock';
|
||||
|
||||
public $mockPPRestCall;
|
||||
|
||||
public function setUp()
|
||||
@@ -42,21 +41,7 @@ class PaymentsFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
if (array_key_exists('body', $this->operation['response'])) {
|
||||
$this->response = json_encode($this->operation['response']['body']);
|
||||
}
|
||||
|
||||
$this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
|
||||
if ($this->mode != 'sandbox') {
|
||||
|
||||
// Mock PPRest Caller if mode set to mock
|
||||
$this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
$this->response
|
||||
));
|
||||
}
|
||||
Setup::SetUpForFunctionalTests($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +124,7 @@ class PaymentsFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testExecute($payment)
|
||||
{
|
||||
if ($this->mode == 'sandbox') {
|
||||
if (Setup::$mode == 'sandbox') {
|
||||
$this->markTestSkipped('Not executable on sandbox environment. Needs human interaction');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use PayPal\Common\PPModel;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Rest\IResource;
|
||||
use PayPal\Api\CreateProfileResponse;
|
||||
use PayPal\Test\Functional\Setup;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\WebProfile;
|
||||
|
||||
@@ -22,8 +23,6 @@ class WebProfileFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public $response;
|
||||
|
||||
public $mode = 'mock';
|
||||
|
||||
public $mockPPRestCall;
|
||||
|
||||
public function setUp()
|
||||
@@ -37,20 +36,7 @@ class WebProfileFunctionalTest extends \PHPUnit_Framework_TestCase
|
||||
$this->response = json_encode($this->operation['response']['body']);
|
||||
}
|
||||
|
||||
$this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
|
||||
if ($this->mode != 'sandbox') {
|
||||
|
||||
// Mock PPRest Caller if mode set to mock
|
||||
$this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
$this->response
|
||||
));
|
||||
}
|
||||
Setup::SetUpForFunctionalTests($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
49
tests/PayPal/Test/Functional/Setup.php
Normal file
49
tests/PayPal/Test/Functional/Setup.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Test\Functional;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Core\PPCredentialManager;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
class Setup
|
||||
{
|
||||
|
||||
public static $mode = 'mock';
|
||||
|
||||
public static function SetUpForFunctionalTests(\PHPUnit_Framework_TestCase &$test)
|
||||
{
|
||||
$context = new ApiContext();
|
||||
$context->setConfig(array(
|
||||
'mode' => 'sandbox',
|
||||
'acct1.ClientId' => 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS',
|
||||
'acct1.ClientSecret' => 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL',
|
||||
'http.ConnectionTimeOut' => 30,
|
||||
'log.LogEnabled' => true,
|
||||
'log.FileName' => '../PayPal.log',
|
||||
'log.LogLevel' => 'FINE',
|
||||
'validation.level' => 'warning'
|
||||
));
|
||||
PPCredentialManager::getInstance()->setCredentialObject(
|
||||
new OAuthTokenCredential(
|
||||
"AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS",
|
||||
"EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL"
|
||||
)
|
||||
);
|
||||
|
||||
self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
|
||||
if (self::$mode != 'sandbox') {
|
||||
|
||||
// Mock PPRest Caller if mode set to mock
|
||||
$test->mockPPRestCall = $test->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$test->mockPPRestCall->expects($test->any())
|
||||
->method('execute')
|
||||
->will($test->returnValue(
|
||||
$test->response
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user