Passed
Push — master ( 75f1be...abbf77 )
by Lucien
01:58
created

PluginRequirementsTest::testPluginRequirements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 61
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 9.5147
c 0
b 0
f 0
cc 1
eloc 46
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use TwinDigital\WPTools\PluginRequirements;
4
use TwinDigital\WPTools\PluginTools;
5
6
/**
7
 * Class PluginToolsTest
8
 */
9
class PluginRequirementsTest extends WP_UnitTestCase {
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
  /**
12
   * Plugins that come pre-installed with WordPress.
13
   *
14
   * @var array $preinstalledPlugins
15
   */
16
  public $preinstalledPlugins = [
17
    'Akismet Anti-Spam',
18
    'Hello Dolly',
19
  ];
20
21
  /**
22
   * Test adding a plugin-requirement.
23
   * @covers \TwinDigital\WPTools\PluginRequirements::checkPluginInstalled()
24
   * @covers \TwinDigital\WPTools\PluginRequirements::checkRequiredPlugins()
25
   * @covers \TwinDigital\WPTools\PluginRequirements::addPluginRequirement()
26
   * @covers \TwinDigital\WPTools\PluginRequirements::removePluginRequirement()
27
   * @return void
28
   */
29
  public function testPluginRequirements() {
30
    PluginTools::refreshLoadedPlugins();
31
    // Add plugin to requirements-list, first time should be true, second time false because requirement already in list.
32
    $this->assertTrue(
33
      PluginRequirements::addPluginRequirement(
34
        'Hello Dolly',
35
        '0.0.0',
36
        '0.0.0',
37
        true
38
      ),
39
      'Could not add fake requirements'
40
    );
41
    $this->assertFalse(
42
      PluginRequirements::addPluginRequirement(
43
        'Hello Dolly',
44
        '0.0.0',
45
        '0.0.0',
46
        true
47
      ),
48
      'Check for existing requirement failed'
49
    );
50
    $this->assertTrue(
51
      PluginRequirements::addPluginRequirement(
52
        'WPTools',
53
        '0.0.0',
54
        '0.0.0',
55
        true
56
      ),
57
      'Could not add fake requirements'
58
    );
59
    // Testing requiredPlugins should be false, since we set fake version-numbers.
60
    $this->assertFalse(
61
      PluginRequirements::checkRequiredPlugins(),
62
      'Requirement should not be met unless version number of Hello Dolly is 0.0.0'
63
    );
64
    $this->assertTrue(PluginRequirements::removePluginRequirement('WPTools'));
65
66
    $this->assertTrue(PluginRequirements::removePluginRequirement('Hello Dolly'));
67
    $this->assertFalse(PluginRequirements::removePluginRequirement('Hello Dolly'));
68
    $this->assertTrue(PluginRequirements::checkRequiredPlugins());
69
    activate_plugin('hello-dolly/hello.php');
70
    PluginTools::refreshLoadedPlugins();
71
    $this->assertTrue(
72
      PluginRequirements::addPluginRequirement(
73
        'Hello Dolly',
74
        '0.0.0',
75
        '999.999.999',
76
        false
77
      )
78
    );
79
    $this->assertTrue(PluginRequirements::checkRequiredPlugins(), 'Hello Dolly should not be active yet.');
80
    $this->assertTrue(PluginRequirements::removePluginRequirement('Hello Dolly'));
81
    $this->assertTrue(
82
      PluginRequirements::addPluginRequirement(
83
        'Hello Dolly',
84
        '0.0.0',
85
        '999.999.999',
86
        true
87
      )
88
    );
89
    $this->assertFalse(PluginRequirements::checkRequiredPlugins(), 'Hello Dolly should not be active yet.');
90
  }
91
}
92