-
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.
Covering abstract-omise-block-apm.php with tests. Changing setUp and …
…tearDown visibility to protected from public. Fixing failed test for class-omise-payment-duitnow-obw.php.
- Loading branch information
Aashish
committed
May 30, 2024
1 parent
bb5264b
commit df9b16a
Showing
30 changed files
with
192 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ vendor | |
.phpunit.result.cache | ||
composer.lock | ||
.nvmrc | ||
wp-content |
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
121 changes: 121 additions & 0 deletions
121
tests/unit/includes/blocks/gateways/abstract-omise-block-apm-test.php
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,121 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
use Brain\Monkey; | ||
|
||
class Omise_Block_Apm_Test extends TestCase | ||
{ | ||
// Adds Mockery expectations to the PHPUnit assertions count. | ||
use MockeryPHPUnitIntegration; | ||
|
||
public $obj; | ||
|
||
// @runInSeparateProcess | ||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-apm.php'; | ||
$this->obj = new class extends Omise_Block_Apm {}; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function initialize() | ||
{ | ||
$clazz = (object) [ | ||
'payment_gateways' => new class { | ||
function payment_gateways() { | ||
// dummy gateway | ||
$gateway = new class { | ||
public $supports = ['products']; | ||
|
||
public function is_available() { | ||
return true; | ||
} | ||
|
||
public function supports() { | ||
return $this->supports; | ||
} | ||
}; | ||
|
||
return [ | ||
'abc' => $gateway, | ||
'xyz' => $gateway, | ||
]; | ||
} | ||
} | ||
]; | ||
|
||
Monkey\Functions\expect('get_option')->andReturn(null); | ||
Monkey\Functions\expect('WC')->andReturn($clazz); | ||
|
||
$reflection = new \ReflectionClass($this->obj); | ||
$name_property = $reflection->getProperty('name'); | ||
$name_property->setAccessible(true); | ||
$name_property->setValue($this->obj, 'abc'); | ||
|
||
$this->obj->initialize(); | ||
|
||
$gateway_property = $reflection->getProperty('gateway'); | ||
$gateway_property->setAccessible(true); | ||
$gateway_val = $gateway_property->getValue($this->obj); | ||
|
||
$this->assertEquals('object', gettype($gateway_val)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function is_active() | ||
{ | ||
// Calling initialize() to set $gateway value | ||
$reflection = new \ReflectionClass($this->obj); | ||
$name_property = $reflection->getProperty('name'); | ||
$name_property->setAccessible(true); | ||
$name_property->setValue($this->obj, 'abc'); | ||
|
||
$this->obj->initialize(); | ||
|
||
$is_active = $this->obj->is_active(); | ||
$this->assertTrue($is_active); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function get_payment_method_data() | ||
{ | ||
// Calling initialize() to set $gateway value | ||
$reflection = new \ReflectionClass($this->obj); | ||
$name_property = $reflection->getProperty('name'); | ||
$name_property->setAccessible(true); | ||
$name_property->setValue($this->obj, 'abc'); | ||
|
||
$this->obj->initialize(); | ||
|
||
$data = $this->obj->get_payment_method_data(); | ||
|
||
$this->assertArrayHasKey('title', $data); | ||
$this->assertArrayHasKey('description', $data); | ||
$this->assertArrayHasKey('supports', $data); | ||
$this->assertEquals('array', gettype($data['supports'])); | ||
$this->assertEquals('abc', $data['name']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function get_payment_method_script_handles() | ||
{ | ||
Monkey\Functions\expect('wp_script_is')->andReturn(false); | ||
Monkey\Functions\expect('wp_register_script'); | ||
Monkey\Functions\expect('plugin_dir_url'); | ||
Monkey\Functions\expect('wp_enqueue_script'); | ||
|
||
$result = $this->obj->get_payment_method_script_handles(); | ||
|
||
$this->assertEquals([ 'wc-omise-one-click-apms-payments-blocks' ], $result); | ||
} | ||
} |
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 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
Oops, something went wrong.