Completed
Push — renovate/major-react-monorepo ( 880c2b...a6f86c )
by
unknown
355:09 queued 345:32
created

test_autoloader_resolves_symlinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName
2
/**
3
 * Acceptance test suite for the current autoloader.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
/**
9
 * Test suite class for verifying the functionality of the current autoloader.
10
 *
11
 * @runTestsInSeparateProcesses Ensure each test has a fresh process as if it was a real request.
12
 * @preserveGlobalState disabled
13
 */
14
class AutoloaderTest extends Acceptance_Test_Case {
15
16
	/**
17
	 * Tests that the autoloader works properly in the standard case.
18
	 */
19 View Code Duplication
	public function test_autoloader_as_active_plugin() {
20
		// Activate the current autoloader so it won't be unknown.
21
		$this->activate_autoloader( Test_Plugin_Factory::CURRENT );
22
23
		// Load and shutdown the autoloader safely.
24
		$this->load_plugin_autoloader( Test_Plugin_Factory::CURRENT );
25
		$this->trigger_shutdown( true );
26
27
		// Make sure the autoloader worked as expected.
28
		$this->assertAutoloaderVersion( Test_Plugin_Factory::CURRENT );
29
		$this->assertAutoloaderResetCount( 0 );
30
		$this->assertAutoloaderNotFoundUnknown( Test_Plugin_Factory::CURRENT );
31
		$this->assertAutoloaderCacheEquals( Test_Plugin_Factory::CURRENT );
32
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass::class );
33
	}
34
35
	/**
36
	 * Tests that the autoloader works properly as an mu-plugin.
37
	 */
38
	public function test_autoloader_as_mu_plugin() {
39
		// Load and shutdown the autoloader safely.
40
		$this->load_plugin_autoloader( self::CURRENT_MU );
41
		$this->trigger_shutdown( true );
42
43
		// Make sure the autoloader worked as expected.
44
		$this->assertAutoloaderVersion( self::CURRENT_MU );
45
		$this->assertAutoloaderResetCount( 0 );
46
		$this->assertAutoloaderFoundUnknown( self::CURRENT_MU );
47
		$this->assertAutoloaderCacheEquals( self::CURRENT_MU );
48
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Currentmu\UniqueTestClass::class );
49
	}
50
51
	/**
52
	 * Tests that the autoloader does not reset when all of the plugins are known during initialization.
53
	 */
54 View Code Duplication
	public function test_autoloader_does_not_reset_when_all_plugins_are_known() {
55
		// Activate the current autoloader so that the mu-plugin autoloader can see it.
56
		$this->activate_autoloader( Test_Plugin_Factory::CURRENT );
57
58
		// Load and shutdown the autoloaders safely.
59
		$this->execute_autoloader_chain(
60
			array(
61
				self::CURRENT_MU,
62
				Test_Plugin_Factory::CURRENT,
63
			),
64
			true
65
		);
66
67
		// Make sure the autoloader worked as expected.
68
		$this->assertAutoloaderVersion( Test_Plugin_Factory::CURRENT );
69
		$this->assertAutoloaderResetCount( 0 );
70
		$this->assertAutoloaderFoundUnknown( self::CURRENT_MU );
71
		$this->assertAutoloaderCacheEquals( array( self::CURRENT_MU, Test_Plugin_Factory::CURRENT ) );
72
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\SharedTestClass::class );
73
74
		$this->markTestIncomplete( 'The autoloader does not currently support PSR-4 loading from multiple directories.' );
75
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass::class );
76
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Currentmu\UniqueTestClass::class );
77
	}
78
79
	/**
80
	 * Tests that the autoloader resets when it encounters unknown plugins.
81
	 */
82 View Code Duplication
	public function test_autoloader_resets_when_plugins_are_unknown() {
83
		// Do not activate any plugins so that all are considered unknown.
84
85
		// Load and shutdown the autoloaders safely.
86
		$this->execute_autoloader_chain(
87
			array(
88
				self::CURRENT_MU,
89
				Test_Plugin_Factory::CURRENT,
90
			),
91
			true
92
		);
93
94
		// Make sure the autoloader worked as expected.
95
		$this->assertAutoloaderVersion( Test_Plugin_Factory::CURRENT );
96
		$this->assertAutoloaderResetCount( 1 );
97
		$this->assertAutoloaderFoundUnknown( self::CURRENT_MU );
98
		$this->assertAutoloaderCacheEquals( array( self::CURRENT_MU, Test_Plugin_Factory::CURRENT ) );
99
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\SharedTestClass::class );
100
101
		$this->markTestIncomplete( 'The autoloader does not currently support PSR-4 loading from multiple directories.' );
102
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass::class );
103
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Currentmu\UniqueTestClass::class );
104
	}
105
106
	/**
107
	 * Tests that the autoloader resolves symlinks to plugins so that those environments can be handled correctly.
108
	 */
109 View Code Duplication
	public function test_autoloader_resolves_symlinks() {
110
		$symlink_key = 'current_symlink';
111
112
		// Install the autoloader as a symlink so that we can execute it.
113
		$this->install_autoloader_symlink( Test_Plugin_Factory::CURRENT, false, $symlink_key );
114
115
		// Activate the symlink autoloader so it won't be unknown.
116
		$this->activate_autoloader( $symlink_key );
117
118
		// Load and shutdown the autoloader safely.
119
		$this->load_plugin_autoloader( $symlink_key );
120
		$this->trigger_shutdown( true );
121
122
		// Make sure the autoloader worked as expected.
123
		$this->assertAutoloaderVersion( Test_Plugin_Factory::CURRENT );
124
		$this->assertAutoloaderResetCount( 0 );
125
		$this->assertAutoloaderNotFoundUnknown( $symlink_key );
126
		// The symlink is stored in the cache resolved to the original directory.
127
		$this->assertAutoloaderCacheEquals( Test_Plugin_Factory::CURRENT );
128
		$this->assertAutoloaderProvidesClass( \Automattic\Jetpack\AutoloaderTesting\Current\UniqueTestClass::class );
129
	}
130
}
131