From d66f71e7ab03d6674cf67a839b5b744c0696ba06 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Thu, 26 Oct 2023 16:08:31 -0400 Subject: [PATCH 1/4] test for wp_cache_set_last_changed --- .../tests/functions/wpCacheSetLastChanged.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpCacheSetLastChanged.php diff --git a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php new file mode 100644 index 0000000000000..15ad90b4a0d82 --- /dev/null +++ b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php @@ -0,0 +1,38 @@ +assertSame( wp_cache_set_last_changed( $group ), wp_cache_get( 'last_changed', $group ) ); + } + + /** + * Check the action is called. + * + * @ticket 59737 + */ + public function test_wp_cache_set_last_changed_action_is_called() { + + add_action( + 'wp_cache_set_last_changed', + function ( $group ) { + $this->assertSame( 'group_name', $group ); + } + ); + + wp_cache_set_last_changed( 'group_name' ); + } +} From 9f51e9d5bbf53ec361f321507feb1c53ffd1580b Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Fri, 3 Nov 2023 16:19:58 -0400 Subject: [PATCH 2/4] swaped to using mack for action test --- .../phpunit/tests/functions/wpCacheSetLastChanged.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php index 15ad90b4a0d82..c69c903fb68a0 100644 --- a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php +++ b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php @@ -25,14 +25,11 @@ public function test_wp_cache_set_last_changed() { * @ticket 59737 */ public function test_wp_cache_set_last_changed_action_is_called() { - - add_action( - 'wp_cache_set_last_changed', - function ( $group ) { - $this->assertSame( 'group_name', $group ); - } - ); + $a1 = new MockAction(); + add_action( 'wp_cache_set_last_changed', array( $a1, 'action' ) ); wp_cache_set_last_changed( 'group_name' ); + + $this->assertSame( 1, $a1->get_call_count() ); } } From ce95026cb036eecca2ceff1c2ad62a7308c707c4 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Sat, 4 Nov 2023 08:53:47 +1100 Subject: [PATCH 3/4] Rename group. --- tests/phpunit/tests/functions/wpCacheSetLastChanged.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php index c69c903fb68a0..d8c3208008a8b 100644 --- a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php +++ b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php @@ -2,7 +2,7 @@ /** * Tests for the wp_cache_set_last_changed function. * - * @group functions.php + * @group functions * * @covers ::wp_cache_set_last_changed */# From f99d077392cbf48a69bf1e4cab798e15500f548c Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Sat, 4 Nov 2023 09:57:54 +1100 Subject: [PATCH 4/4] Apply suggestions from code review --- tests/phpunit/tests/functions/wpCacheSetLastChanged.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php index d8c3208008a8b..9394801c9600f 100644 --- a/tests/phpunit/tests/functions/wpCacheSetLastChanged.php +++ b/tests/phpunit/tests/functions/wpCacheSetLastChanged.php @@ -1,15 +1,15 @@