From 36fe817c1f2e184c011593c3a6a352d17125c1b6 Mon Sep 17 00:00:00 2001 From: Igor <35524806+igorschoester@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:07:52 +0200 Subject: [PATCH] Rename get/set introductions to include `all` for a clearer distinction between the multiple and single methods --- .../introductions-seen-repository.php | 10 ++++---- .../introductions-seen-repository-test.php | 24 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/introductions/infrastructure/introductions-seen-repository.php b/src/introductions/infrastructure/introductions-seen-repository.php index 015c49d68cb..50f8d41f587 100644 --- a/src/introductions/infrastructure/introductions-seen-repository.php +++ b/src/introductions/infrastructure/introductions-seen-repository.php @@ -39,7 +39,7 @@ public function __construct( User_Helper $user_helper ) { * * @return array The introductions. */ - public function get_introductions( $user_id ): array { + public function get_all_introductions( $user_id ): array { $seen_introductions = $this->user_helper->get_meta( $user_id, self::USER_META_KEY, true ); if ( $seen_introductions === false ) { throw new Invalid_User_Id_Exception(); @@ -66,7 +66,7 @@ public function get_introductions( $user_id ): array { * @return bool True on successful update, false on failure or if the value passed to the function is the same as * the one that is already in the database. */ - public function set_introductions( $user_id, array $introductions ): bool { + public function set_all_introductions( $user_id, array $introductions ): bool { return $this->user_helper->update_meta( $user_id, self::USER_META_KEY, $introductions ) === true; } @@ -81,7 +81,7 @@ public function set_introductions( $user_id, array $introductions ): bool { * @return bool Whether the introduction is seen. */ public function is_introduction_seen( $user_id, string $introduction_id ): bool { - $introductions = $this->get_introductions( $user_id ); + $introductions = $this->get_all_introductions( $user_id ); if ( \array_key_exists( $introduction_id, $introductions ) ) { return (bool) $introductions[ $introduction_id ]; @@ -102,7 +102,7 @@ public function is_introduction_seen( $user_id, string $introduction_id ): bool * @return bool False on failure. Not having to update is a success. */ public function set_introduction( $user_id, string $introduction_id, bool $is_seen = true ): bool { - $introductions = $this->get_introductions( $user_id ); + $introductions = $this->get_all_introductions( $user_id ); // Check if the wanted value is already set. if ( \array_key_exists( $introduction_id, $introductions ) && $introductions[ $introduction_id ] === $is_seen ) { @@ -110,6 +110,6 @@ public function set_introduction( $user_id, string $introduction_id, bool $is_se } $introductions[ $introduction_id ] = $is_seen; - return $this->set_introductions( $user_id, $introductions ); + return $this->set_all_introductions( $user_id, $introductions ); } } diff --git a/tests/unit/introductions/infrastructure/introductions-seen-repository-test.php b/tests/unit/introductions/infrastructure/introductions-seen-repository-test.php index 99ec7a592b3..8f74cdc5809 100644 --- a/tests/unit/introductions/infrastructure/introductions-seen-repository-test.php +++ b/tests/unit/introductions/infrastructure/introductions-seen-repository-test.php @@ -57,31 +57,31 @@ public function test_constructor() { /** * Tests the introductions retrieval. * - * @covers ::get_introductions + * @covers ::get_all_introductions * - * @dataProvider provide_get_introductions_test_data + * @dataProvider provide_get_all_introductions_test_data * * @param mixed $meta Value `get_meta` returns. * @param boolean $expected The expected value. * * @throws Invalid_User_Id_Exception Invalid User ID. */ - public function test_get_introductions( $meta, $expected ) { + public function test_get_all_introductions( $meta, $expected ) { $user_id = 1; $this->user_helper->expects( 'get_meta' ) ->once() ->with( $user_id, Introductions_Seen_Repository::USER_META_KEY, true ) ->andReturn( $meta ); - $this->assertEquals( $expected, $this->instance->get_introductions( $user_id ) ); + $this->assertEquals( $expected, $this->instance->get_all_introductions( $user_id ) ); } /** - * Provides data for `test_get_introductions()`. + * Provides data for `test_get_all_introductions()`. * * @return array */ - public function provide_get_introductions_test_data() { + public function provide_get_all_introductions_test_data() { return [ 'nothing stored' => [ 'meta' => '', @@ -101,11 +101,11 @@ public function provide_get_introductions_test_data() { /** * Tests the introductions retrieval with an invalid user ID. * - * @covers ::get_introductions + * @covers ::get_all_introductions * * @throws Invalid_User_Id_Exception Invalid User ID. */ - public function test_get_introductions_with_invalid_user_id() { + public function test_get_all_introductions_with_invalid_user_id() { $user_id = 1; $this->user_helper->expects( 'get_meta' ) ->once() @@ -114,15 +114,15 @@ public function test_get_introductions_with_invalid_user_id() { $this->expectException( Invalid_User_Id_Exception::class ); - $this->instance->get_introductions( $user_id ); + $this->instance->get_all_introductions( $user_id ); } /** * Tests setting the introductions calls update_meta(). * - * @covers ::set_introductions + * @covers ::set_all_introductions */ - public function test_set_introductions() { + public function test_set_all_introductions() { $user_id = 1; $introductions = [ 'foo' => true ]; $this->user_helper->expects( 'update_meta' ) @@ -130,7 +130,7 @@ public function test_set_introductions() { ->with( $user_id, Introductions_Seen_Repository::USER_META_KEY, $introductions ) ->andReturnTrue(); - $this->instance->set_introductions( $user_id, $introductions ); + $this->instance->set_all_introductions( $user_id, $introductions ); } /**