Skip to content

Commit 971359d

Browse files
authored
Merge pull request #573 from wp-cli/fix-tests
2 parents 43c7077 + 1339d68 commit 971359d

File tree

9 files changed

+75
-17
lines changed

9 files changed

+75
-17
lines changed

entity-command.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@
5454
'Site_Meta_Command',
5555
array(
5656
'before_invoke' => function () {
57+
/**
58+
* @var \wpdb $wpdb
59+
*/
60+
global $wpdb;
5761
if ( ! is_multisite() ) {
5862
WP_CLI::error( 'This is not a multisite installation.' );
5963
}
6064
if ( ! function_exists( 'is_site_meta_supported' ) || ! is_site_meta_supported() ) {
61-
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $GLOBALS['wpdb']->blogmeta ) );
65+
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $wpdb->blogmeta ) );
6266
}
6367
},
6468
)

features/post-block.feature

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@ Feature: Manage blocks in post content
127127
Then save STDOUT as {POST_ID}
128128

129129
When I run `wp post block render {POST_ID}`
130+
# In WordPress 7.0+ paragraph blocks are rendered with a class name.
131+
# See https://github.com/WordPress/gutenberg/pull/71207.
130132
Then STDOUT should contain:
131133
"""
132-
<p>Hello World</p>
134+
<p
135+
"""
136+
And STDOUT should contain:
137+
"""
138+
>Hello World</p>
133139
"""
134140
And STDOUT should contain:
135141
"""
@@ -143,7 +149,11 @@ Feature: Manage blocks in post content
143149
When I run `wp post block render {POST_ID} --block=core/paragraph`
144150
Then STDOUT should contain:
145151
"""
146-
<p>Hello World</p>
152+
<p
153+
"""
154+
And STDOUT should contain:
155+
"""
156+
>Hello World</p>
147157
"""
148158
And STDOUT should not contain:
149159
"""
@@ -773,9 +783,15 @@ Feature: Manage blocks in post content
773783
Then save STDOUT as {POST_ID}
774784

775785
When I run `wp post block export {POST_ID} --format=html`
786+
# In WordPress 7.0+ paragraph blocks are rendered with a class name.
787+
# See https://github.com/WordPress/gutenberg/pull/71207.
776788
Then STDOUT should contain:
777789
"""
778-
<p>Hello World</p>
790+
<p
791+
"""
792+
And STDOUT should contain:
793+
"""
794+
>Hello World</p>
779795
"""
780796

781797
@require-wp-5.0

