-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more test to cover charge method.
- Loading branch information
Aashish
committed
Oct 11, 2023
1 parent
2995684
commit 7eb6401
Showing
10 changed files
with
184 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class Bootstrap_Test_Setup extends TestCase | ||
{ | ||
public $sourceType; | ||
|
||
public function setUp(): void | ||
{ | ||
// mocking WP built-in functions | ||
if (!function_exists('wp_kses')) { | ||
function wp_kses() {} | ||
} | ||
|
||
if (!function_exists('add_action')) { | ||
function add_action() {} | ||
} | ||
|
||
if (!function_exists('sanitize_text_field')) { | ||
function sanitize_text_field() { | ||
return 'Sanitized text'; | ||
} | ||
} | ||
} | ||
|
||
public function getOrderMock($expectedAmount, $expectedCurrency) | ||
{ | ||
// Create a mock of the $order object | ||
$orderMock = Mockery::mock('WC_Order'); | ||
|
||
// Define expectations for the mock | ||
$orderMock->shouldReceive('get_currency') | ||
->andReturn($expectedCurrency); | ||
$orderMock->shouldReceive('get_total') | ||
->andReturn($expectedAmount); // in units | ||
$orderMock->shouldReceive('add_meta_data'); | ||
$orderMock->shouldReceive('get_billing_phone') | ||
->andReturn('1234567890'); | ||
$orderMock->shouldReceive('get_address') | ||
->andReturn([ | ||
'country' => 'Thailand', | ||
'city' => 'Bangkok', | ||
'postcode' => '10110', | ||
'state' => 'Bangkok', | ||
'address_1' => 'Sukumvit Road' | ||
]); | ||
$orderMock->shouldReceive('get_items') | ||
->andReturn([ | ||
[ | ||
'name' => 'T Shirt', | ||
'subtotal' => 600, | ||
'qty' => 1, | ||
'product_id' => 'product_123', | ||
'variation_id' => null | ||
] | ||
]); | ||
return $orderMock; | ||
} | ||
|
||
/** | ||
* close mockery after tests are done | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
Mockery::close(); | ||
} | ||
|
||
public function getChargeTest($classObj) | ||
{ | ||
$expectedAmount = 999999; | ||
$expectedCurrency = 'thb'; | ||
$expectedRequest = [ | ||
"object" => "charge", | ||
"id" => "chrg_test_no1t4tnemucod0e51mo", | ||
"location" => "/charges/chrg_test_no1t4tnemucod0e51mo", | ||
"amount" => $expectedAmount, | ||
"currency" => $expectedCurrency | ||
]; | ||
|
||
// Create a mock for OmiseCharge | ||
$chargeMock = Mockery::mock('overload:OmiseCharge'); | ||
$chargeMock->shouldReceive('create')->once()->andReturn($expectedRequest); | ||
|
||
$orderMock = $this->getOrderMock($expectedAmount, $expectedCurrency); | ||
|
||
$wcProduct = Mockery::mock('overload:WC_Product'); | ||
$wcProduct->shouldReceive('get_sku') | ||
->once() | ||
->andReturn('sku_1234'); | ||
|
||
$orderId = 'order_123'; | ||
$result = $classObj->charge($orderId, $orderMock); | ||
$this->assertEquals($expectedAmount, $result['amount']); | ||
$this->assertEquals($expectedCurrency, $result['currency']); | ||
} | ||
} | ||
|
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
Oops, something went wrong.