Skip to content

Commit

Permalink
Declare HPOS as compatible (#385)
Browse files Browse the repository at this point in the history
* Declare HPOS as compatible

* add test for hpos enable

* update comment
  • Loading branch information
ajzkk authored Jul 26, 2023
1 parent dfc9963 commit a9fce91
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"homepage": "https://www.omise.co/",
"license": "MIT",
"require-dev": {
"phpunit/phpunit": "^5.7 || ^9.5"
"phpunit/phpunit": "^5.7 || ^9.5",
"mockery/mockery": "^1.6"
},
"scripts": {
"test": "vendor/bin/phpunit --testdox --colors"
}
}
14 changes: 14 additions & 0 deletions omise-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,26 @@ class Omise
*/
public function __construct()
{
add_action('before_woocommerce_init', [$this, 'enable_hpos']);
add_action('plugins_loaded', array($this, 'check_dependencies'));
add_action('woocommerce_init', array($this, 'init'));
do_action('omise_initiated');
add_action('admin_notices', [$this, 'embedded_form_notice']);
}

/**
* enable high performance order storage(HPOS) feature
*/
public function enable_hpos() {
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'custom_order_tables',
__FILE__,
true
);
}
}

/**
* Notice for users informing about embedded form
*/
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/omise-woocommerce-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

use Omise;
use Mockery;
use PHPUnit\Framework\TestCase;

class Omise_Test extends TestCase
{
private Omise $model;

/**
* setup add_action and do_action before the test run
*/
public function setUp(): void
{
if (!function_exists('add_action')) {
function add_action()
{
}
}
if (!function_exists('do_action')) {
function do_action()
{
}
}
require_once __DIR__ . '/../../omise-woocommerce.php';
$this->model = Omise::instance();
}

/**
* close mockery after test cases are done
*/
public function tearDown(): void
{
Mockery::close();
}

/**
* Making sure that when FeaturesUtil class do not exist,
* it doesn't throw any error
*/
public function test_when_features_util_class_do_not_exist()
{
$this->model->enable_hpos();
$this->assertFalse(class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class));
}

/**
* Making sure that when FeaturesUti class exist,
* it doesn't throw any error and the 'declare_compatibility' method should be called once
*/
public function test_when_features_util_class_exist()
{
$featuresUtilMock = Mockery::mock('alias:\Automattic\WooCommerce\Utilities\FeaturesUtil');
$featuresUtilMock->shouldReceive('declare_compatibility')->once();
$this->model->enable_hpos();
$this->assertTrue(class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class));
}
}

0 comments on commit a9fce91

Please sign in to comment.