diff --git a/.gitignore b/.gitignore index b693fac..a13ce21 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ /.php-cs-fixer.cache # PHPUnit +/.phpunit.cache/ /.phpunit.result.cache # WordPress diff --git a/composer.json b/composer.json index 75348cb..9440b59 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0554948..0ddf1f8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,19 @@ - + tests/src - - + + + + + + src - + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 012503c..4c7cbac 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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'; diff --git a/tests/src/AddressTest.php b/tests/src/AddressTest.php index 97e9029..be35b8c 100644 --- a/tests/src/AddressTest.php +++ b/tests/src/AddressTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Address test diff --git a/tests/src/DataHelperTest.php b/tests/src/DataHelperTest.php index fd7cb79..130c7c0 100644 --- a/tests/src/DataHelperTest.php +++ b/tests/src/DataHelperTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Data helper test diff --git a/tests/src/ErrorTest.php b/tests/src/ErrorTest.php index 0d2044a..01d148f 100644 --- a/tests/src/ErrorTest.php +++ b/tests/src/ErrorTest.php @@ -10,6 +10,8 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; + /** * Error test * @@ -17,7 +19,7 @@ * @version 2.1.10 * @since 2.0.2 */ -class ErrorTest extends \PHPUnit\Framework\TestCase { +class ErrorTest extends TestCase { /** * Get test error. * diff --git a/tests/src/NotificationTest.php b/tests/src/NotificationTest.php index 12233db..8dc641b 100644 --- a/tests/src/NotificationTest.php +++ b/tests/src/NotificationTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Notification test diff --git a/tests/src/OrderAnnounceResponseTest.php b/tests/src/OrderAnnounceResponseTest.php index 7a6046a..ebd5e01 100644 --- a/tests/src/OrderAnnounceResponseTest.php +++ b/tests/src/OrderAnnounceResponseTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Order results test diff --git a/tests/src/OrderItemTest.php b/tests/src/OrderItemTest.php index 9c5085a..34eca6f 100644 --- a/tests/src/OrderItemTest.php +++ b/tests/src/OrderItemTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Order item test diff --git a/tests/src/OrderResultsTest.php b/tests/src/OrderResultsTest.php index 8134b38..097a3e3 100644 --- a/tests/src/OrderResultsTest.php +++ b/tests/src/OrderResultsTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Order results test diff --git a/tests/src/OrderTest.php b/tests/src/OrderTest.php index f556000..f5abefd 100644 --- a/tests/src/OrderTest.php +++ b/tests/src/OrderTest.php @@ -11,7 +11,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; use DateTime; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Order test diff --git a/tests/src/PaymentBrandsTest.php b/tests/src/PaymentBrandsTest.php index 92efafe..93b63fc 100644 --- a/tests/src/PaymentBrandsTest.php +++ b/tests/src/PaymentBrandsTest.php @@ -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 diff --git a/tests/src/ReturnParametersTest.php b/tests/src/ReturnParametersTest.php index 51aa523..c056ace 100644 --- a/tests/src/ReturnParametersTest.php +++ b/tests/src/ReturnParametersTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Return parameters test diff --git a/tests/src/SecurityTest.php b/tests/src/SecurityTest.php index c6093b0..6acc630 100644 --- a/tests/src/SecurityTest.php +++ b/tests/src/SecurityTest.php @@ -10,7 +10,7 @@ namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; -use PHPUnit\Framework\TestCase; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; /** * Security test diff --git a/tests/src/StatusesTest.php b/tests/src/StatusesTest.php index 243c6f0..a3d3458 100644 --- a/tests/src/StatusesTest.php +++ b/tests/src/StatusesTest.php @@ -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 diff --git a/tests/src/WebhookControllerTest.php b/tests/src/WebhookControllerTest.php index ab0863c..aac0f3a 100644 --- a/tests/src/WebhookControllerTest.php +++ b/tests/src/WebhookControllerTest.php @@ -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. *