Skip to content

Commit

Permalink
Update unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed May 2, 2024
1 parent c4994aa commit a9ac56d
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/.php-cs-fixer.cache

# PHPUnit
/.phpunit.cache/
/.phpunit.result.cache

# WordPress
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"automattic/jetpack-autoloader": true
}
},
"repositories": [
{
"url": "https://github.com/wordpress/sqlite-database-integration.git",
"type": "git"
}
],
"require": {
"php": ">=8.0",
"automattic/jetpack-autoloader": "^3.0",
Expand All @@ -56,7 +62,8 @@
"roots/wordpress": "^6.4",
"sirbrillig/phpcs-variable-analysis": "^2.11",
"slevomat/coding-standard": "^8.15",
"wp-phpunit/wp-phpunit": "^6.4",
"wordpress/sqlite-database-integration": "^2.1",
"wp-phpunit/wp-phpunit": "^6.5",
"yoast/phpunit-polyfills": "^2.0"
},
"scripts": {
Expand Down
19 changes: 8 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" backupGlobals="false" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="unit">
<directory>tests/src</directory>
</testsuite>
</testsuites>

<coverage>

<php>
<env name="WP_PHPUNIT__TESTS_CONFIG" value="tests/wp-config.php"/>
</php>

<source>
<include>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
60 changes: 55 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,67 @@
* @package Pronamic\WordPress\Pay\Gateways\OmniKassa2
*/

putenv( 'WP_PHPUNIT__TESTS_CONFIG=tests/wp-config.php' );
/**
* Give access to tests_add_filter() function.
*
* @link https://github.com/wp-phpunit/example-plugin/blob/master/tests/bootstrap.php
*/
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';

require_once __DIR__ . '/../vendor/autoload.php';
/**
* Psalm.
*/
if ( defined( 'PSALM_VERSION' ) ) {
return;
}

require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
/**
* SQLite integration.
*
* @link https://github.com/WordPress/sqlite-database-integration/issues/7#issuecomment-1646660980
* @link https://github.com/wp-phpunit/example-plugin/blob/master/tests/bootstrap.php
* @link https://github.com/WordPress/wordpress-playground/blob/23c0fc6aae5d090a14d352160c34d39988167406/packages/playground/wordpress/build/Dockerfile#L25-L42
*/
if ( ! is_dir( __DIR__ . '/../wordpress/wp-content/' ) ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.directory_mkdir
mkdir( __DIR__ . '/../wordpress/wp-content/' );
}

$db_dropin_file = __DIR__ . '/../wordpress/wp-content/db.php';

if ( ! is_file( $db_dropin_file ) ) {
// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
file_put_contents(
$db_dropin_file,
str_replace(
[
'{SQLITE_IMPLEMENTATION_FOLDER_PATH}',
'{SQLITE_PLUGIN}',
],
[
__DIR__ . '/../vendor/wordpress/sqlite-database-integration',
'sqlite-database-integration/load.php',
],
file_get_contents( __DIR__ . '/../vendor/wordpress/sqlite-database-integration/db.copy' )
)
);
}

/**
* Plugin.
*/
tests_add_filter(
'muplugins_loaded',
function() {
function () {
require __DIR__ . '/../vendor/wordpress/sqlite-database-integration/load.php';

require __DIR__ . '/../pronamic-pay-with-rabo-smart-pay.php';
}
}
);

/**
* Start up the WP testing environment.
*
* @link https://github.com/wp-phpunit/example-plugin/blob/master/tests/bootstrap.php
*/
require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php';
2 changes: 1 addition & 1 deletion tests/src/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Address test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/DataHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Data helper test
Expand Down
4 changes: 3 additions & 1 deletion tests/src/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Error test
*
* @author Remco Tolsma
* @version 2.1.10
* @since 2.0.2
*/
class ErrorTest extends \PHPUnit\Framework\TestCase {
class ErrorTest extends TestCase {
/**
* Get test error.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/src/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Notification test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/OrderAnnounceResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Order results test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/OrderItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Order item test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/OrderResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Order results test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use DateTime;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Order test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/PaymentBrandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Pronamic\WordPress\Pay\Core\PaymentMethods;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Payment brands test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/ReturnParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Return parameters test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Security test
Expand Down
2 changes: 1 addition & 1 deletion tests/src/StatusesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;

use PHPUnit\Framework\TestCase;
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Statuses test
Expand Down
4 changes: 2 additions & 2 deletions tests/src/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
use Pronamic\WordPress\Pay\Plugin;
use WP_REST_Request;
use WP_UnitTestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* Webhook controller test class
*/
class WebhookControllerTest extends WP_UnitTestCase {
class WebhookControllerTest extends TestCase {
/**
* REST server.
*
Expand Down

0 comments on commit a9ac56d

Please sign in to comment.