Completed
Push — update/show-recurring-payments... ( 106a5e...b030b6 )
by
unknown
415:44 queued 407:29
created

test_builds_classmap_manifest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 29
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 29
loc 29
rs 9.456
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName
2
/**
3
 * Autoloader test suite.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
use Automattic\Jetpack\Autoloader\ManifestGenerator;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * Test suite class for the manifest generator
13
 */
14
class ManifestGeneratorTest extends TestCase {
15
16
	/**
17
	 * Tests that all of the manifest generation methods do nothing without content.
18
	 */
19
	public function test_manifests_do_nothing_without_content() {
20
		$this->assertNull( ManifestGenerator::buildManifest( 'classmap', 'test', array() ) );
21
		$this->assertNull( ManifestGenerator::buildManifest( 'psr-4', 'test', array() ) );
22
		$this->assertNull( ManifestGenerator::buildManifest( 'files', 'test', array() ) );
23
	}
24
25
	/**
26
	 * Tests that manifests for classmaps are generated correctly.
27
	 */
28 View Code Duplication
	public function test_builds_classmap_manifest() {
29
		$expected = <<<EXPECTED_FILE
30
<?php
31
32
// This file `test-file.php` was auto generated by automattic/jetpack-autoloader.
33
34
\$vendorDir = dirname(__DIR__);
35
\$baseDir   = dirname(\$vendorDir);
36
37
return array(
38
	'TestFile' => array(
39
		'version' => '1.0.0.0',
40
		'path'    => \$vendorDir . '/path_to_file.php'
41
	),
42
);
43
44
EXPECTED_FILE;
45
46
		$content = array(
47
			'TestFile' => array(
48
				'path'    => '$vendorDir . \'/path_to_file.php\'',
49
				'version' => '1.0.0.0',
50
			),
51
		);
52
53
		$manifest = ManifestGenerator::buildManifest( 'classmap', 'test-file.php', $content );
54
55
		$this->assertEquals( $expected, $manifest );
56
	}
57
58
	/**
59
	 * Tests that manifests for PSR-4 are generated correctly.
60
	 */
61 View Code Duplication
	public function test_builds_psr_manifest() {
62
		$expected = <<<EXPECTED_FILE
63
<?php
64
65
// This file `test-file2.php` was auto generated by automattic/jetpack-autoloader.
66
67
\$vendorDir = dirname(__DIR__);
68
\$baseDir   = dirname(\$vendorDir);
69
70
return array(
71
	'Automattic\\\\Jetpack\\\\' => array(
72
		'version' => '1.0.0.0',
73
		'path'    => array( \$vendorDir . '/src' )
74
	),
75
);
76
77
EXPECTED_FILE;
78
79
		$content = array(
80
			'Automattic\\Jetpack\\' => array(
81
				'path'    => array( '$vendorDir . \'/src\'' ),
82
				'version' => '1.0.0.0',
83
			),
84
		);
85
86
		$manifest = ManifestGenerator::buildManifest( 'psr-4', 'test-file2.php', $content );
87
88
		$this->assertEquals( $expected, $manifest );
89
	}
90
91
	/**
92
	 * Tests that manifests for files are generated correctly.
93
	 */
94 View Code Duplication
	public function test_builds_files_manifest() {
95
		$expected = <<<EXPECTED_FILE
96
<?php
97
98
// This file `test-file3.php` was auto generated by automattic/jetpack-autoloader.
99
100
\$vendorDir = dirname(__DIR__);
101
\$baseDir   = dirname(\$vendorDir);
102
103
return array(
104
	'123d5a6s7vd' => array(
105
		'version' => '1.0.0.0',
106
		'path'    => \$vendorDir . '/path_to_file.php'
107
	),
108
);
109
110
EXPECTED_FILE;
111
112
		$content = array(
113
			'123d5a6s7vd' => array(
114
				'path'    => '$vendorDir . \'/path_to_file.php\'',
115
				'version' => '1.0.0.0',
116
			),
117
		);
118
119
		$manifest = ManifestGenerator::buildManifest( 'files', 'test-file3.php', $content );
120
121
		$this->assertEquals( $expected, $manifest );
122
	}
123
}
124