Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
= 1.3.0 =

Bugs we fixed:

* Fixed error during plugin uninstall.

= 1.2.1 =

Enhancements:
Expand Down
48 changes: 48 additions & 0 deletions tests/phpunit/test-class-uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Class Uninstall_Test
*
* @package Progress_Planner\Tests
*/

namespace Progress_Planner\Tests;

/**
* Uninstall test case.
*/
class Uninstall_Test extends \WP_UnitTestCase {

/**
* Test that the uninstall file runs without fatal error.
*
* @return void
*/
public function test_uninstall_file_runs_without_fatal_error() {
$uninstall_file = plugin_dir_path( __DIR__ ) . '../uninstall.php';

$this->assertFileExists( $uninstall_file, 'Uninstall file does not exist.' );

// Catch fatal errors.
$errors = [];
set_error_handler( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler
function ( $errno, $errstr ) use ( &$errors ) {
$errors[] = "$errno: $errstr";
return true; // prevent default error handler.
}
);

// Needed to simulate WordPress uninstall context.
define( 'WP_UNINSTALL_PLUGIN', true );

// Include the uninstall script.
try {
require $uninstall_file;
} catch ( \Throwable $e ) {
$this->fail( 'Fatal error during uninstall.php: ' . $e->getMessage() );
}

restore_error_handler();

$this->assertEmpty( $errors, 'Uninstall file caused PHP warnings or errors: ' . implode( ', ', $errors ) );
}
}
2 changes: 1 addition & 1 deletion uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

require_once __DIR__ . '/classes/class-settings.php';
require_once __DIR__ . '/classes/class-query.php';
require_once __DIR__ . '/classes/activities/class-query.php';

/**
* Delete the plugin options.
Expand Down
Loading