Skip to content

Commit 49f38d7

Browse files
SP-812 - Build WooCommerce testing into the pipeline
1 parent 95a00ca commit 49f38d7

File tree

3 files changed

+69
-60
lines changed

3 files changed

+69
-60
lines changed

.github/workflows/tests.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
unit:
7+
runs-on: ubuntu-24.04
8+
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php-version: [8.1, 8.2, 8.3]
13+
14+
services:
15+
mysql:
16+
image: mysql:latest
17+
env:
18+
MYSQL_ALLOW_EMPTY_PASSWORD: false
19+
MYSQL_ROOT_PASSWORD: root
20+
MYSQL_DATABASE: bitpay-wordpress-test
21+
ports:
22+
- 3306:3306
23+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Install Composer dependencies
28+
run: composer install --no-progress --prefer-dist --optimize-autoloader
29+
- name: Install WordPress with WooCommerce
30+
run: |
31+
cd ..
32+
rm -fr wordpress
33+
mkdir wordpress
34+
cd wordpress
35+
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
36+
php wp-cli.phar core download
37+
php wp-cli.phar config create --dbname=bitpay-wordpress-test --dbuser=root --dbpass=root --dbhost=127.0.0.1
38+
php wp-cli.phar core install --url=bitpay-wordpress.test --title=Example --admin_user=admin --admin_password=admin [email protected]
39+
php wp-cli.phar plugin install --activate woocommerce
40+
cp -R ../bitpay-checkout-for-woocommerce wp-content/plugins/bitpay-checkout-for-woocommerce
41+
cp ../bitpay-checkout-for-woocommerce/tests/Unit/wp-config.dist.php wp-content/plugins/bitpay-checkout-for-woocommerce/tests/Unit/wp-config.php
42+
cp ../bitpay-checkout-for-woocommerce/tests/Unit/index.tests.php wp-content/plugins/bitpay-checkout-for-woocommerce/index.php
43+
php wp-cli.phar plugin activate bitpay-checkout-for-woocommerce
44+
- name: Run tests
45+
run: |
46+
cd ../wordpress/wp-content/plugins/bitpay-checkout-for-woocommerce
47+
./vendor/bin/phpunit -c phpunit.xml.dist

tests/Unit/index.tests.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Plugin Name: BitPay Checkout for WooCommerce
4+
* Plugin URI: https://www.bitpay.com
5+
* Description: BitPay Checkout Plugin
6+
* Version: 6.0.0
7+
* Author: BitPay
8+
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
9+
*/
10+
11+
require_once __DIR__ . '/vendor/autoload.php';
12+
require_once __DIR__ . '/vendor/netresearch/jsonmapper/src/JsonMapper.php';
13+
14+
use BitPayLib\BitPayPluginSetup;
15+
16+
if ( ! defined( 'ABSPATH' ) ) {
17+
exit;
18+
}
19+
20+
$bitpay_plugin_setup = new BitPayPluginSetup();
21+
$bitpay_plugin_setup->execute();

tests/Unit/wp-config.dist.php

+1-60
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,6 @@
11
<?php
22

3-
/* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */
4-
define( 'ABSPATH', __DIR__ . '/../../../../../' );
5-
6-
/*
7-
* Path to the theme to test with.
8-
*
9-
* The 'default' theme is symlinked from test/phpunit/data/themedir1/default into
10-
* the themes directory of the WordPress installation defined above.
11-
*/
12-
define( 'WP_DEFAULT_THEME', 'default' );
13-
14-
/*
15-
* Test with multisite enabled.
16-
* Alternatively, use the tests/phpunit/multisite.xml configuration file.
17-
*/
18-
// define( 'WP_TESTS_MULTISITE', true );
19-
20-
/*
21-
* Force known bugs to be run.
22-
* Tests with an associated Trac ticket that is still open are normally skipped.
23-
*/
24-
// define( 'WP_TESTS_FORCE_KNOWN_BUGS', true );
25-
26-
// Test with WordPress debug mode (default).
27-
define( 'WP_DEBUG', true );
28-
29-
// ** MySQL settings ** //
30-
31-
/*
32-
* This configuration file will be used by the copy of WordPress being tested.
33-
* wordpress/wp-config.php will be ignored.
34-
*
35-
* WARNING WARNING WARNING!
36-
* These tests will DROP ALL TABLES in the database with the prefix named below.
37-
* DO NOT use a production database or one that is shared with something else.
38-
*/
39-
40-
define( 'DB_NAME', 'youremptytestdbnamehere' );
41-
define( 'DB_USER', 'yourusernamehere' );
42-
define( 'DB_PASSWORD', 'yourpasswordhere' );
43-
define( 'DB_HOST', 'localhost' );
44-
define( 'DB_CHARSET', 'utf8' );
45-
define( 'DB_COLLATE', '' );
46-
47-
/**#@+
48-
* Authentication Unique Keys and Salts.
49-
*
50-
* Change these to different unique phrases!
51-
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
52-
*/
53-
define( 'AUTH_KEY', 'put your unique phrase here' );
54-
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
55-
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
56-
define( 'NONCE_KEY', 'put your unique phrase here' );
57-
define( 'AUTH_SALT', 'put your unique phrase here' );
58-
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
59-
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
60-
define( 'NONCE_SALT', 'put your unique phrase here' );
61-
62-
$table_prefix = 'wptests_'; // Only numbers, letters, and underscores please!
3+
require_once '../../../wp-config.php';
634

645
define( 'WP_TESTS_DOMAIN', 'example.org' );
656
define( 'WP_TESTS_EMAIL', '[email protected]' );

0 commit comments

Comments
 (0)