This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Skipping tests till run in separate process if fixed - Making array objects to be compatible with older versions of php
- Loading branch information
japatel
committed
Oct 6, 2014
1 parent
cea8981
commit 4592938
Showing
8 changed files
with
128 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
use PayPal\Core\PPConfigManager; | ||
|
||
class PPConfigManagerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var PPConfigManager | ||
*/ | ||
protected $object; | ||
|
||
/** | ||
* Sets up the fixture, for example, opens a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->object = new \ReflectionClass('PayPal\Core\PPConfigManager'); | ||
runkit_constant_remove('PP_CONFIG_PATH'); | ||
} | ||
|
||
/** | ||
* Tears down the fixture, for example, closes a network connection. | ||
* This method is called after a test is executed. | ||
*/ | ||
protected function tearDown() | ||
{ | ||
$property = $this->object->getProperty('instance'); | ||
$property->setValue(null); | ||
} | ||
|
||
|
||
public function testGetInstance() | ||
{ | ||
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__)))); | ||
$this->object = PPConfigManager::getInstance(); | ||
$instance = $this->object->getInstance(); | ||
$instance2 = $this->object->getInstance(); | ||
$this->assertTrue($instance instanceof PPConfigManager); | ||
$this->assertSame($instance, $instance2); | ||
} | ||
|
||
|
||
public function testGet() | ||
{ | ||
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__)))); | ||
$this->object = PPConfigManager::getInstance(); | ||
$ret = $this->object->get('acct2'); | ||
$this->assertConfiguration( | ||
array('acct2.ClientId' => 'TestClientId', 'acct2.ClientSecret' => 'TestClientSecret'), | ||
$ret | ||
); | ||
$this->assertTrue(sizeof($ret) == 2); | ||
|
||
} | ||
|
||
|
||
public function testGetIniPrefix() | ||
{ | ||
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__)))); | ||
$this->object = PPConfigManager::getInstance(); | ||
|
||
$ret = $this->object->getIniPrefix(); | ||
$this->assertContains('acct1', $ret); | ||
$this->assertEquals(sizeof($ret), 2); | ||
|
||
$ret = $this->object->getIniPrefix('TestClientId'); | ||
$this->assertEquals('acct2', $ret); | ||
} | ||
|
||
|
||
public function testConfigByDefault() | ||
{ | ||
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__)))); | ||
$this->object = PPConfigManager::getInstance(); | ||
|
||
// Test file based config params and defaults | ||
$config = PPConfigManager::getInstance()->getConfigHashmap(); | ||
$this->assertConfiguration(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => '60'), $config); | ||
} | ||
|
||
|
||
public function testConfigByCustom() | ||
{ | ||
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__)))); | ||
$this->object = PPConfigManager::getInstance(); | ||
|
||
// Test custom config params and defaults | ||
$config = PPConfigManager::getInstance()->addConfigs(array('mode' => 'custom', 'http.ConnectionTimeOut' => 900))->getConfigHashmap(); | ||
$this->assertConfiguration(array('mode' => 'custom', 'http.ConnectionTimeOut' => '900'), $config); | ||
} | ||
|
||
|
||
public function testConfigByFileAndCustom() { | ||
define("PP_CONFIG_PATH", __DIR__. '/non_existent/'); | ||
$this->object = PPConfigManager::getInstance(); | ||
|
||
$config = PPConfigManager::getInstance()->getConfigHashmap(); | ||
$this->assertArrayHasKey('http.ConnectionTimeOut', $config); | ||
$this->assertEquals('30', $config['http.ConnectionTimeOut']); | ||
$this->assertEquals('5', $config['http.Retry']); | ||
|
||
//Add more configs | ||
$config = PPConfigManager::getInstance()->addConfigs(array('http.Retry' => "10", 'mode' => 'sandbox'))->getConfigHashmap(); | ||
$this->assertConfiguration(array('http.ConnectionTimeOut' => "30", 'http.Retry' => "10", 'mode' => 'sandbox'), $config); | ||
} | ||
|
||
/** | ||
* Asserts if each configuration is available and has expected value. | ||
* | ||
* @param $conditions | ||
* @param $config | ||
*/ | ||
public function assertConfiguration($conditions, $config) { | ||
foreach($conditions as $key => $value) { | ||
$this->assertArrayHasKey($key, $config); | ||
$this->assertEquals($value, $config[$key]); | ||
} | ||
} | ||
} | ||
?> |