Skip to content

Commit

Permalink
Tests: Ensure options are not set when tests run. (#95)
Browse files Browse the repository at this point in the history
* Introduce a test constant.

* Don't initialize when the tests are running.

* Use a new object for testing `Admin_Settings::get_setting()`.
  • Loading branch information
costdev authored Nov 2, 2024
1 parent 802a269 commit bb0d77a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
4 changes: 3 additions & 1 deletion aspire-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@

require_once __DIR__ . '/includes/autoload.php';

new AspireUpdate\Controller();
if ( ! defined( 'AP_RUN_TESTS' ) ) {
new AspireUpdate\Controller();
}
19 changes: 3 additions & 16 deletions tests/AdminSettings/AdminSettings_GetSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,16 @@
* @covers \AspireUpdate\Admin_Settings::get_setting
*/
class AdminSettings_GetSettingTest extends WP_UnitTestCase {
/**
* Shared instance of the class.
*
* @var \AspireUpdate\Admin_Settings
*/
private static $instance;

/**
* Set up before any tests run.
*/
public static function set_up_before_class() {
self::$instance = \AspireUpdate\Admin_Settings::get_instance();
}

/**
* Test that the default 'api_host' value is retrieved.
*
* @covers \AspireUpdate\Admin_Settings::get_default_settings
*/
public function test_should_get_default_api_host() {
$actual = self::$instance->get_setting( 'api_host' );
$admin_settings = new \AspireUpdate\Admin_Settings();
$actual = $admin_settings->get_setting( 'api_host' );

$this->assertIsString( $actual, 'The API host value is not a string.' );
$this->assertNotEmpty( $actual, 'The API host value is empty. ' . var_export( $actual, true ) );
$this->assertNotEmpty( $actual, 'The API host value is empty. ' );
}
}
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package AspireUpdate
*/

define( 'AP_RUN_TESTS', true );

$_tests_dir = getenv( 'WP_TESTS_DIR' );

if ( ! $_tests_dir ) {
Expand Down

0 comments on commit bb0d77a

Please sign in to comment.