Skip to content

Commit 88e1ea6

Browse files
authored
Workflows
1 parent adffa40 commit 88e1ea6

File tree

6 files changed

+166
-5
lines changed

6 files changed

+166
-5
lines changed

.github/workflows/php-code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
# Install PHP compatibility standards and required packages
9191
composer require --dev phpcompatibility/php-compatibility squizlabs/php_codesniffer wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer --no-interaction || true
9292
93-
# Set up PHPCompatibility standards properly - use direct path references
93+
# Set up PHPCompatibility standards properly
9494
vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility,vendor/wp-coding-standards/wpcs
9595
9696
# Verify configured standards

.github/workflows/wordpress-tests.yml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,69 @@ jobs:
286286
sudo cp -f /tmp/wordpress-tests-lib/wp-tests-config.php /wordpress-tests-lib/ || echo "::warning::Failed to copy wp-tests-config.php"
287287
fi
288288
289+
# Create or copy required class-basic-object.php file if missing
290+
if [ ! -f "/tmp/wordpress-tests-lib/includes/class-basic-object.php" ]; then
291+
echo "Creating missing class-basic-object.php file in /tmp/wordpress-tests-lib..."
292+
cat > "/tmp/wordpress-tests-lib/includes/class-basic-object.php" << 'EOF'
293+
<?php
294+
/**
295+
* Basic object, which other objects in WordPress extend.
296+
*
297+
* This is a simplified version for tests to fix the missing class issue.
298+
*/
299+
class Basic_Object {
300+
/**
301+
* Retrieve a value from an array with support for a default value.
302+
*
303+
* @param array $args Arguments.
304+
* @param string $key Key to retrieve.
305+
* @param mixed $default Default value.
306+
* @return mixed Value if set, default if not.
307+
*/
308+
protected function get_from_array( $args, $key, $default = null ) {
309+
if ( isset( $args[ $key ] ) ) {
310+
return $args[ $key ];
311+
}
312+
return $default;
313+
}
314+
}
315+
EOF
316+
fi
317+
318+
# Copy to the alternate path as well
319+
if [ ! -f "/wordpress-tests-lib/includes/class-basic-object.php" ]; then
320+
sudo mkdir -p /wordpress-tests-lib/includes/
321+
if [ -f "/tmp/wordpress-tests-lib/includes/class-basic-object.php" ]; then
322+
sudo cp -f /tmp/wordpress-tests-lib/includes/class-basic-object.php /wordpress-tests-lib/includes/ || echo "::warning::Failed to copy class-basic-object.php"
323+
else
324+
echo "Creating missing class-basic-object.php file in /wordpress-tests-lib..."
325+
sudo bash -c 'cat > "/wordpress-tests-lib/includes/class-basic-object.php" << "EOF"
326+
<?php
327+
/**
328+
* Basic object, which other objects in WordPress extend.
329+
*
330+
* This is a simplified version for tests to fix the missing class issue.
331+
*/
332+
class Basic_Object {
333+
/**
334+
* Retrieve a value from an array with support for a default value.
335+
*
336+
* @param array $args Arguments.
337+
* @param string $key Key to retrieve.
338+
* @param mixed $default Default value.
339+
* @return mixed Value if set, default if not.
340+
*/
341+
protected function get_from_array( $args, $key, $default = null ) {
342+
if ( isset( $args[ $key ] ) ) {
343+
return $args[ $key ];
344+
}
345+
return $default;
346+
}
347+
}
348+
EOF'
349+
fi
350+
fi
351+
289352
# Check WordPress core installation and verify db.php was copied
290353
if [ ! -d "/tmp/wordpress" ]; then
291354
echo "::error::WordPress core directory not created."
@@ -379,7 +442,7 @@ jobs:
379442
fi
380443
else
381444
# Standard execution for PHP 7.4
382-
echo "Running tests with PHP $PHP_VERSION standard mode"
445+
echo "Running tests with PHP $PHP_VERSION standard mode"
383446
vendor/bin/phpunit || {
384447
echo "::warning::Tests failed with standard execution, trying individual test files..."
385448
EXIT_CODE=0

bin/install-wp-tests.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,41 @@ install_test_suite() {
247247
}
248248
}
249249

