From f002e12693339ffeb445798670c5a044ae0662af Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Fri, 23 Feb 2024 11:56:44 -0800 Subject: [PATCH] Update return documentation in tests, use `factory()` --- phpstan.neon.dist | 3 +- tests/bootstrap.php | 6 +-- tests/test-taxonomy-registration.php | 6 +-- tests/test-term-sync.php | 78 ++++++++++++++-------------- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ac75668..b3dbc76 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,4 +2,5 @@ includes: - %rootDir%/../../happyprime/coding-standards/phpstan.neon.dist parameters: - level: 5 + level: 6 + checkGenericClassInNonGenericObjectType: false diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d0c2b7b..e75f9ee 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ /** * PHPUnit bootstrap file. * - * @package Shadow_Terms + * @package shadow-terms */ $_tests_dir = getenv( 'WP_TESTS_DIR' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound @@ -30,7 +30,7 @@ * Setup example post types that support or do not * support shadow terms. */ -function _register_test_post_types() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound +function _register_test_post_types(): void { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound register_post_type( 'example', array( @@ -75,7 +75,7 @@ function _register_test_post_types() { // phpcs:ignore WordPress.NamingConventio /** * Manually load the plugin being tested. */ -function _manually_load_plugin() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound +function _manually_load_plugin(): void { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound require dirname( __DIR__ ) . '/plugin.php'; } diff --git a/tests/test-taxonomy-registration.php b/tests/test-taxonomy-registration.php index 7601bcd..f82f6e8 100644 --- a/tests/test-taxonomy-registration.php +++ b/tests/test-taxonomy-registration.php @@ -15,7 +15,7 @@ class TestTaxonomyRegistration extends WP_UnitTestCase { * Test a post type that has declared support for shadow terms in * the register_post_type() arguments. */ - public function test_post_type_with_register_post_type_support_registers_shadow_taxonomy() { + public function test_post_type_with_register_post_type_support_registers_shadow_taxonomy(): void { $this->assertTrue( taxonomy_exists( 'example_connect' ) ); } @@ -23,14 +23,14 @@ public function test_post_type_with_register_post_type_support_registers_shadow_ * Test a post type that has declared support for shadow terms in * add_post_type_support(). */ - public function test_post_type_with_add_post_type_support_registers_shadow_taxonomy() { + public function test_post_type_with_add_post_type_support_registers_shadow_taxonomy(): void { $this->assertTrue( taxonomy_exists( 'another-example_connect' ) ); } /** * Test a post type that has not declared support for shadow terms. */ - public function test_post_type_with_no_support_has_no_shadow_taxonomy() { + public function test_post_type_with_no_support_has_no_shadow_taxonomy(): void { $this->assertFalse( taxonomy_exists( 'unexample_connect' ) ); } } diff --git a/tests/test-term-sync.php b/tests/test-term-sync.php index d202eec..e7f6661 100644 --- a/tests/test-term-sync.php +++ b/tests/test-term-sync.php @@ -15,8 +15,8 @@ class TestTermSync extends WP_UnitTestCase { /** * A newly created post with an initial status of publish should generate a shadow term. */ - public function test_post_new_to_publish_creates_term() { - $this->factory->post->create( + public function test_post_new_to_publish_creates_term(): void { + $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Apple', @@ -33,8 +33,8 @@ public function test_post_new_to_publish_creates_term() { /** * An existing draft post that is published should generate a shadow term. */ - public function test_post_draft_to_publish_creates_term() { - $post = $this->factory->post->create( + public function test_post_draft_to_publish_creates_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Bean', @@ -55,8 +55,8 @@ public function test_post_draft_to_publish_creates_term() { /** * A shadow term should be deleted when its connected post is deleted. */ - public function test_post_publish_to_delete_removes_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_delete_removes_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Corn', @@ -76,8 +76,8 @@ public function test_post_publish_to_delete_removes_term() { /** * A shadow term should be deleted when its connected post is moved from publish to draft. */ - public function test_post_publish_to_draft_removes_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_draft_removes_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Daikon', @@ -98,8 +98,8 @@ public function test_post_publish_to_draft_removes_term() { /** * Existing shadow term relationships should be stored when its connected post is moved from publish to draft. */ - public function test_post_publish_to_draft_preserves_relationships() { - $post = $this->factory->post->create( + public function test_post_publish_to_draft_preserves_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Zebra', @@ -109,7 +109,7 @@ public function test_post_publish_to_draft_preserves_relationships() { $post = get_post( $post ); $term = get_term_by( 'slug', 'zebra', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 129', @@ -130,8 +130,8 @@ public function test_post_publish_to_draft_preserves_relationships() { /** * A shadow term should be deleted when its connected post is moved from publish to pending. */ - public function test_post_publish_to_pending_removes_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_pending_removes_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Elderberry', @@ -152,8 +152,8 @@ public function test_post_publish_to_pending_removes_term() { /** * Existing shadow term relationships should be stored when its connected post is moved from publish to pending. */ - public function test_post_publish_to_pending_preserves_relationships() { - $post = $this->factory->post->create( + public function test_post_publish_to_pending_preserves_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Yellow', @@ -163,7 +163,7 @@ public function test_post_publish_to_pending_preserves_relationships() { $post = get_post( $post ); $term = get_term_by( 'slug', 'yellow', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 128', @@ -184,8 +184,8 @@ public function test_post_publish_to_pending_preserves_relationships() { /** * A shadow term should be deleted when its connected post is moved from publish to private. */ - public function test_post_publish_to_private_removes_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_private_removes_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Xylophone', @@ -206,8 +206,8 @@ public function test_post_publish_to_private_removes_term() { /** * Existing shadow term relationships should be stored when its conncted post is moved from publish to private. */ - public function test_post_publish_to_private_preserves_relationships() { - $post = $this->factory->post->create( + public function test_post_publish_to_private_preserves_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'French Fry', @@ -217,7 +217,7 @@ public function test_post_publish_to_private_preserves_relationships() { $post = get_post( $post ); $term = get_term_by( 'slug', 'french-fry', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 127', @@ -238,8 +238,8 @@ public function test_post_publish_to_private_preserves_relationships() { /** * Existing shadow term relationships should be restored when its connected post is moved from draft to publish. */ - public function test_post_draft_to_publish_creates_term_and_restores_relationships() { - $post = $this->factory->post->create( + public function test_post_draft_to_publish_creates_term_and_restores_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Wrapper', @@ -249,7 +249,7 @@ public function test_post_draft_to_publish_creates_term_and_restores_relationshi $post = get_post( $post ); $term = get_term_by( 'slug', 'wrapper', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 126', @@ -276,8 +276,8 @@ public function test_post_draft_to_publish_creates_term_and_restores_relationshi /** * Existing shadow term relationships should be restored when its connected post is moved from pending to publish. */ - public function test_post_pending_to_publish_creates_term_and_restores_relationships() { - $post = $this->factory->post->create( + public function test_post_pending_to_publish_creates_term_and_restores_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Viola', @@ -287,7 +287,7 @@ public function test_post_pending_to_publish_creates_term_and_restores_relations $post = get_post( $post ); $term = get_term_by( 'slug', 'viola', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 125', @@ -314,8 +314,8 @@ public function test_post_pending_to_publish_creates_term_and_restores_relations /** * Existing shadow term relationships should be restored when its connected post is moved from private to publish. */ - public function test_post_private_to_publish_creates_term_and_restores_relationships() { - $post = $this->factory->post->create( + public function test_post_private_to_publish_creates_term_and_restores_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Umbrella', @@ -325,7 +325,7 @@ public function test_post_private_to_publish_creates_term_and_restores_relations $post = get_post( $post ); $term = get_term_by( 'slug', 'umbrella', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 124', @@ -352,8 +352,8 @@ public function test_post_private_to_publish_creates_term_and_restores_relations /** * Existing shadow term relationships should be restored when its connected post is moved from trash to publish. */ - public function test_post_trash_to_publish_creates_term_and_restores_relationships() { - $post = $this->factory->post->create( + public function test_post_trash_to_publish_creates_term_and_restores_relationships(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Tasty', @@ -363,7 +363,7 @@ public function test_post_trash_to_publish_creates_term_and_restores_relationshi $post = get_post( $post ); $term = get_term_by( 'slug', 'tasty', 'example_connect', 'OBJECT' ); - $associated_post = $this->factory->post->create( + $associated_post = $this->factory()->post->create( array( 'post_type' => 'post', 'post_title' => 'ABC Test 123', @@ -391,8 +391,8 @@ public function test_post_trash_to_publish_creates_term_and_restores_relationshi * An existing published post that has its title changed should change the * title of its shadow term. */ - public function test_post_publish_to_publish_modified_title_updates_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_publish_modified_title_updates_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Garbanzo Bean', @@ -416,8 +416,8 @@ public function test_post_publish_to_publish_modified_title_updates_term() { * An existing published post that has its slug changed should change the * slug of its shadow term. */ - public function test_post_publish_to_publish_modified_slug_updates_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_publish_modified_slug_updates_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Garbanzo Bean', @@ -441,8 +441,8 @@ public function test_post_publish_to_publish_modified_slug_updates_term() { * An existing published post that has its title changed should change the * title of its shadow term. */ - public function test_post_publish_to_publish_modified_title_and_slug_updates_term() { - $post = $this->factory->post->create( + public function test_post_publish_to_publish_modified_title_and_slug_updates_term(): void { + $post = $this->factory()->post->create( array( 'post_type' => 'example', 'post_title' => 'Garbanzo Bean',