src/Comment_Command.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function __construct() {
9494
*
9595
* # Create a note (WordPress 6.9+).
9696
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
97-
* Success: Created comment 933. *
97+
* Success: Created comment 933. *
9898
* @param string[] $args Positional arguments. Unused.
9999
* @param array<string, mixed> $assoc_args Associative arguments.
100100
*/
@@ -279,6 +279,7 @@ public function get( $args, $assoc_args ) {
279279
WP_CLI::error( 'Invalid comment ID.' );
280280
}
281281

282+
// @phpstan-ignore property.notFound
282283
if ( ! isset( $comment->url ) ) {
283284
// @phpstan-ignore property.notFound
284285
$comment->url = get_comment_link( $comment );
@@ -447,8 +448,12 @@ public function list_( $args, $assoc_args ) {
447448
} elseif ( is_array( $comments ) ) {
448449
$comments = array_map(
449450
function ( $comment ) {
450-
$comment->url = get_comment_link( $comment->comment_ID );
451-
return $comment;
451+
/**
452+
* @var \WP_Comment $comment
453+
*/
454+
// @phpstan-ignore property.notFound
455+
$comment->url = get_comment_link( (int) $comment->comment_ID );
456+
return $comment;
452457
},
453458
$comments
454459
);

src/Post_Block_Command.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* $ wp post block insert 123 core/paragraph --content="Hello World"
3232
*
3333
* @package wp-cli
34+
*
35+
* @phpstan-type ParsedBlock array{blockName?: string, attrs: array<string, mixed>, innerBlocks: array<array<mixed>>, innerHTML: string, innerContent: list<mixed>}
36+
* @phpstan-type ParsedBlockWithBlockName array{blockName: string, attrs: array<string, mixed>, innerBlocks: array<array<mixed>>, innerHTML: string, innerContent: list<mixed>}
3437
*/
3538
class Post_Block_Command extends WP_CLI_Command {
3639

@@ -641,13 +644,21 @@ public function import( $args, $assoc_args ) {
641644
WP_CLI::error( 'No blocks found in import data.' );
642645
}
643646

647+
/**
648+
* @phpstan-var array<int|string, ParsedBlock> $import_blocks
649+
*/
650+
644651
// Validate block structure.
645652
foreach ( $import_blocks as $idx => $block ) {
646653
if ( ! isset( $block['blockName'] ) ) {
647654
WP_CLI::error( "Invalid block structure at index {$idx}: missing blockName." );
648655
}
649656
}
650657

658+
/**
659+
* @phpstan-var array<int|string, ParsedBlockWithBlockName> $import_blocks
660+
*/
661+
651662
$imported_count = count( $import_blocks );
652663

653664
if ( $replace ) {

src/Site_Command.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ private function get_sites_ids( $args, $assoc_args ) {
12441244
* @param array $assoc_args Passed-in parameters.
12451245
*
12461246
* @return bool
1247-
* @throws ExitException If neither site ids nor site slug using --slug were provided.
12481247
*/
12491248
private function check_site_ids_and_slug( $args, $assoc_args ) {
12501249
if ( ( empty( $args ) && empty( $assoc_args['slug'] ) )

src/Term_Command.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ public function list_( $args, $assoc_args ) {
140140
$term = get_term_by( 'id', $assoc_args['term_id'], $args[0] );
141141
$terms = [ $term ];
142142
} else {
143-
/**
144-
* @var \WP_Term[] $terms
145-
*/
146143
$terms = get_terms(
147144
array_merge(
148145
$assoc_args,
@@ -151,6 +148,15 @@ public function list_( $args, $assoc_args ) {
151148
]
152149
)
153150
);
151+
152+
// This should never happen because of the taxonomy_exists check above.
153+
if ( is_wp_error( $terms ) ) {
154+
WP_CLI::error( $terms );
155+
}
156+
157+
/**
158+
* @var \WP_Term[] $terms
159+
*/
154160
}
155161

156162
$terms = array_map(
@@ -295,6 +301,7 @@ public function get( $args, $assoc_args ) {
295301
WP_CLI::error( "Term doesn't exist." );
296302
}
297303

304+
// @phpstan-ignore property.notFound
298305
if ( ! isset( $term->url ) ) {
299306
// @phpstan-ignore property.notFound
300307
$term->url = get_term_link( $term );
@@ -649,18 +656,23 @@ public function recount( $args ) {
649656
if ( ! taxonomy_exists( $taxonomy ) ) {
650657
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
651658
} else {
652-
653-
/**
654-
* @var \WP_Term[] $terms
655-
*/
656-
657659
$terms = get_terms(
658660
[
659661
'taxonomy' => $taxonomy,
660662
'hide_empty' => false,
661663
]
662664
);
663665

666+
// This should never happen because of the taxonomy_exists check above.
667+
if ( is_wp_error( $terms ) ) {
668+
WP_CLI::warning( "Taxonomy {$taxonomy} does not exist." );
669+
continue;
670+
}
671+
672+
/**
673+
* @var \WP_Term[] $terms
674+
*/
675+
664676
$term_taxonomy_ids = wp_list_pluck( $terms, 'term_taxonomy_id' );
665677

666678
wp_update_term_count( $term_taxonomy_ids, $taxonomy );

src/User_Meta_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) {
341341
private function replace_login_with_user_id( $args ) {
342342
$user = $this->fetcher->get_check( $args[0] );
343343
$args[0] = $user->ID;
344+
// TODO: Improve method type eventually.
345+
// Related: https://github.com/phpstan/phpstan/issues/8438.
346+
// @phpstan-ignore return.type
344347
return $args;
345348
}
346349
}

src/User_Session_Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ protected function get_all_sessions( WP_Session_Tokens $manager ) {
174174
// Make the private session data accessible to WP-CLI
175175
$get_sessions = new ReflectionMethod( $manager, 'get_sessions' );
176176
if ( PHP_VERSION_ID < 80100 ) {
177+
// @phpstan-ignore method.deprecated
177178
$get_sessions->setAccessible( true );
178179
}
179180

@@ -197,6 +198,7 @@ function ( &$session, $token ) {
197198
protected function destroy_session( WP_Session_Tokens $manager, $token ) {
198199
$update_session = new ReflectionMethod( $manager, 'update_session' );
199200
if ( PHP_VERSION_ID < 80100 ) {
201+
// @phpstan-ignore method.deprecated
200202
$update_session->setAccessible( true );
201203
}
202204
return $update_session->invoke( $manager, $token, null );

src/WP_CLI/CommandWithTerms.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ public function list_( $args, $assoc_args ) {
103103
$taxonomy_args['fields'] = 'ids';
104104
}
105105

106+
$items = wp_get_object_terms( $object_id, $taxonomy_names, $taxonomy_args );
107+
108+
// This should never happen because of the taxonomy_exists check above.
109+
if ( is_wp_error( $items ) ) {
110+
WP_CLI::error( $items );
111+
}
112+
106113
/**
107114
* @var \WP_Term[] $items
108115
*/
109-
$items = wp_get_object_terms( $object_id, $taxonomy_names, $taxonomy_args );
110116

111117
$formatter = $this->get_formatter( $assoc_args );
112118
$formatter->display_items( $items );

0 commit comments

Comments
 (0)