|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class WP_Test_Jetpack_Deprecation extends WP_UnitTestCase { |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @dataProvider provider_deprecated_file_paths |
|
7
|
|
|
*/ |
|
8
|
|
|
public function test_deprecated_file_paths( $file_path, $replacement_path ) { |
|
9
|
|
|
$mock = $this->getMockBuilder( stdClass::class ) |
|
10
|
|
|
->setMethods( array( 'action' ) ) |
|
11
|
|
|
->getMock(); |
|
12
|
|
|
$mock->expects( $this->once() )->method( 'action' )->with( $file_path, $replacement_path ); |
|
13
|
|
|
|
|
14
|
|
|
add_action( 'deprecated_file_included', array( $mock, 'action' ), 10, 2 ); |
|
15
|
|
|
add_filter( 'deprecated_file_trigger_error', '__return_false' ); |
|
16
|
|
|
|
|
17
|
|
|
require_once JETPACK__PLUGIN_DIR . $file_path; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @dataProvider provider_deprecated_method_stubs |
|
22
|
|
|
*/ |
|
23
|
|
|
function test_deprecated_method_stubs( $class_name, $method_name ) { |
|
24
|
|
|
$this->assertTrue( method_exists( $class_name, $method_name ) ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function provider_deprecated_method_stubs() { |
|
28
|
|
|
return array( |
|
29
|
|
|
array( 'JetpackTracking', 'record_user_event', array( 'Bogus' ) ), |
|
30
|
|
|
array( 'Jetpack_Client', '_wp_remote_request', array( 'Bogus', 'Bogus' ) ), |
|
31
|
|
|
array( 'Jetpack_Client', 'remote_request', array( 'Bogus' ) ), |
|
32
|
|
|
array( 'Jetpack_Client', 'wpcom_json_api_request_as_blog', array( 'Bogus' ) ), |
|
33
|
|
|
array( 'Jetpack_Options', 'get_option', array( 'Bogus' ), false ), |
|
34
|
|
|
array( 'Jetpack_Options', 'get_option_and_ensure_autoload', array( 'Bogus', 'Bogus' ), false ), |
|
35
|
|
|
array( 'Jetpack_Options', 'update_option', array( 'Bogus', 'Bogus' ), false ), |
|
36
|
|
|
array( 'Jetpack_Sync_Actions', 'initialize_listener', array() ), |
|
37
|
|
|
array( 'Jetpack_Sync_Actions', 'initialize_sender', array() ), |
|
38
|
|
|
array( 'Jetpack_Sync_Actions', 'sync_via_cron_allowed', array() ), |
|
39
|
|
|
array( 'Jetpack_Sync_Modules', 'get_module', array( 'Bogus' ) ), |
|
40
|
|
|
array( 'Jetpack_Sync_Settings', 'is_syncing', array() ), |
|
41
|
|
|
array( 'Jetpack_Sync_Settings', 'reset_data', array() ), |
|
42
|
|
|
array( 'Jetpack_Sync_Settings', 'update_settings', array( array( 'Bogus' => 1 ) ) ), |
|
43
|
|
|
array( 'Jetpack_Tracks_Client', 'get_connected_user_tracks_identity', array(), false ), |
|
44
|
|
|
array( 'Jetpack_Sync_Settings', 'is_syncing', array() ), |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @dataProvider provider_deprecated_defined_functions |
|
50
|
|
|
*/ |
|
51
|
|
|
function test_deprecated_defined_functions( $function ) { |
|
52
|
|
|
$this->assertTrue( function_exists( $function ) ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @dataProvider provider_deprecated_method_stubs |
|
57
|
|
|
*/ |
|
58
|
|
|
public function test_deprecated_method_smoke_test( $class, $method, $arguments, $expect_notice = true ) { |
|
59
|
|
|
if ( $expect_notice ) { |
|
60
|
|
|
$this->setExpectedDeprecated( "$class::$method" ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$class = new ReflectionClass( $class ); |
|
64
|
|
|
$method = $class->getMethod( $method ); |
|
65
|
|
|
|
|
66
|
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler |
|
67
|
|
|
set_error_handler( '__return_null' ); |
|
68
|
|
|
try { |
|
69
|
|
|
$method->invokeArgs( null, $arguments ); |
|
70
|
|
|
$this->assertTrue( true ); |
|
71
|
|
|
} catch ( Error $e ) { |
|
|
|
|
|
|
72
|
|
|
$this->fail( "{$class->getName()}::{$method->getName()} is throwing fatal errors.\n$e" ); |
|
73
|
|
|
} finally { |
|
74
|
|
|
restore_error_handler(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
function provider_deprecated_defined_functions() { |
|
79
|
|
|
return array( |
|
80
|
|
|
array( 'jetpack_tracks_get_identity' ), |
|
81
|
|
|
array( 'jetpack_tracks_record_event' ), |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
function test_jetpack_sync_action_sender_exists() { |
|
86
|
|
|
$this->assertTrue( property_exists( 'Jetpack_Sync_Actions', 'sender' ) ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Provides deprecated files and expected replacements. |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
|
|
function provider_deprecated_file_paths() { |
|
95
|
|
|
return array( |
|
96
|
|
|
array( |
|
97
|
|
|
'class.jetpack-ixr-client.php', |
|
98
|
|
|
'', |
|
99
|
|
|
), |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.