From a0639fc8741c02f584520de78d45e7e35fc3b5b0 Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:16:55 -0300 Subject: [PATCH] Misc changes to the unit tests --- CHANGELOG.md | 7 ++++ phpunit.xml | 1 + .../class-disable-attachment-routing.php | 9 ++-- .../concerns/trait-remove-meta-box.php | 6 ++- .../features/test-clean-admin-bar.php | 23 ++++++---- .../test-disable-attachment-routing.php | 42 ++++++++++++++++--- .../features/test-disable-comments.php | 12 +++--- .../test-disable-custom-fields-meta-box.php | 7 ++-- .../test-disable-dashboard-widgets.php | 14 ++++--- ...t-disable-password-change-notification.php | 14 ++++--- .../features/test-disable-sticky-posts.php | 21 ++++------ .../features/test-disable-trackbacks.php | 8 ++-- .../features/test-disallow-file-edit.php | 10 +++-- .../alleyvate/features/test-login-nonce.php | 2 + .../features/test-prevent-framing.php | 10 +++-- .../test-redirect-guess-shortcircuit.php | 12 ++++-- .../alleyvate/features/test-site-health.php | 10 +++-- .../test-user-enumeration-restrictions.php | 16 ++++--- 18 files changed, 145 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea9aa77..d69cfe3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a C * `prevent_framing`: Added a feature to prevent framing of the site via the `X-Frame-Options` header. +### Changed + +* Unit tests: misc changes and fixes. +* Unit tests: the `$feature` property uses the main feature class for better IDE intelephense support. +* Unit tests: all test cases use `declare( strict_types=1 );`. +* Unit tests: added test to confirm the attachment rewrite rules are removed + ## 2.3.1 ### Changed diff --git a/phpunit.xml b/phpunit.xml index 90707de3..0ad5694f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,6 +2,7 @@ bootstrap="tests/bootstrap.php" backupGlobals="false" colors="true" + convertDeprecationsToExceptions="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" diff --git a/src/alley/wp/alleyvate/features/class-disable-attachment-routing.php b/src/alley/wp/alleyvate/features/class-disable-attachment-routing.php index 53edb3e6..e0415fb6 100644 --- a/src/alley/wp/alleyvate/features/class-disable-attachment-routing.php +++ b/src/alley/wp/alleyvate/features/class-disable-attachment-routing.php @@ -12,6 +12,8 @@ namespace Alley\WP\Alleyvate\Features; +use WP_Admin_Bar; +use WP_Query; use Alley\WP\Alleyvate\Feature; /** @@ -48,10 +50,9 @@ public static function filter__rewrite_rules_array( $rules ): array { /** * Remove the attachment link. * - * @param string $link Attachment link. * @return string */ - public static function filter__attachment_link( $link ): string { + public static function filter__attachment_link(): string { return ''; } @@ -60,7 +61,7 @@ public static function filter__attachment_link( $link ): string { * * @param WP_Query $query WP_Query object. */ - public static function action__pre_get_posts( $query ) { + public static function action__pre_get_posts( $query ): void { if ( is_admin() || ! $query->is_main_query() ) { return; } @@ -77,7 +78,7 @@ public static function action__pre_get_posts( $query ) { /** * Remove attachment link from admin bar. * - * @param \WP_Admin_Bar $wp_admin_bar Admin bar class. + * @param WP_Admin_Bar $wp_admin_bar Admin bar class. */ public static function action__admin_bar_menu( $wp_admin_bar ): void { if ( 'attachment' === get_post_type() ) { diff --git a/tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php b/tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php index 843a773e..ecc7eaca 100644 --- a/tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php +++ b/tests/alley/wp/alleyvate/features/concerns/trait-remove-meta-box.php @@ -12,15 +12,18 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features\Concerns; use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Admin_Screen; /** * Test the removal of a meta box. */ trait Remove_Meta_Box { - use \Mantle\Testing\Concerns\Admin_Screen; + use Admin_Screen; /** * Test the removal of a meta box. @@ -30,7 +33,6 @@ trait Remove_Meta_Box { * @param string $screen Screen to test on. * @param string $context Meta box context. * @param string $priority Meta box priority. - * @return void */ protected function assertMetaBoxRemoval( Feature $feature, string $id, string $screen = 'post', string $context = 'normal', string $priority = 'default' ): void { $post = self::factory()->post->create_and_get(); diff --git a/tests/alley/wp/alleyvate/features/test-clean-admin-bar.php b/tests/alley/wp/alleyvate/features/test-clean-admin-bar.php index c3a5d0b9..426e6fd1 100644 --- a/tests/alley/wp/alleyvate/features/test-clean-admin-bar.php +++ b/tests/alley/wp/alleyvate/features/test-clean-admin-bar.php @@ -10,23 +10,26 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use WP_Admin_Bar; use Mantle\Testkit\Test_Case; +use Mantle\Testing\Concerns\Refresh_Database; /** * Tests for the cleaning of the admin bar. */ final class Test_Clean_Admin_Bar extends Test_Case { - use \Mantle\Testing\Concerns\Refresh_Database; + use Refresh_Database; /** * Feature instance. * - * @var Feature + * @var Clean_Admin_Bar */ - private Feature $feature; + private Clean_Admin_Bar $feature; /** * Set up. @@ -40,8 +43,7 @@ protected function setUp(): void { /** * Test default admin bar cleaning. */ - public function test_remove_admin_bar_nodes() { - + public function test_remove_admin_bar_nodes(): void { $admin_bar = $this->apply_admin_bar(); // Get nodes to compare. @@ -73,8 +75,7 @@ public function test_remove_admin_bar_nodes() { /** * Test admin bar cleaning using filter. */ - public function test_filter() { - + public function test_filter(): void { $admin_bar = $this->apply_admin_bar(); $node = 'my-account'; @@ -105,8 +106,12 @@ function ( $disposable_nodes ) use ( $node ) { /** * Apply the admin bar. + * + * @global WP_Admin_Bar $wp_admin_bar Core class used to implement the Toolbar API. + * + * @return WP_Admin_Bar */ - public function apply_admin_bar() { + public function apply_admin_bar(): WP_Admin_Bar { // Load file required to work with the admin bar. require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; diff --git a/tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php b/tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php index eafce7fc..7007da7e 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php +++ b/tests/alley/wp/alleyvate/features/test-disable-attachment-routing.php @@ -10,24 +10,25 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; /** * Tests for fully disabling attachment routing. */ final class Test_Disable_Attachment_Routing extends Test_Case { - use \Mantle\Testing\Concerns\Admin_Screen; - use \Mantle\Testing\Concerns\Refresh_Database; + use Refresh_Database; /** * Feature instance. * - * @var Feature + * @var Disable_Attachment_Routing */ - private Feature $feature; + private Disable_Attachment_Routing $feature; /** * Set up. @@ -38,6 +39,35 @@ protected function setUp(): void { $this->feature = new Disable_Attachment_Routing(); } + /** + * Test that the feature removes rewrite rules related to attachments. + */ + public function test_attachment_rewrile_rules_are_removed(): void { + $rewrite_rules = get_option( 'rewrite_rules' ); + + /** + * Attachment paths extracted from WordPress Develop. + * + * @see https://github.com/WordPress/wordpress-develop/blob/5b46851f7c52c2548630314d456b6e058d32a645/tests/phpunit/tests/query/conditionals.php#L774-L789 + */ + + $this->assertArrayHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$', $rewrite_rules ); + $this->assertArrayHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$', $rewrite_rules ); + $this->assertArrayHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', $rewrite_rules ); + $this->assertArrayHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', $rewrite_rules ); + + $this->feature->boot(); + + flush_rewrite_rules( false ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules + + $rewrite_rules = get_option( 'rewrite_rules' ); + + $this->assertArrayNotHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$', $rewrite_rules ); + $this->assertArrayNotHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$', $rewrite_rules ); + $this->assertArrayNotHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$', $rewrite_rules ); + $this->assertArrayNotHasKey( '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$', $rewrite_rules ); + } + /** * Test that the attachment permalink is empty. */ @@ -72,7 +102,7 @@ public function test_attachment_page(): void { * Test that the attachment pages are disabled using the new * 'wp_attachment_pages_enabled' option from WordPress 6.4. */ - public function test_attachment_pages_disabled_using_option() { + public function test_attachment_pages_disabled_using_option(): void { update_option( 'wp_attachment_pages_enabled', '1' ); $this->assertEquals( '1', get_option( 'wp_attachment_pages_enabled' ) ); diff --git a/tests/alley/wp/alleyvate/features/test-disable-comments.php b/tests/alley/wp/alleyvate/features/test-disable-comments.php index a8fb0cdd..9e7431d3 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-comments.php +++ b/tests/alley/wp/alleyvate/features/test-disable-comments.php @@ -10,25 +10,27 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; use Mantle\Testkit\Test_Case; +use Mantle\Testing\Concerns\{Admin_Screen, Refresh_Database}; /** * Tests for fully disabling comment functionality. */ final class Test_Disable_Comments extends Test_Case { use Concerns\Remove_Meta_Box; - use \Mantle\Testing\Concerns\Admin_Screen; - use \Mantle\Testing\Concerns\Refresh_Database; + use Admin_Screen; + use Refresh_Database; /** * Feature instance. * - * @var Feature + * @var Disable_Comments */ - private Feature $feature; + private Disable_Comments $feature; /** * Set up. diff --git a/tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php b/tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php index 1658d3c2..3f3bf78f 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php +++ b/tests/alley/wp/alleyvate/features/test-disable-custom-fields-meta-box.php @@ -10,9 +10,10 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; use Mantle\Testkit\Test_Case; /** @@ -24,9 +25,9 @@ final class Test_Disable_Custom_Fields_Meta_Box extends Test_Case { /** * Feature instance. * - * @var Feature + * @var Disable_Custom_Fields_Meta_Box */ - private Feature $feature; + private Disable_Custom_Fields_Meta_Box $feature; /** * Set up. diff --git a/tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php b/tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php index 7d9cae33..5167cddc 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php +++ b/tests/alley/wp/alleyvate/features/test-disable-dashboard-widgets.php @@ -10,24 +10,26 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\{Admin_Screen, Refresh_Database}; use Mantle\Testkit\Test_Case; /** * Tests for disabling selected unpopular dashboard widgets. */ final class Test_Disable_Dashboard_Widgets extends Test_Case { - use \Mantle\Testing\Concerns\Admin_Screen; - use \Mantle\Testing\Concerns\Refresh_Database; + use Admin_Screen; + use Refresh_Database; /** * Feature instance. * - * @var Feature + * @var Disable_Dashboard_Widgets */ - private Feature $feature; + private Disable_Dashboard_Widgets $feature; /** * Set up. @@ -44,7 +46,7 @@ protected function setUp(): void { /** * Test that widgets have been removed. */ - public function test_action__disable_dashboard_widgets() { + public function test_action__disable_dashboard_widgets(): void { // Load files required to get wp_meta_boxes global. require_once ABSPATH . 'wp-admin/includes/misc.php'; diff --git a/tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php b/tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php index 0ed28ce2..2abe1f44 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php +++ b/tests/alley/wp/alleyvate/features/test-disable-password-change-notification.php @@ -10,23 +10,25 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; /** * Tests for disabling the password change notification. */ final class Test_Disable_Password_Change_Notification extends Test_Case { - use \Mantle\Testing\Concerns\Refresh_Database; + use Refresh_Database; /** * Feature instance. * - * @var Feature + * @var Disable_Password_Change_Notification */ - private Feature $feature; + private Disable_Password_Change_Notification $feature; /** * Set up. @@ -38,9 +40,9 @@ protected function setUp(): void { } /** - * Test that the feature. + * Test disable password change notification hook. */ - public function test_disable_password_change_notification_hook() { + public function test_disable_password_change_notification_hook(): void { $this->acting_as( 'administrator' ); $this->assertTrue( diff --git a/tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php b/tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php index b7b1bcb5..b588117f 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php +++ b/tests/alley/wp/alleyvate/features/test-disable-sticky-posts.php @@ -10,12 +10,12 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; -use WP_Query; /** * Tests for fully disabling sticky posts. @@ -42,8 +42,7 @@ protected function setUp(): void { /** * Test that sticky posts are disabled in queries on the homepage. */ - public function test_disable_sticky_posts_in_query() { - + public function test_disable_sticky_posts_in_query(): void { $posts = self::factory()->post->create_ordered_set( 5 ); $stick_post_id = self::factory()->post->create( [ @@ -87,22 +86,18 @@ public function test_disable_sticky_posts_in_query() { /** * Test that sticky posts are disabled in Gutenberg. */ - public function test_disable_action_sticky_rest_api_edit() { + public function test_disable_action_sticky_rest_api_edit(): void { $this->acting_as( 'administrator' ); $post_id = self::factory()->post->create(); - $this->get( - rest_url( 'wp/v2/posts/' . $post_id . '?context=edit' ), - ) - ->assertJsonPathExists( '_links.wp:action-sticky' ); + $this->get( rest_url( 'wp/v2/posts/' . $post_id . '?context=edit' ) ) + ->assertJsonPathExists( '_links.wp:action-sticky' ); // Activate the disable sticky post feature. $this->feature->boot(); - $this->get( - rest_url( 'wp/v2/posts/' . $post_id . '?context=edit' ), - ) - ->assertJsonPathMissing( '_links.wp:action-sticky' ); + $this->get( rest_url( 'wp/v2/posts/' . $post_id . '?context=edit' ) ) + ->assertJsonPathMissing( '_links.wp:action-sticky' ); } } diff --git a/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php b/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php index 98148d55..081265d4 100644 --- a/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php +++ b/tests/alley/wp/alleyvate/features/test-disable-trackbacks.php @@ -12,19 +12,21 @@ namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; /** * Tests for fully disabling pingback and trackback functionality. */ final class Test_Disable_Trackbacks extends Test_Case { + use Refresh_Database; + /** * Feature instance. * - * @var Feature + * @var Disable_Trackbacks */ - private Feature $feature; + private Disable_Trackbacks $feature; /** * Set up. diff --git a/tests/alley/wp/alleyvate/features/test-disallow-file-edit.php b/tests/alley/wp/alleyvate/features/test-disallow-file-edit.php index 5d5b9f43..725f716e 100644 --- a/tests/alley/wp/alleyvate/features/test-disallow-file-edit.php +++ b/tests/alley/wp/alleyvate/features/test-disallow-file-edit.php @@ -10,21 +10,23 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; use Mantle\Testkit\Test_Case; /** * Tests for the disallowing of file editing. */ final class Test_Disallow_File_Edit extends Test_Case { + /** * Feature instance. * - * @var Feature + * @var Disallow_File_Edit */ - private Feature $feature; + private Disallow_File_Edit $feature; /** * Set up. @@ -38,7 +40,7 @@ protected function setUp(): void { /** * Test that the feature disallows file editing. */ - public function test_disallow_file_editing() { + public function test_disallow_file_editing(): void { $this->assertFalse( \defined( 'DISALLOW_FILE_EDIT' ), 'DISALLOW_FILE_EDIT should not be defined prior to boot.' ); $this->feature->boot(); $this->assertTrue( \defined( 'DISALLOW_FILE_EDIT' ), 'DISALLOW_FILE_EDIT should be defined after boot.' ); diff --git a/tests/alley/wp/alleyvate/features/test-login-nonce.php b/tests/alley/wp/alleyvate/features/test-login-nonce.php index 2918b50f..1f273f99 100644 --- a/tests/alley/wp/alleyvate/features/test-login-nonce.php +++ b/tests/alley/wp/alleyvate/features/test-login-nonce.php @@ -12,6 +12,8 @@ * @phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited, Generic.CodeAnalysis.EmptyStatement.DetectedCatch, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; use Mantle\Testing\Concerns\Refresh_Database; diff --git a/tests/alley/wp/alleyvate/features/test-prevent-framing.php b/tests/alley/wp/alleyvate/features/test-prevent-framing.php index b769362e..a8a78d08 100644 --- a/tests/alley/wp/alleyvate/features/test-prevent-framing.php +++ b/tests/alley/wp/alleyvate/features/test-prevent-framing.php @@ -10,23 +10,25 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; /** * Tests for the preventing the iframing of a site. */ final class Test_Prevent_Framing extends Test_Case { - use \Mantle\Testing\Concerns\Refresh_Database; + use Refresh_Database; /** * Feature instance. * - * @var Feature + * @var Prevent_Framing */ - private Feature $feature; + private Prevent_Framing $feature; /** * Set up. diff --git a/tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php b/tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php index ed8f7f4e..c8665bf3 100644 --- a/tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php +++ b/tests/alley/wp/alleyvate/features/test-redirect-guess-shortcircuit.php @@ -10,21 +10,25 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; /** * Tests for short-circuiting the redirect URL guessing for 404 requests. */ final class Test_Redirect_Guess_Shortcircuit extends Test_Case { + use Refresh_Database; + /** * Feature instance. * - * @var Feature + * @var Redirect_Guess_Shortcircuit */ - private Feature $feature; + private Redirect_Guess_Shortcircuit $feature; /** * Set up. @@ -38,7 +42,7 @@ protected function setUp(): void { /** * Test that the feature short-circuits a redirect that would otherwise occur. */ - public function test_no_redirect_guess() { + public function test_no_redirect_guess(): void { $post_name = 'foo'; $actual = self::factory()->post->create( [ diff --git a/tests/alley/wp/alleyvate/features/test-site-health.php b/tests/alley/wp/alleyvate/features/test-site-health.php index 40fcee1c..8e730036 100644 --- a/tests/alley/wp/alleyvate/features/test-site-health.php +++ b/tests/alley/wp/alleyvate/features/test-site-health.php @@ -10,9 +10,10 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; use Mantle\Testkit\Test_Case; use function Alley\WP\Alleyvate\available_features; @@ -21,12 +22,13 @@ * Test for site health feature. */ final class Test_Site_Health extends Test_Case { + /** * Feature instance. * - * @var Feature + * @var Site_Health */ - private Feature $feature; + private Site_Health $feature; /** * Set up. @@ -40,7 +42,7 @@ protected function setUp(): void { /** * Test the site health feature. */ - public function test_site_health_feature() { + public function test_site_health_feature(): void { $features = available_features(); $this->expectApplied( 'alleyvate_load_feature' )->times( \count( $features ) ); diff --git a/tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php b/tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php index 376ae62e..2755fd58 100644 --- a/tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php +++ b/tests/alley/wp/alleyvate/features/test-user-enumeration-restrictions.php @@ -10,21 +10,25 @@ * @package wp-alleyvate */ +declare( strict_types=1 ); + namespace Alley\WP\Alleyvate\Features; -use Alley\WP\Alleyvate\Feature; +use Mantle\Testing\Concerns\Refresh_Database; use Mantle\Testkit\Test_Case; /** * Tests for the user enumeration restrictions feature. */ final class Test_User_Enumeration_Restrictions extends Test_Case { + use Refresh_Database; + /** * Feature instance. * - * @var Feature + * @var User_Enumeration_Restrictions */ - private Feature $feature; + private User_Enumeration_Restrictions $feature; /** * Set up. @@ -43,7 +47,7 @@ protected function setUp(): void { * @param bool $logged_in Whether a user is logged in. * @param int $expected_status Expected response code. */ - public function test_rest_enumeration_by_user( $logged_in, $expected_status ) { + public function test_rest_enumeration_by_user( bool $logged_in, int $expected_status ): void { /* * Individual users can be read anonymously over the REST API only * if they're the author of a post that is itself shown in REST. @@ -90,11 +94,11 @@ public function test_rest_enumeration_by_user( $logged_in, $expected_status ) { } /** - * Data provider. + * Data provider for the test_rest_enumeration_by_user test. * * @return array */ - public function data_rest_enumeration_by_user() { + public function data_rest_enumeration_by_user(): array { return [ 'logged-out user' => [ false, 401 ], 'logged-in user' => [ true, 200 ],