Skip to content

Commit

Permalink
separate class for file get contents
Browse files Browse the repository at this point in the history
  • Loading branch information
ajzkk committed Oct 16, 2023
1 parent 9a1a3d6 commit 0d4e32f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/gateway/class-omise-payment-promptpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function init_form_fields() {
* @param string $id Value to be added in the id attribute of the svg element
*/
private function load_qr_svg_to_DOM($url, $id = null) {
$svg_file = $this->file_get_contents($url);
$svg_file = File_Get_Contents_Wrapper::get_contents($url);

$find_string = '<svg';
$position = strpos($svg_file, $find_string);
Expand Down
1 change: 1 addition & 0 deletions includes/libraries/omise-plugin/Omise.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
require_once dirname(__FILE__).'/helpers/request.php';
require_once dirname(__FILE__).'/helpers/token.php';
require_once dirname(__FILE__).'/helpers/RedirectUrl.php';
require_once dirname(__FILE__).'/helpers/file_get_contents_wrapper.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* file_get_contents wrapper class
*
* Since we cannot mock global function,
* we have to create a wrapper for file_get_contents.
*/
class File_Get_Contents_Wrapper
{
public static function get_contents($url)
{
return file_get_contents($url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Omise_Payment_Promptpay_Test extends Omise_Payment_Offline_Test
public $mockOmisePluginHelper;
public $mockOmisePaymentOffline;
public $mockOmiseCharge;
public $mockFileGetContent;

public function setUp(): void
{
Expand All @@ -23,6 +24,7 @@ function admin_url() {}
$this->mockOmisePluginHelper = Mockery::mock('overload:OmisePluginHelperWcOrder')->shouldIgnoreMissing();
$this->mockOmisePaymentOffline = Mockery::mock('overload:Omise_Payment_Offline');
$this->mockOmiseCharge = Mockery::mock('overload:OmiseCharge');
$this->mockFileGetContent = Mockery::mock('overload:File_Get_Contents_Wrapper');

require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-promptpay.php';
}
Expand All @@ -34,6 +36,8 @@ public function textExpiresAtFieldIsPassedToJavascript()
{
$expiresAt = '2023-11-22T14:48:00.000Z';

$this->mockFileGetContent->shouldReceive('get_contents')->once();

$this->mockOmisePaymentOffline->shouldReceive('init_settings');
$this->mockOmisePaymentOffline->shouldReceive('get_option');
$this->mockOmisePaymentOffline->shouldReceive('load_order')->andReturn(true);
Expand Down

0 comments on commit 0d4e32f

Please sign in to comment.