Skip to content

Commit

Permalink
Introduce and implement AdminSettings_UnitTestCase (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev authored Dec 1, 2024
1 parent b1104df commit 2ae4c24
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@

<!-- Enforce short syntax arrays. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<!-- Exclude test classes from naming conventions. -->
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/tests/phpunit/tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>/tests/phpunit/tests/*</exclude-pattern>
</rule>
</ruleset>
3 changes: 3 additions & 0 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ function _manually_load_plugin() {

// Start up the WP testing environment.
require "{$_tests_dir}/includes/bootstrap.php";

// Load unit test abstract classes.
require __DIR__ . '/includes/AdminSettings_UnitTestCase.php';
25 changes: 25 additions & 0 deletions tests/phpunit/includes/AdminSettings_UnitTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Abstract base test class for \AspireUpdate\Admin_Settings.
*
* All \AspireUpdate\Admin_Settings unit tests should inherit from this class.
*/
abstract class AdminSettings_UnitTestCase extends WP_UnitTestCase {
/**
* The Name of the Option.
*
* @var string
*/
protected static $option_name = 'aspireupdate_settings';

/**
* Deletes settings before each test runs.
*
* @return void
*/
public function set_up() {
parent::set_up();

delete_site_option( self::$option_name );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @covers \AspireUpdate\Admin_Settings::get_setting
*/
class AdminSettings_GetSettingTest extends WP_UnitTestCase {
class AdminSettings_GetSettingTest extends AdminSettings_UnitTestCase {
/**
* Test that the default 'api_host' value is retrieved.
*
Expand Down

0 comments on commit 2ae4c24

Please sign in to comment.