wordpress-develop/tests/phpunit/tests/filesystem/base.php
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-04 15:22:47 +00:00

45 lines
1.4 KiB
PHP

<?php
/**
* This class is designed to make use of MockFS, a Virtual in-memory filesystem compatible with WP_Filesystem
*/
abstract class WP_Filesystem_UnitTestCase extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
add_filter( 'filesystem_method_file', array( $this, 'filter_abstraction_file' ) );
add_filter( 'filesystem_method', array( $this, 'filter_fs_method' ) );
WP_Filesystem();
}
public function tear_down() {
global $wp_filesystem;
remove_filter( 'filesystem_method_file', array( $this, 'filter_abstraction_file' ) );
remove_filter( 'filesystem_method', array( $this, 'filter_fs_method' ) );
unset( $wp_filesystem );
parent::tear_down();
}
public function filter_fs_method( $method ) {
return 'MockFS';
}
public function filter_abstraction_file( $file ) {
return dirname( dirname( __DIR__ ) ) . '/includes/mock-fs.php';
}
public function test_is_MockFS_sane() {
global $wp_filesystem;
$this->assertInstanceOf( 'WP_Filesystem_MockFS', $wp_filesystem );
$wp_filesystem->init( '/' );
// Test creation/exists checks.
$this->assertFalse( $wp_filesystem->is_dir( '/test/' ) );
$wp_filesystem->mkdir( '/test' );
$this->assertTrue( $wp_filesystem->exists( '/test' ) );
$this->assertTrue( $wp_filesystem->is_dir( '/test/' ) );
$this->assertFalse( $wp_filesystem->is_file( '/test' ) );
// $this->assertFalse( true );
}
}