Completed
Pull Request — master (#133)
by Simone
02:04
created

RuleTest::testContainsConfigurationAsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of sensorario/resources repository
5
 *
6
 * (c) Simone Gentili <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sensorario\Resources\Test\Resources;
13
14
use PHPUnit\Framework\TestCase;
15
use Sensorario\Resources\Rulers\Rule;
16
17
class RuleTest extends TestCase
18
{
19
    /**
20
     * @expectedException \LogicException
21
     * @expectedExceptionMessage rule type is not defined
22
     */
23
    public function testIvalidInitializationThrowAndException()
24
    {
25
        $rule = Rule::fromArray([]);
0 ignored issues
show
Unused Code introduced by
$rule is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
    }
27
28
    public function testContainsConfigurationAsArray()
29
    {
30
        $rule = Rule::fromArray(
31
            $ruleConfiguration = [
32
                Rule::TYPE_OBJECT => [
33
                    '\DateTime',
34
                ]
35
            ]
36
        );
37
38
        $this->assertEquals(
39
            $ruleConfiguration,
40
            $rule->asArray()
41
        );
42
    }
43
44
    /**
45
     * @expectedException \Sensorario\Resources\Exceptions\InvalidTypeException
46
     * @expectedExceptionMessageRegex #Oops! Invalid configuration!!!Type `foo` is not valid.#
47
     */
48
    public function testInvalidTypeIsNotAllowed()
49
    {
50
        $rule = Rule::fromArray([
51
            'foo' => [ ]
52
        ]);
53
54
        $rule->ensureRuleNameIsValid();
55
    }
56
57
    public function testCheckFunctionReturnRuleValidityAsBoolean()
58
    {
59
        $rule = Rule::fromArray([
60
            'foo' => [ ]
61
        ]);
62
63
        $this->assertSame(
64
            false,
65
            $rule->isValid()
66
        );
67
    }
68
69 View Code Duplication
    public function testCheckIfValueIsOfRightObjectType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $rule = Rule::fromArray(
72
            $ruleConfiguration = [
73
                Rule::TYPE_OBJECT => [
74
                    '\DateTime',
75
                ]
76
            ]
77
        );
78
79
        $this->assertSame(
80
            true,
81
            $rule->is(Rule::TYPE_OBJECT)
82
        );
83
    }
84
85 View Code Duplication
    public function testCheckIfValueIsNotOfRightObjectType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        $rule = Rule::fromArray(
88
            $ruleConfiguration = [
89
                Rule::TYPE_OBJECT => [
90
                    '\DateTime',
91
                ]
92
            ]
93
        );
94
95
        $this->assertSame(
96
            false,
97
            $rule->isNot(Rule::TYPE_OBJECT)
98
        );
99
    }
100
101 View Code Duplication
    public function testGetExpectedType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103
        $rule = Rule::fromArray(
104
            $ruleConfiguration = [
105
                Rule::TYPE_OBJECT => [
106
                    '\DateTime',
107
                ]
108
            ]
109
        );
110
111
        $this->assertSame(
112
            ['\DateTime'],
113
            $rule->getExpectedType()
114
        );
115
    }
116
}
117