|
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 hook manager mock; |
|
20
|
|
|
* |
|
21
|
|
|
* @var Hook_Manager|\PHPUnit\Framework\MockObject\MockObject |
|
22
|
|
|
*/ |
|
23
|
|
|
private $hook_manager; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The manifest reader mock. |
|
27
|
|
|
* |
|
28
|
|
|
* @var Manifest_Reader|\PHPUnit\Framework\MockObject\MockObject |
|
29
|
|
|
*/ |
|
30
|
|
|
private $manifest_reader; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The autoloader handler we're testing. |
|
34
|
|
|
* |
|
35
|
|
|
* @var Autoloader_Handler |
|
36
|
|
|
*/ |
|
37
|
|
|
private $autoloader_handler; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Setup runs before each test. |
|
41
|
|
|
* |
|
42
|
|
|
* @before |
|
43
|
|
|
*/ |
|
44
|
|
|
public function set_up() { |
|
45
|
|
|
$this->hook_manager = $this->getMockBuilder( Hook_Manager::class ) |
|
46
|
|
|
->disableOriginalConstructor() |
|
47
|
|
|
->getMock(); |
|
48
|
|
|
$this->manifest_reader = $this->getMockBuilder( Manifest_Reader::class ) |
|
49
|
|
|
->disableOriginalConstructor() |
|
50
|
|
|
->getMock(); |
|
51
|
|
|
$version_selector = $this->getMockBuilder( Version_Selector::class ) |
|
52
|
|
|
->disableOriginalConstructor() |
|
53
|
|
|
->getMock(); |
|
54
|
|
|
$this->autoloader_handler = new Autoloader_Handler( |
|
55
|
|
|
$this->hook_manager, |
|
56
|
|
|
$this->manifest_reader, |
|
57
|
|
|
$version_selector |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Tests that the handler is able to creates the autoloader successfully. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function test_create_autoloader() { |
|
65
|
|
|
$plugins = array( TEST_DATA_PATH . '/plugins/dummy_newer' ); |
|
66
|
|
|
|
|
67
|
|
|
$this->manifest_reader->expects( $this->exactly( 3 ) ) |
|
|
|
|
|
|
68
|
|
|
->method( 'read_manifests' ) |
|
69
|
|
|
->withConsecutive( |
|
70
|
|
|
array( $plugins, 'vendor/composer/jetpack_autoload_psr4.php' ), |
|
71
|
|
|
array( $plugins, 'vendor/composer/jetpack_autoload_classmap.php' ), |
|
72
|
|
|
array( $plugins, 'vendor/composer/jetpack_autoload_filemap.php' ) |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$this->autoloader_handler->create_autoloader( $plugins ); |
|
76
|
|
|
|
|
77
|
|
|
global $jetpack_autoloader_loader; |
|
78
|
|
|
$this->assertInstanceOf( Version_Loader::class, $jetpack_autoloader_loader ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Tests that the handler is able to reset the autoloader successfully. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function test_reset_autoloader() { |
|
85
|
|
|
global $jetpack_autoloader_loader; |
|
86
|
|
|
global $jetpack_autoloader_latest_version; |
|
87
|
|
|
|
|
88
|
|
|
$jetpack_autoloader_loader = 'test'; |
|
89
|
|
|
$jetpack_autoloader_latest_version = 'test'; |
|
90
|
|
|
$this->hook_manager->expects( $this->once() ) |
|
|
|
|
|
|
91
|
|
|
->method( 'reset' ); |
|
92
|
|
|
|
|
93
|
|
|
$this->autoloader_handler->reset_autoloader(); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertNull( $jetpack_autoloader_loader ); |
|
96
|
|
|
$this->assertNull( $jetpack_autoloader_latest_version ); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
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.