Skip to content

Commit 121918f

Browse files
authored
devops: Test Scripts updated. (#702)
* devops: Test Scripts updated. * chore: WPCS compliance met.
1 parent 0a54ce9 commit 121918f

File tree

10 files changed

+273
-323
lines changed

10 files changed

+273
-323
lines changed

bin/_lib.sh

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
set +u
44

5-
install_wordpress() {
6-
if [ -f $WP_CORE_DIR/wp-config.php ]; then
7-
echo "Wordpress already installed."
8-
return;
9-
fi
10-
5+
composer_wordpress_config() {
116
# Set the wordpress install directory and plugin paths in the composer.json
127
composer config --unset extra.wordpress-install-dir;
138
composer config extra.wordpress-install-dir $WP_CORE_DIR;
@@ -19,14 +14,30 @@ install_wordpress() {
1914
\"$THEMES_DIR/{\$name}/\": [\"type:wordpress-theme\"]
2015
}"
2116

17+
# Set WPackagist repository
18+
composer config repositories.wpackagist composer https://wpackagist.org
19+
20+
# Enable plugins
21+
composer config --no-plugins allow-plugins.composer/installers true
22+
composer config --no-plugins allow-plugins.johnpbloch/wordpress-core-installer true
23+
}
24+
25+
install_wordpress() {
26+
if [ -f $WP_CORE_DIR/wp-config.php ]; then
27+
echo "Wordpress already installed."
28+
return;
29+
fi
30+
31+
composer_wordpress_config
32+
2233
# Install Wordpress + integrated plugins for testing/development.
2334
composer install
2435
composer require --dev -W \
2536
johnpbloch/wordpress:* \
2637
wp-graphql/wp-graphql-jwt-authentication \
2738
wpackagist-plugin/woocommerce \
2839
wpackagist-plugin/woocommerce-gateway-stripe \
29-
wpackagist-plugin/wp-graphql:* \
40+
wpackagist-plugin/wp-graphql \
3041
wpackagist-theme/twentytwentyone \
3142
wp-cli/wp-cli-bundle
3243
}
@@ -52,8 +63,11 @@ install_local_test_library() {
5263
# Install testing library dependencies.
5364
composer install
5465
composer require --dev \
55-
lucatume/wp-browser \
56-
codeception/module-asserts:^1.0 \
66+
lucatume/wp-browser:^3.1 \
67+
codeception/codeception:^4.2 \
68+
symfony/finder:* \
69+
codeception/lib-asserts:^1.0 \
70+
codeception/module-asserts:^1.3.1 \
5771
codeception/module-rest:^2.0 \
5872
codeception/util-universalframework:^1.0 \
5973
wp-graphql/wp-graphql-testcase:^2.3 \
@@ -82,12 +96,25 @@ remove_local_test_library() {
8296
# Remove testing library dependencies.
8397
composer remove --dev wp-graphql/wp-graphql-testcase \
8498
codeception/module-asserts \
99+
codeception/codeception \
100+
codeception/lib-asserts \
101+
symfony/finder \
85102
codeception/module-rest \
86103
codeception/util-universalframework \
87104
lucatume/wp-browser \
88105
stripe/stripe-php
89106
}
90107

108+
cleanup_composer_file() {
109+
echo "Removing extra config..."
110+
composer config --unset extra
111+
echo "Removing repositories..."
112+
composer config --unset repositories
113+
114+
composer config --unset config.allow-plugins
115+
echo "composer.json cleaned!"
116+
}
117+
91118
cleanup_local_files() {
92119
if [ -n "$(ls -A $WP_CORE_DIR)" ]; then
93120
echo "Removing final test files..."
@@ -98,7 +125,7 @@ cleanup_local_files() {
98125
fi
99126

100127
echo "Rebuilding lock file..."
101-
rm -rf $PROJECT_ROOT_DIR/vendor $PROJECT_ROOT_DIR/composer.lock
128+
rm -rf $PROJECT_ROOT_DIR/vendor
102129
composer install --no-dev
103130
}
104131

bin/cleanup.local.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ remove_wordpress
2525
# Delete symlink to
2626
remove_project_symlink
2727

28-
# Remove "extra" config.
29-
composer config --unset extra.wordpress-install-dir
30-
composer config --unset extra.installer-paths
31-
3228
# Remove testing dependencies from Composer.
3329
remove_local_test_library
3430

31+
# Clean composer.json.
32+
cleanup_composer_file
33+
3534
# Delete any missed files in the removal of the local installation.
3635
# And rebuild composer.lock
3736
cleanup_local_files

composer.json

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
"role": "Lead developer"
2121
}
2222
],
23-
"repositories": [
24-
{
25-
"type": "composer",
26-
"url": "https://wpackagist.org"
27-
}
28-
],
2923
"require": {
3024
"php": ">=7.1.0",
3125
"firebase/php-jwt": "^6.1.0"
@@ -39,27 +33,24 @@
3933
"process-timeout": 0,
4034
"sort-packages": true,
4135
"allow-plugins": {
42-
"johnpbloch/wordpress-core-installer": true,
43-
"composer/installers": true
36+
"johnpbloch/wordpress-core-installer": true
4437
}
4538
},
4639
"autoload-dev": {
4740
"files": [
4841
"tests/_data/config.php"
4942
],
5043
"psr-4": {
51-
"Tests\\WPGraphQL\\WooCommerce\\": "tests/_support/"
44+
"Tests\\WPGraphQL\\WooCommerce\\": "tests/_support/"
5245
}
5346
},
54-
"extra": {
55-
},
5647
"scripts": {
5748
"installTestEnv": "bash bin/install-test-env.local.sh",
5849
"runPreCommitCleanup": "bash bin/cleanup.local.sh",
5950
"runWPUnitTest": "vendor/bin/codecept run wpunit",
6051
"dBuild": "env $(sed -e '/^#/d' .env.testing) docker-compose build",
6152
"dRunApp": "env $(sed -e '/^#/d' .env.testing) docker-compose up testable_app app_db mailhog",
62-
"dRunTestingDb":"if [ ! \"$(docker ps -a | grep testing_db)\" ]; then env $(sed -e '/^#/d' .env.testing) docker-compose up -d testing_db; fi",
53+
"dRunTestingDb": "if [ ! \"$(docker ps -a | grep testing_db)\" ]; then env $(sed -e '/^#/d' .env.testing) docker-compose up -d testing_db; fi",
6354
"dSetMainDb": "docker-compose exec testable_app ./setup-database.sh main",
6455
"dSetTestingDb": "docker-compose exec testable_app wait-for-it -s -t 300 testing_db:3306 -- ./setup-database.sh testing",
6556
"dRunTest": [
@@ -69,30 +60,31 @@
6960
],
7061
"dRunTestStandalone": "env $(sed -e '/^#/d' .env.testing) docker-compose run --rm run_tests",
7162
"dDestroy": "docker-compose down -v",
72-
"lint": "vendor/bin/phpcs -vp ."
63+
"lint": "vendor/bin/phpcs -vp .",
64+
"fix": "vendor/bin/phpcbf -vp ."
7365
},
7466
"support": {
7567
"issues": "https://github.com/wp-graphql/wp-graphql-woocommerce/issues",
7668
"source": "https://github.com/wp-graphql/wp-graphql-woocommerce"
7769
},
7870
"archive": {
79-
"name": "wp-graphql-wooocommerce",
80-
"exclude": [
81-
"/.*",
82-
"/bin",
83-
"/docs",
84-
"/local",
85-
"/plugin-build",
86-
"/tests",
87-
"!/vendor",
88-
"/codeception.dist.yml",
89-
"/codeception.yml",
90-
"/composer.json",
91-
"/composer.lock",
92-
"/docker-compose.yml",
93-
"/Dockerfile",
94-
"/netlify.toml",
95-
"/README.md"
96-
]
71+
"name": "wp-graphql-wooocommerce",
72+
"exclude": [
73+
"/.*",
74+
"/bin",
75+
"/docs",
76+
"/local",
77+
"/plugin-build",
78+
"/tests",
79+
"!/vendor",
80+
"/codeception.dist.yml",
81+
"/codeception.yml",
82+
"/composer.json",
83+
"/composer.lock",
84+
"/docker-compose.yml",
85+
"/Dockerfile",
86+
"/netlify.toml",
87+
"/README.md"
88+
]
9789
}
9890
}

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ services:
44
# Main application database.
55
app_db:
66
image: mysql
7-
volumes:
8-
- app_db_data
97
command: --default-authentication-plugin=mysql_native_password
108
environment:
119
MYSQL_ROOT_PASSWORD: ${ROOT_PASSWORD:-password}
@@ -43,7 +41,8 @@ services:
4341
env_file: .env.testing
4442
environment:
4543
APACHE_RUN_USER: "#1000" # Ensure Apache can write to the filesystem.
46-
XDEBUG_CONFIG: remote_host=10.0.0.52 idekey=vscode
44+
DOCKER_GATEWAY_HOST: "172.17.0.1"
45+
XDEBUG_CONFIG: remote_host=${DOCKER_GATEWAY_HOST:-host.docker.internal} idekey=vscode
4746
networks:
4847
development:
4948
ports:
@@ -99,6 +98,3 @@ services:
9998
networks:
10099
development:
101100
testing:
102-
103-
volumes:
104-
app_db_data: {}

includes/connection/class-orders.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,29 @@ private static function get_customer_order_connection( $resolver, $customer ) {
114114
}
115115

116116
$meta_query = false;
117-
if ( ! empty ( $customer->get_id() ) ) {
117+
if ( ! empty( $customer->get_id() ) ) {
118118
$meta_query = [
119119
[
120-
'key' => '_customer_user',
121-
'value' => $customer->get_id(),
122-
'compare' => '=',
120+
'key' => '_customer_user',
121+
'value' => $customer->get_id(),
122+
'compare' => '=',
123123
],
124124
];
125-
} else if ( ! empty( $customer->get_billing_email() ) ) {
125+
} elseif ( ! empty( $customer->get_billing_email() ) ) {
126126
$meta_query = [
127127
'relation' => 'AND',
128128
[
129-
'key' => '_billing_email',
130-
'value' => $customer->get_billing_email(),
131-
'compare' => '=',
129+
'key' => '_billing_email',
130+
'value' => $customer->get_billing_email(),
131+
'compare' => '=',
132132
],
133133
[
134-
'key' => '_customer_user',
135-
'value' => 0,
136-
'compare' => '=',
137-
]
134+
'key' => '_customer_user',
135+
'value' => 0,
136+
'compare' => '=',
137+
],
138138
];
139-
}
139+
}//end if
140140