250+
# Check for required files in the includes directory
251+
if [ ! -f "$WP_TESTS_DIR/includes/functions.php" ]; then
252+
echo "Error: functions.php not found in includes directory. Tests may not work properly."
253+
fi
254+
255+
# Create/download any missing required files
256+
if [ ! -f "$WP_TESTS_DIR/includes/class-basic-object.php" ]; then
257+
echo "Creating missing class-basic-object.php file..."
258+
cat > "$WP_TESTS_DIR/includes/class-basic-object.php" << 'EOT'
259+
<?php
260+
/**
261+
* Basic object, which other objects in WordPress extend.
262+
*
263+
* This is a simplified version for tests to fix the missing class issue.
264+
*/
265+
class Basic_Object {
266+
267+
/**
268+
* Retrieve a value from an array with support for a default value.
269+
*
270+
* @param array $args Arguments.
271+
* @param string $key Key to retrieve.
272+
* @param mixed $default Default value.
273+
* @return mixed Value if set, default if not.
274+
*/
275+
protected function get_from_array( $args, $key, $default = null ) {
276+
if ( isset( $args[ $key ] ) ) {
277+
return $args[ $key ];
278+
}
279+
return $default;
280+
}
281+
}
282+
EOT
283+
fi
284+
250285
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data || {
251286
echo "Failed to download test data - retrying once"
252287
svn cleanup $WP_TESTS_DIR/data
@@ -289,6 +324,16 @@ install_test_suite() {
289324
echo "Copying test files to /wordpress-tests-lib for compatibility"
290325
cp -R "$WP_TESTS_DIR"/* /wordpress-tests-lib/ 2>/dev/null || sudo cp -R "$WP_TESTS_DIR"/* /wordpress-tests-lib/ 2>/dev/null
291326

327+
# Ensure the class-basic-object.php exists in both locations
328+
if [ -f "$WP_TESTS_DIR/includes/class-basic-object.php" ] && [ ! -f "/wordpress-tests-lib/includes/class-basic-object.php" ]; then
329+
echo "Copying class-basic-object.php to alternate location"
330+
mkdir -p /wordpress-tests-lib/includes/ 2>/dev/null || sudo mkdir -p /wordpress-tests-lib/includes/ 2>/dev/null
331+
cp "$WP_TESTS_DIR/includes/class-basic-object.php" /wordpress-tests-lib/includes/ 2>/dev/null ||
332+
sudo cp "$WP_TESTS_DIR/includes/class-basic-object.php" /wordpress-tests-lib/includes/ 2>/dev/null
333+
elif [ ! -f "$WP_TESTS_DIR/includes/class-basic-object.php" ]; then
334+
echo "Warning: class-basic-object.php not found in source directory"
335+
fi
336+
292337
if [ ! -f "/wordpress-tests-lib/includes/functions.php" ]; then
293338
echo "Warning: Could not copy all files to /wordpress-tests-lib"
294339
else

run-phpunit.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@
5656
// Default arguments
5757
$default_args = [];
5858

59+
// Only add --no-deprecations flag for PHPUnit versions that support it (before PHPUnit 10)
60+
if (version_compare($phpunit_version, '10.0', '<')) {
61+
$default_args[] = '--no-deprecations';
62+
} else {
63+
// For PHPUnit 10+, the --no-deprecations flag is no longer supported
64+
// Deprecation notices are suppressed by default in newer PHPUnit versions
65+
if (function_exists('esc_html')) {
66+
echo esc_html("Skipping --no-deprecations flag for PHPUnit 10+") . "\n";
67+
} else {
68+
echo "Skipping --no-deprecations flag for PHPUnit 10+\n";
69+
}
70+
}
71+
5972
// PHP 8.x specific settings
6073
if ($php_major_version >= 8) {
6174
if (function_exists('esc_html')) {
@@ -72,9 +85,6 @@
7285
echo "Using PHP 8.3+ with PHPUnit requires special handling\n";
7386
}
7487

75-
// Add any PHP 8.3/8.4 specific flags
76-
$default_args[] = '--no-deprecations';
77-
7888
// For PHPUnit 10+
7989
if (version_compare($phpunit_version, '10.0', '>=')) {
8090
if (function_exists('esc_html')) {

tests/bootstrap.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@
4444
// Give access to tests_add_filter() function.
4545
require_once $_tests_dir . '/includes/functions.php';
4646

47+
// Check and handle missing class-basic-object.php file
48+
if ( ! file_exists( $_tests_dir . '/includes/class-basic-object.php' ) && file_exists( __DIR__ . '/class-basic-object.php' ) ) {
49+
// If class-basic-object.php is missing in test lib but exists locally, use our version
50+
echo "Using local class-basic-object.php as fallback..." . PHP_EOL;
51+
52+
// If the includes directory doesn't exist in the test directory, create it
53+
if ( ! file_exists( $_tests_dir . '/includes' ) ) {
54+
mkdir( $_tests_dir . '/includes', 0777, true );
55+
}
56+
57+
// Copy our local version to the test directory
58+
copy( __DIR__ . '/class-basic-object.php', $_tests_dir . '/includes/class-basic-object.php' );
59+
}
60+
4761
/**
4862
* Manually load the plugin being tested.
4963
*/

tests/class-basic-object.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Basic object, which objects in WordPress extend.
4+
*
5+
* This is a simplified version to fix the missing class-basic-object.php error
6+
* in the WordPress test suite.
7+
*
8+
* @package Simple_WP_Optimizer
9+
*/
10+
11+
/**
12+
* Basic_Object is a simple class that provides basic functionality.
13+
*/
14+
class Basic_Object {
15+
/**
16+
* Retrieve a value from an array with support for a default value.
17+
*
18+
* @param array $args Arguments.
19+
* @param string $key Key to retrieve.
20+
* @param mixed $default Default value.
21+
* @return mixed Value if set, default if not.
22+
*/
23+
protected function get_from_array( $args, $key, $default = null ) {
24+
if ( isset( $args[ $key ] ) ) {
25+
return $args[ $key ];
26+
}
27+
return $default;
28+
}
29+
}

0 commit comments

Comments
 (0)