1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName |
2
|
|
|
/** |
3
|
|
|
* Integration test suite for the manifest reading. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-autoloader |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
// We live in the namespace of the test autoloader to avoid many use statements. |
9
|
|
|
namespace Automattic\Jetpack\Autoloader\jpCurrent; |
10
|
|
|
|
11
|
|
|
// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents |
12
|
|
|
|
13
|
|
|
use Automattic\Jetpack\Autoloader\ManifestGenerator; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Test suite class for verifying that manifests we generate can also be read correctly. |
18
|
|
|
*/ |
19
|
|
|
class LoadingGeneratedManifestsTest extends TestCase { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The path to the test manifest we want to operate on. |
23
|
|
|
*/ |
24
|
|
|
const TEST_MANIFEST_PATH = 'vendor/composer/test-manifest.php'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The manifest handler we're testing. |
28
|
|
|
* |
29
|
|
|
* @var Manifest_Reader |
30
|
|
|
*/ |
31
|
|
|
private $manifest_handler; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Setup runs before each test. |
35
|
|
|
* |
36
|
|
|
* @before |
37
|
|
|
*/ |
38
|
|
|
public function set_up() { |
39
|
|
|
$this->manifest_handler = new Manifest_Reader( new Version_Selector() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Teardown runs after each test. |
44
|
|
|
* |
45
|
|
|
* @after |
46
|
|
|
*/ |
47
|
|
|
public function tear_down() { |
48
|
|
|
unlink( TEST_PLUGIN_DIR . '/' . self::TEST_MANIFEST_PATH ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Tests that the classmap manifest we generate can be read by the handler. |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function test_that_handler_reads_classmap_manifests() { |
55
|
|
|
$this->write_test_manifest( |
56
|
|
|
'classmap', |
57
|
|
|
array( |
58
|
|
|
'TestFile' => array( |
59
|
|
|
'path' => '$baseDir . \'/path_to_file.php\'', |
60
|
|
|
'version' => '1.0.0.0', |
61
|
|
|
), |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$loaded = array(); |
66
|
|
|
$this->manifest_handler->read_manifests( |
67
|
|
|
array( TEST_PLUGIN_DIR ), |
68
|
|
|
self::TEST_MANIFEST_PATH, |
69
|
|
|
$loaded |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->assertEquals( |
73
|
|
|
array( |
74
|
|
|
'TestFile' => array( |
75
|
|
|
'version' => '1.0.0.0', |
76
|
|
|
'path' => TEST_PLUGIN_DIR . '/path_to_file.php', |
77
|
|
|
), |
78
|
|
|
), |
79
|
|
|
$loaded |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Tests that the PSR-4 manifest we generate can be read by the handler. |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function test_that_handler_reads_psr4_manifests() { |
87
|
|
|
$this->write_test_manifest( |
88
|
|
|
'psr-4', |
89
|
|
|
array( |
90
|
|
|
'Automattic\\Jetpack\\' => array( |
91
|
|
|
'path' => array( '$baseDir . \'/src\'' ), |
92
|
|
|
'version' => '1.2.0.0', |
93
|
|
|
), |
94
|
|
|
) |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$loaded = array(); |
98
|
|
|
$this->manifest_handler->read_manifests( |
99
|
|
|
array( TEST_PLUGIN_DIR ), |
100
|
|
|
self::TEST_MANIFEST_PATH, |
101
|
|
|
$loaded |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->assertEquals( |
105
|
|
|
array( |
106
|
|
|
'Automattic\\Jetpack\\' => array( |
107
|
|
|
'version' => '1.2.0.0', |
108
|
|
|
'path' => array( TEST_PLUGIN_DIR . '/src' ), |
109
|
|
|
), |
110
|
|
|
), |
111
|
|
|
$loaded |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Tests that the files manifest we generate can be read by the handler. |
117
|
|
|
*/ |
118
|
|
View Code Duplication |
public function test_that_handler_reads_files_manifests() { |
119
|
|
|
$this->write_test_manifest( |
120
|
|
|
'files', |
121
|
|
|
array( |
122
|
|
|
'123d5a6s7vd' => array( |
123
|
|
|
'path' => '$baseDir . \'/path_to_file.php\'', |
124
|
|
|
'version' => '1.3.0.0', |
125
|
|
|
), |
126
|
|
|
) |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
$loaded = array(); |
130
|
|
|
$this->manifest_handler->read_manifests( |
131
|
|
|
array( TEST_PLUGIN_DIR ), |
132
|
|
|
self::TEST_MANIFEST_PATH, |
133
|
|
|
$loaded |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
$this->assertEquals( |
137
|
|
|
array( |
138
|
|
|
'123d5a6s7vd' => array( |
139
|
|
|
'version' => '1.3.0.0', |
140
|
|
|
'path' => TEST_PLUGIN_DIR . '/path_to_file.php', |
141
|
|
|
), |
142
|
|
|
), |
143
|
|
|
$loaded |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Writes the test manifest for the tests to use. |
149
|
|
|
* |
150
|
|
|
* @param string $autoload_type The type of manifest to generate. |
151
|
|
|
* @param array $content The content to write a manifest using. |
152
|
|
|
*/ |
153
|
|
|
private function write_test_manifest( $autoload_type, $content ) { |
154
|
|
|
file_put_contents( |
155
|
|
|
TEST_PLUGIN_DIR . '/' . self::TEST_MANIFEST_PATH, |
156
|
|
|
ManifestGenerator::buildManifest( $autoload_type, 'test-manifest.php', $content ) |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|