141141
// Bail if needed info not found on customer object.
142142
if ( false === $meta_query ) {

includes/connection/class-products.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ public static function set_ordering_query_args( $resolver, $args ) {
366366
'_wc_average_rating',
367367
'_sale_price_dates_from',
368368
'_sale_price_dates_to',
369-
'total_sales'
369+
'total_sales',
370370
];
371-
$sort_fields = apply_filters( 'graphql_woocommerce_products_add_sort_fields', $default_fields );
371+
$sort_fields = apply_filters( 'graphql_woocommerce_products_add_sort_fields', $default_fields );
372372
foreach ( $args['where']['orderby'] as $orderby_input ) {
373-
if (in_array($orderby_input['field'], $sort_fields)){
373+
if ( in_array( $orderby_input['field'], $sort_fields, true ) ) {
374374
$order = $orderby_input['order'];
375375

376376
if ( $backward ) {
@@ -546,7 +546,7 @@ public static function get_connection_args(): array {
546546
* @return array Query arguments.
547547
*/
548548
public static function map_input_fields_to_wp_query( $query_args, $args, $source, $all_args, $context, $info, $post_type ) {
549-
$post_type = is_array( $post_type ) ? $post_type : array( $post_type );
549+
$post_type = is_array( $post_type ) ? $post_type : [ $post_type ];
550550
if ( ! in_array( 'product', $post_type, true ) && ! in_array( 'product_variation', $post_type, true ) ) {
551551
return $query_args;
552552
}

tests/_support/Factory/OrderFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function add_tax( $order, $args = [], $save = true ) {
340340
}
341341

342342
public function set_to_customer_billing_address( $order, $customer, $save = true ) {
343-
$order = \wc_get_order( $order );
343+
$order = \wc_get_order( $order );
344344
if ( ! $customer ) {
345345
return $order;
346346
}
@@ -366,7 +366,7 @@ public function set_to_customer_billing_address( $order, $customer, $save = true
366366
}
367367

368368
public function set_to_customer_shipping_address( $order, $customer, $save = true ) {
369-
$order = \wc_get_order( $order );
369+
$order = \wc_get_order( $order );
370370
if ( ! $customer ) {
371371
return $order;
372372
}

0 commit comments

Comments
 (0)