From f89ed3c742e8d56dd4cda55056dc738422ffa33e Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Wed, 13 Dec 2023 11:09:38 -0700 Subject: [PATCH] Fix linting errors, make Relay mock return more deterministic numbers --- src/graphql/graphql-api.php | 2 +- tests/mocks/graphql-relay-mock.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/graphql/graphql-api.php b/src/graphql/graphql-api.php index 659cd33..33da566 100644 --- a/src/graphql/graphql-api.php +++ b/src/graphql/graphql-api.php @@ -64,7 +64,7 @@ public static function get_blocks_data( $post_model ) { */ public static function transform_block_format( $block, $post_id ) { // Generate a unique ID for the block. - $block['id'] = Relay::toGlobalId( 'BlockData', sprintf( "%d:%d", $post_id, wp_unique_id() ) ); + $block['id'] = Relay::toGlobalId( 'BlockData', sprintf( '%d:%d', $post_id, wp_unique_id() ) ); // Convert the attributes to be in the name-value format that the schema expects. $block = self::map_attributes( $block ); diff --git a/tests/mocks/graphql-relay-mock.php b/tests/mocks/graphql-relay-mock.php index f7e695c..d0b6eab 100644 --- a/tests/mocks/graphql-relay-mock.php +++ b/tests/mocks/graphql-relay-mock.php @@ -4,6 +4,7 @@ // Ported over to mock out this functionality for tests. class Relay { + public static $current_id = 0; /** * Takes a type name and an ID specific to that type name, and returns a @@ -12,10 +13,12 @@ class Relay { * @param string $type * @param string $id * @return string - * + * * phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed */ public static function toGlobalId( $type, $id ) { - return "{$id}"; + ++self::$current_id; + return strval( self::$current_id ); } }