Completed
Push — add/autoloader-path-cache ( f1e7cc...c5c740 )
by
unknown
55:01 queued 47:07
created

Test_Plugin::set_up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * Unit tests for the Connection Plugin Manager class.
4
 *
5
 * @package automattic/jetpack-connection
6
 * @see \Automattic\Jetpack\Connection\Plugin
7
 */
8
9
namespace Automattic\Jetpack\Connection;
10
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * Unit tests for the Connection Plugin Manager class.
15
 *
16
 * @see \Automattic\Jetpack\Connection\Plugin
17
 */
18
class Test_Plugin extends TestCase {
19
20
	const PLUGIN_SLUG = 'sample-plugin-slug';
21
22
	const PLUGIN_NAME = 'Sample Plugin Name';
23
24
	/**
25
	 * Sample plugin arguments.
26
	 *
27
	 * @var array
28
	 */
29
	private $plugin_args = array(
30
		'url_info' => 'https://example.org/',
31
	);
32
33
	/**
34
	 * Initialization of the test class
35
	 *
36
	 * @before
37
	 * @throws MockEnabledException PHPUnit wasn't able to enable mock functions  ¯\_(⊙︿⊙)_/¯.
38
	 */
39
	protected function set_up() {
40
		Plugin_Storage::configure();
41
	}
42
43
	/**
44
	 * Unit test for the `Plugin::add()` method.
45
	 *
46
	 * @covers Automattic\Jetpack\Connection\Plugin::add
47
	 */
48
	public function test_add() {
49
		$plugin = new Plugin( self::PLUGIN_SLUG );
50
51
		$plugin->add( self::PLUGIN_NAME, $this->plugin_args + array( 'invalid_key' => 'value' ) );
52
53
		$this->assertEquals( array( 'name' => self::PLUGIN_NAME ) + $this->plugin_args, Plugin_Storage::get_one( self::PLUGIN_SLUG ) );
54
	}
55
56
	/**
57
	 * Unit test for the `Plugin::remove()` method.
58
	 *
59
	 * @depends test_add
60
	 * @covers Automattic\Jetpack\Connection\Plugin::remove
61
	 */
62
	public function test_remove() {
63
		$plugin = new Plugin( self::PLUGIN_SLUG );
64
		$plugin->remove();
65
66
		$this->assertArrayNotHasKey( self::PLUGIN_SLUG, Plugin_Storage::get_all() );
67
	}
68
69
}
70