1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName |
2
|
|
|
/** |
3
|
|
|
* Autoloader handler test suite. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-autoloader |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test suite class for the Autoloader handler. |
12
|
|
|
* |
13
|
|
|
* @runClassInSeparateProcess |
14
|
|
|
* @preserveGlobalState disabled |
15
|
|
|
*/ |
16
|
|
|
class Test_Autoloader_Handler extends TestCase { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The php autoloader mock; |
20
|
|
|
* |
21
|
|
|
* @var PHP_Autoloader|\PHPUnit\Framework\MockObject\MockObject |
22
|
|
|
*/ |
23
|
|
|
private $php_autoloader; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The hook manager mock; |
27
|
|
|
* |
28
|
|
|
* @var Hook_Manager|\PHPUnit\Framework\MockObject\MockObject |
29
|
|
|
*/ |
30
|
|
|
private $hook_manager; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The manifest reader mock. |
34
|
|
|
* |
35
|
|
|
* @var Manifest_Reader|\PHPUnit\Framework\MockObject\MockObject |
36
|
|
|
*/ |
37
|
|
|
private $manifest_reader; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The autoloader handler we're testing. |
41
|
|
|
* |
42
|
|
|
* @var Autoloader_Handler |
43
|
|
|
*/ |
44
|
|
|
private $autoloader_handler; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Setup runs before each test. |
48
|
|
|
* |
49
|
|
|
* @before |
50
|
|
|
*/ |
51
|
|
|
public function set_up() { |
52
|
|
|
$this->php_autoloader = $this->getMockBuilder( PHP_Autoloader::class ) |
53
|
|
|
->disableOriginalConstructor() |
54
|
|
|
->getMock(); |
55
|
|
|
$this->hook_manager = $this->getMockBuilder( Hook_Manager::class ) |
56
|
|
|
->disableOriginalConstructor() |
57
|
|
|
->getMock(); |
58
|
|
|
$this->manifest_reader = $this->getMockBuilder( Manifest_Reader::class ) |
59
|
|
|
->disableOriginalConstructor() |
60
|
|
|
->getMock(); |
61
|
|
|
$version_selector = $this->getMockBuilder( Version_Selector::class ) |
62
|
|
|
->disableOriginalConstructor() |
63
|
|
|
->getMock(); |
64
|
|
|
$this->autoloader_handler = new Autoloader_Handler( |
65
|
|
|
$this->php_autoloader, |
66
|
|
|
$this->hook_manager, |
67
|
|
|
$this->manifest_reader, |
68
|
|
|
$version_selector |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Tests that the handler is able to activate the autoloader successfully. |
74
|
|
|
*/ |
75
|
|
|
public function test_activates_autoloader() { |
76
|
|
|
$plugins = array( TEST_DATA_PATH . '/plugins/dummy_newer' ); |
77
|
|
|
|
78
|
|
|
$this->manifest_reader->expects( $this->exactly( 3 ) ) |
|
|
|
|
79
|
|
|
->method( 'read_manifests' ) |
80
|
|
|
->withConsecutive( |
81
|
|
|
array( $plugins, 'vendor/composer/jetpack_autoload_psr4.php' ), |
82
|
|
|
array( $plugins, 'vendor/composer/jetpack_autoload_classmap.php' ), |
83
|
|
|
array( $plugins, 'vendor/composer/jetpack_autoload_filemap.php' ) |
84
|
|
|
); |
85
|
|
|
$this->php_autoloader->expects( $this->once() ) |
|
|
|
|
86
|
|
|
->method( 'register_autoloader' ); |
87
|
|
|
|
88
|
|
|
$this->autoloader_handler->activate_autoloader( $plugins ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Tests that the handler is able to reset the autoloader successfully. |
93
|
|
|
*/ |
94
|
|
|
public function test_reset_autoloader() { |
95
|
|
|
global $jetpack_autoloader_loader; |
96
|
|
|
global $jetpack_autoloader_latest_version; |
97
|
|
|
|
98
|
|
|
$jetpack_autoloader_loader = 'test'; |
99
|
|
|
$jetpack_autoloader_latest_version = 'test'; |
100
|
|
|
$this->php_autoloader->expects( $this->once() ) |
|
|
|
|
101
|
|
|
->method( 'unregister_autoloader' ); |
102
|
|
|
$this->hook_manager->expects( $this->once() ) |
|
|
|
|
103
|
|
|
->method( 'reset' ); |
104
|
|
|
|
105
|
|
|
$this->autoloader_handler->reset_autoloader(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.