Skip to content

Commit

Permalink
Fix linting errors, make Relay mock return more deterministic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgeatches committed Dec 13, 2023
1 parent 6e2c367 commit f89ed3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/graphql/graphql-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
7 changes: 5 additions & 2 deletions tests/mocks/graphql-relay-mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
}
}

0 comments on commit f89ed3c

Please sign in to comment.