Completed
Push — add/e2e-connection-purchase-fl... ( d02cce...68beb5 )
by Yaroslav
14:07 queued 04:35
created

WP_Test_Autoloader_Locator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A test_finds_latest_autoloader() 0 25 1
A test_gets_autoloader_path() 0 4 1
A test_gets_autoloader_version_as_null_without_class() 0 5 1
A test_gets_autoloader_version() 0 5 1
1
<?php // phpcs:ignore WordPress.Files.FileName
2
/**
3
 * Autoloader locator test suite.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Test suite class for the Autoloader locator.
12
 */
13
class WP_Test_Autoloader_Locator extends TestCase {
14
15
	/**
16
	 * The locator we are testing.
17
	 *
18
	 * @var Autoloader_Locator
19
	 */
20
	private $autoloader_locator;
21
22
	/**
23
	 * Setup executes before each test.
24
	 */
25
	public function setUp() {
26
		parent::setUp();
27
28
		$this->autoloader_locator = new Autoloader_Locator( new Version_Selector() );
29
	}
30
31
	/**
32
	 * Tests the locator to find the latest version of the autoloader.
33
	 */
34
	public function test_finds_latest_autoloader() {
35
		$latest_version = null;
36
		$latest         = $this->autoloader_locator->find_latest_autoloader( array(), $latest_version );
37
		$this->assertNull( $latest );
38
		$this->assertNull( $latest_version );
39
40
		$latest = $this->autoloader_locator->find_latest_autoloader(
41
			array(
42
				TEST_DATA_PATH . '/plugins/plugin_current',
43
			),
44
			$latest_version
45
		);
46
		$this->assertEquals( TEST_DATA_PATH . '/plugins/plugin_current', $latest );
47
		$this->assertEquals( '2.0.0.0', $latest_version );
48
49
		$latest = $this->autoloader_locator->find_latest_autoloader(
50
			array(
51
				TEST_DATA_PATH . '/plugins/plugin_newer',
52
				TEST_DATA_PATH . '/plugins/plugin_current',
53
			),
54
			$latest_version
55
		);
56
		$this->assertEquals( TEST_DATA_PATH . '/plugins/plugin_newer', $latest );
57
		$this->assertEquals( '2.2.0.0', $latest_version );
58
	}
59
60
	/**
61
	 * Tests that the locator can find the path to the autoloader file.
62
	 */
63
	public function test_gets_autoloader_path() {
64
		$path = $this->autoloader_locator->get_autoloader_path( TEST_DATA_PATH . '/plugins/plugin_current' );
65
		$this->assertEquals( TEST_DATA_PATH . '/plugins/plugin_current/vendor/autoload_packages.php', $path );
66
	}
67
68
	/**
69
	 * Tests that the locator returns null when no version could be found.
70
	 */
71
	public function test_gets_autoloader_version_as_null_without_class() {
72
		$version = $this->autoloader_locator->get_autoloader_version( TEST_DATA_PATH );
73
74
		$this->assertNull( $version );
75
	}
76
77
	/**
78
	 * Tests that the locator can find the version..
79
	 */
80
	public function test_gets_autoloader_version() {
81
		$version = $this->autoloader_locator->get_autoloader_version( TEST_DATA_PATH . '/plugins/plugin_current' );
82
83
		$this->assertEquals( '2.0.0.0', $version );
84
	}
85
}
86