FeatureToggleTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 107
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testHasFeatureReturnsFalseForTestFeature() 0 4 1
A testHasFeatureReturnsFalseForUnknownFeature() 0 4 1
A testHasFeatureExists() 0 4 1
A testHasFeatureThrowsErrorWithMissingParameter() 0 6 1
A testGetFeaturesContainsTestFeature() 0 5 1
A testHasFeatureReturnsWhenNoParameterExistsForTestFeature() 0 10 1
A testGetFeaturesExists() 0 4 1
A testGetFeaturesReturnsAnArray() 0 4 1
A testHasFeatureReturnsTrueWhenTestFeatureIsEnabledByParameter() 0 7 1
A testGetFeaturesCountGreaterOne() 0 4 1
1
<?php
2
/* Copyright (C) 2017 Michael Giesler
3
 *
4
 * This file is part of Dembelo.
5
 *
6
 * Dembelo is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Dembelo is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License 3 for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License 3
17
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace DembeloMain\Tests\Model;
21
22
use DembeloMain\Model\FeatureToggle;
23
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
24
use Symfony\Component\DependencyInjection\Container;
25
26
/**
27
 * Class FeatureToggleTest
28
 */
29
class FeatureToggleTest extends WebTestCase
30
{
31
    /**
32
     * @var FeatureToggle
33
     */
34
    private $featureToggle;
0 ignored issues
show
introduced by
The private property $featureToggle is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @return void
38
     */
39
    public function testHasFeatureExists(): void
40
    {
41
        $featureToggle = new FeatureToggle([]);
42
        $this->assertTrue(method_exists($featureToggle, 'hasFeature'));
43
    }
44
45
    /**
46
     * @return void
47
     */
48
    public function testHasFeatureThrowsErrorWithMissingParameter(): void
49
    {
50
        $featureToggle = new FeatureToggle([]);
51
52
        $this->expectException(\ArgumentCountError::class);
53
        $featureToggle->hasFeature();
0 ignored issues
show
Bug introduced by
The call to DembeloMain\Model\FeatureToggle::hasFeature() has too few arguments starting with featureKey. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $featureToggle->/** @scrutinizer ignore-call */ 
54
                        hasFeature();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
54
    }
55
56
    /**
57
     * tests hasFeature() returns false for unknown feature
58
     */
59
    public function testHasFeatureReturnsFalseForUnknownFeature()
60
    {
61
        $featureToggle = new FeatureToggle([]);
62
        self::assertFalse($featureToggle->hasFeature('unknownFeature'));
63
    }
64
65
    /**
66
     * tests hasFeature returns false for test feature
67
     */
68
    public function testHasFeatureReturnsFalseForTestFeature()
69
    {
70
        $featureToggle = new FeatureToggle([]);
71
        self::assertFalse($featureToggle->hasFeature('test_feature'));
72
    }
73
74
    /**
75
     * tests hasFeature() returns false when no parameter exists for test feature
76
     */
77
    public function testHasFeatureReturnsWhenNoParameterExistsForTestFeature()
78
    {
79
        $featureToggle = new FeatureToggle(
80
            [
81
                [
82
                    'test_feature' => false,
83
                ],
84
            ]
85
        );
86
        self::assertFalse($featureToggle->hasFeature('test_feature'));
87
    }
88
89
    /**
90
     * tests hasFeature() returns true when test Feature is enabled by parameter
91
     */
92
    public function testHasFeatureReturnsTrueWhenTestFeatureIsEnabledByParameter()
93
    {
94
        $featureToggle = new FeatureToggle([
95
            ['test_feature' => true],
96
        ]);
97
98
        self::assertTrue($featureToggle->hasFeature('test_feature'));
99
    }
100
101
    /**
102
     * tests getFeatures() is existing
103
     */
104
    public function testGetFeaturesExists()
105
    {
106
        $featureToggle = new FeatureToggle([]);
107
        self::assertTrue(method_exists($featureToggle, 'getFeatures'));
108
    }
109
110
    /**
111
     * tests getFeatures() returns an array
112
     */
113
    public function testGetFeaturesReturnsAnArray()
114
    {
115
        $featureToggle = new FeatureToggle([]);
116
        self::assertInternalType('array', $featureToggle->getFeatures());
117
    }
118
119
    /**
120
     * tests getFeature() count is greater than 1
121
     */
122
    public function testGetFeaturesCountGreaterOne()
123
    {
124
        $featureToggle = new FeatureToggle([]);
125
        self::assertGreaterThan(0, count($featureToggle->getFeatures()));
126
    }
127
128
    /**
129
     * tests getFeatures() contains the test feature
130
     */
131
    public function testGetFeaturesContainsTestFeature()
132
    {
133
        $featureToggle = new FeatureToggle([]);
134
        $features = $featureToggle->getFeatures();
135
        self::assertContains('test_feature', $features);
136
    }
137
}
138