Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare HPOS as compatible #385

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
ajzkk marked this conversation as resolved.
Show resolved Hide resolved
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));
}
}
Loading