Skip to content

Commit

Permalink
Add code coverage for omise-block-duitnow-obw.php and omise-block-fpx…
Browse files Browse the repository at this point in the history
….php
  • Loading branch information
Aashish committed Jun 5, 2024
1 parent a9750e0 commit 19ef73f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use PHPUnit\Framework\TestCase;
use Brain\Monkey;

class Omise_Block_DuitNow_OBW_Test extends TestCase
{
use MockPaymentGateways;

public function setUp(): void
{
parent::setUp();
$this->mockWcGateways();
require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php';
require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-duitnow-obw.php';
}

/**
* @test
*/
public function set_additional_data()
{
Monkey\Functions\expect('get_option')->andReturn(null);
$obj = new Omise_Block_DuitNow_OBW;
$obj->initialize();
$obj->set_additional_data();

$clazz = new \ReflectionClass($obj);
$property = $clazz->getProperty('additional_data');
$property->setAccessible(true);
$result = $property->getValue($obj);

$this->assertIsArray($result);
$this->assertArrayHasKey('banks', $result);
}
}
36 changes: 36 additions & 0 deletions tests/unit/includes/blocks/gateways/omise-block-fpx-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use PHPUnit\Framework\TestCase;
use Brain\Monkey;

class Omise_Block_FPX_Test extends TestCase
{
use MockPaymentGateways;

public function setUp(): void
{
parent::setUp();
$this->mockWcGateways();
require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php';
require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-fpx.php';
}

/**
* @test
*/
public function set_additional_data()
{
Monkey\Functions\expect('get_option')->andReturn(null);
$obj = new Omise_Block_Fpx;
$obj->initialize();
$obj->set_additional_data();

$clazz = new \ReflectionClass($obj);
$property = $clazz->getProperty('additional_data');
$property->setAccessible(true);
$result = $property->getValue($obj);

$this->assertIsArray($result);
$this->assertArrayHasKey('bank_list', $result);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

use PHPUnit\Framework\TestCase;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Brain\Monkey;

require_once __DIR__ . '/traits/mock-gateways.php';

class Omise_Block_Installment_test extends TestCase
{
// Adds Mockery expectations to the PHPUnit assertions count.
use MockeryPHPUnitIntegration, MockPaymentGateways;
use MockPaymentGateways;

public $obj;

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/includes/blocks/gateways/traits/mock-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public function get_view_data() {
};

$gateway->backend = new class {
public $banks = ['bank1', 'bank2'];

public function get_available_providers($currency) {
return $currency;
}

public function get_available_banks() {
return ['bank1', 'bank2'];
}
};

return [
Expand All @@ -63,6 +69,8 @@ public function get_available_providers($currency) {
'omise_atome' => $gateway,
'omise_mobilebanking' => $gateway,
'omise_installment' => $gateway,
'omise_fpx' => $gateway,
'omise_duitnow_obw' => $gateway,
];
}
}
Expand Down
20 changes: 18 additions & 2 deletions tests/unit/includes/blocks/omise-block-payments-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@ protected function setUp() : void
/**
* @test
*/
public function class_is_initialized()
public function register_payment_methods_registers_block_classes()
{
$this->expectNotToPerformAssertions();
$container = \Automattic\WooCommerce\Blocks\Package::container();

Monkey\Functions\expect('add_action')->andReturn(null);

new Omise_Block_Payments($container);
$obj = new Omise_Block_Payments($container);

$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty('payment_methods');
$payment_methods = $property->getValue($obj);

$mock = new class {
public function register($class) { }
};

foreach($payment_methods as $payment_method) {
$this->getMockBuilder($payment_method)
->disableOriginalConstructor()
->getMock();
}

$obj->register_payment_methods($mock);
}
}

0 comments on commit 19ef73f

Please sign in to comment.