Completed
Push — renovate/copy-webpack-plugin-7... ( 1bd716...8ac6ba )
by
unknown
312:57 queued 302:49
created

HookManagerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 24.24 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A set_up() 0 3 1
A tear_down() 0 3 1
A test_adds_action() 8 8 1
A test_adds_filters() 8 8 1
A test_resets() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * The hook manager test suite.
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
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * Provides unit tests for the methods in the Hook_Manager class.
15
 */
16
class HookManagerTest extends TestCase {
17
18
	/**
19
	 * The hook manager we're testing.
20
	 *
21
	 * @var Hook_Manager
22
	 */
23
	private $hook_manager;
24
25
	/**
26
	 * Setup runs before each test.
27
	 *
28
	 * @before
29
	 */
30
	public function set_up() {
31
		$this->hook_manager = new Hook_Manager();
32
	}
33
34
	/**
35
	 * Teardown runs after each test.
36
	 *
37
	 * @after
38
	 */
39
	public function tear_down() {
40
		cleanup_test_wordpress_data();
41
	}
42
43
	/**
44
	 * Tests that the hook manager can add actions.
45
	 */
46 View Code Duplication
	public function test_adds_action() {
47
		$callable = function () {};
48
49
		$this->hook_manager->add_action( 'test', $callable, 11, 12 );
50
51
		$this->assertFalse( test_has_filter( 'test', $callable, 10, 12 ) );
52
		$this->assertTrue( test_has_filter( 'test', $callable, 11, 12 ) );
53
	}
54
55
	/**
56
	 * Tests that the hook manager can add filters.
57
	 */
58 View Code Duplication
	public function test_adds_filters() {
59
		$callable = function () {};
60
61
		$this->hook_manager->add_filter( 'test', $callable, 11, 12 );
62
63
		$this->assertFalse( test_has_filter( 'test', $callable, 10, 12 ) );
64
		$this->assertTrue( test_has_filter( 'test', $callable, 11, 12 ) );
65
	}
66
67
	/**
68
	 * Tests that the hook manager removes hooks on reset.
69
	 */
70
	public function test_resets() {
71
		$callable = function () {};
72
73
		$this->hook_manager->add_filter( 'test', $callable );
74
75
		$this->assertTrue( test_has_filter( 'test', $callable ) );
76
77
		$this->hook_manager->reset();
78
79
		$this->assertFalse( test_has_filter( 'test', $callable ) );
80
	}
81
}
82