Skip to content

Commit

Permalink
Merge pull request #48 from happyprime/fix/bump-phpstan-level-6
Browse files Browse the repository at this point in the history
Update return documentation in tests, use `factory()`
  • Loading branch information
jeremyfelt authored Feb 23, 2024
2 parents 1b059ba + f002e12 commit df83561
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 46 deletions.
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ includes:
- %rootDir%/../../happyprime/coding-standards/phpstan.neon.dist

parameters:
level: 5
level: 6
checkGenericClassInNonGenericObjectType: false
6 changes: 3 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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';
}

Expand Down
6 changes: 3 additions & 3 deletions tests/test-taxonomy-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ 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' ) );
}

/**
* 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' ) );
}
}
78 changes: 39 additions & 39 deletions tests/test-term-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit df83561

Please sign in to comment.