From c23452730188cc371effedd19493a8d50d3031dd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 20 Jun 2021 00:24:31 +0000 Subject: [PATCH] Tests: Use more appropriate assertions in `clean_dirsize_cache()` tests. Follow-up to [49212], [49616], [49628], [49630]. See #52625. git-svn-id: https://develop.svn.wordpress.org/trunk@51186 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/multisite/cleanDirsizeCache.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/phpunit/tests/multisite/cleanDirsizeCache.php b/tests/phpunit/tests/multisite/cleanDirsizeCache.php index cedafb1090..bcc95e6359 100644 --- a/tests/phpunit/tests/multisite/cleanDirsizeCache.php +++ b/tests/phpunit/tests/multisite/cleanDirsizeCache.php @@ -65,7 +65,7 @@ if ( is_multisite() ) : $this->assertSame( 0, recurse_dirsize( $upload_dir['basedir'] ) ); // No cache match on non existing directory should return false. - $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) ); + $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) ); // Cleanup. $this->remove_added_uploads(); @@ -101,19 +101,19 @@ if ( is_multisite() ) : // Set the dirsize cache to our mock. set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) ); - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) ); - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) ); - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ); // Invalidation should also respect the directory tree up. // Should work fine with path to directory OR file. clean_dirsize_cache( $upload_dir['basedir'] . '/2/1/file.dummy' ); - $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) ); - $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) ); + $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ); + $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ); // Other cache paths should not be invalidated. - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ); // Cleanup. $this->remove_added_uploads(); @@ -149,19 +149,19 @@ if ( is_multisite() ) : // Set the dirsize cache to our mock. set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) ); - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) ); - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) ); - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ); // Invalidation should also respect the directory tree up. // Should work fine with path to directory OR file. clean_dirsize_cache( $upload_dir['basedir'] . '/2/1' ); - $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) ); - $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) ); + $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ); + $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ); // Other cache paths should not be invalidated. - $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) ); + $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ); // Cleanup. $this->remove_added_uploads(); @@ -206,7 +206,7 @@ if ( is_multisite() ) : // `dirsize_cache` should now be filled after upload and recurse_dirsize() call. $cache_path = untrailingslashit( $upload_dir['path'] ); - $this->assertSame( true, is_array( get_transient( 'dirsize_cache' ) ) ); + $this->assertInternalType( 'array', get_transient( 'dirsize_cache' ) ); $this->assertSame( $size, get_transient( 'dirsize_cache' )[ $cache_path ] ); // Cleanup. @@ -280,7 +280,7 @@ if ( is_multisite() ) : * will try to fetch a live value, but in this case the folder doesn't actually * exist on disk, so the function should fail. */ - $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) ); + $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) ); /* * Now that it's confirmed that old cached values aren't being returned, create the @@ -304,7 +304,7 @@ if ( is_multisite() ) : $this->assertSame( 21, get_transient( 'dirsize_cache' )[ $upload_dir['basedir'] . '/2/1' ] ); // No cache match on non existing directory should return false. - $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) ); + $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) ); // Cleanup. $this->remove_added_uploads();