Completed
Push — feature/427-FeatureToggle-with... ( 142147 )
by Michael
05:42
created

FeatureToggleTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFeaturesContainsTestFeature() 0 5 1
A testHasFeatureReturnsWhenNoParameterExistsForTestFeature() 0 6 1
A testGetFeaturesExists() 0 4 1
A testHasFeatureReturnsFalseForTestFeature() 0 4 1
A testHasFeatureReturnsFalseForUnknownFeature() 0 4 1
A testHasFeatureExists() 0 4 1
A testGetFeaturesReturnsAnArray() 0 4 1
A testHasFeatureReturnsTrueWhenTestFeatureIsEnabledByParameter() 0 7 1
A testHasFeatureThrowsErrorWithMissingParameter() 0 6 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
            ['test_feature' => false]
81
        ]);
82
        self::assertFalse($featureToggle->hasFeature('test_feature'));
83
    }
84
85
    /**
86
     * tests hasFeature() returns true when test Feature is enabled by parameter
87
     */
88
    public function testHasFeatureReturnsTrueWhenTestFeatureIsEnabledByParameter()
89
    {
90
        $featureToggle = new FeatureToggle([
91
            ['test_feature' => true],
92
        ]);
93
94
        self::assertTrue($featureToggle->hasFeature('test_feature'));
95
    }
96
97
    /**
98
     * tests getFeatures() is existing
99
     */
100
    public function testGetFeaturesExists()
101
    {
102
        $featureToggle = new FeatureToggle([]);
103
        self::assertTrue(method_exists($featureToggle, 'getFeatures'));
104
    }
105
106
    /**
107
     * tests getFeatures() returns an array
108
     */
109
    public function testGetFeaturesReturnsAnArray()
110
    {
111
        $featureToggle = new FeatureToggle([]);
112
        self::assertInternalType('array', $featureToggle->getFeatures());
113
    }
114
115
    /**
116
     * tests getFeature() count is greater than 1
117
     */
118
    public function testGetFeaturesCountGreaterOne()
119
    {
120
        $featureToggle = new FeatureToggle([]);
121
        self::assertGreaterThan(0, count($featureToggle->getFeatures()));
122
    }
123
124
    /**
125
     * tests getFeatures() contains the test feature
126
     */
127
    public function testGetFeaturesContainsTestFeature()
128
    {
129
        $featureToggle = new FeatureToggle([]);
130
        $features = $featureToggle->getFeatures();
131
        self::assertContains('test_feature', $features);
132
    }
133
}
134