Skip to content

Commit

Permalink
Merge pull request #746 from ebanx/quality/mock-unit-function
Browse files Browse the repository at this point in the history
Using WP_Mock to mock wp functions
  • Loading branch information
Ruanito authored Feb 21, 2019
2 parents 11dda78 + 9f37e81 commit 79eb05a
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 24 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "*",
"wp-coding-standards/wpcs": "^0.14",
"exussum12/coverage-checker": "^0.8.0"
"exussum12/coverage-checker": "^0.8.0",
"10up/wp_mock": "0.2.0"
},
"scripts": {
"test": "phpunit",
Expand Down
202 changes: 201 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/unit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
define('WC_EBANX_VENDOR_DIR', realpath('.') . '/vendor/');
define('IS_TEST', true);


require __DIR__ . '/includes/wc_class.php';
require __DIR__ . '/includes/wc_function.php';
//require __DIR__ . '/includes/wc_function.php';
require WC_EBANX_VENDOR_DIR . '/autoload.php';

require_once realpath('.') . '/gateways/class-wc-ebanx-global-gateway.php';

Expand Down
21 changes: 0 additions & 21 deletions tests/unit/includes/wc_function.php

This file was deleted.

10 changes: 10 additions & 0 deletions tests/unit/services/EbanxHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
use PHPUnit\Framework\TestCase;

class EbanxHelperTest extends TestCase {
public function setUp() {
\WP_Mock::setUp();
}
public function testPluginCheckArray() {
\WP_Mock::userFunction( 'get_woocommerce_currency', [
'return_in_order' => ['BRL']
]);
\WP_Mock::userFunction( 'get_plugins', array(
'return_in_order' => array([['Version' => '0.0.1', 'Name' => 'Mock']])
));

$config = new WC_EBANX_Global_Gateway();
$plugin_check = WC_EBANX_Helper::plugin_check($config);
$this->assertPluginCheck($plugin_check);
Expand Down

0 comments on commit 79eb05a

Please sign in to comment.