UtilTest::testFloatType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2014-2016 Ryan Parman.
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * http://opensource.org/licenses/MIT
24
 */
25
26
namespace Skyzyx\Tests\StrongTypes;
27
28
use Skyzyx\StrongTypes as IO;
29
30
class UtilTest extends \PHPUnit_Framework_TestCase
31
{
32
    public function testBooleanType()
33
    {
34
        $this->assertEquals('Skyzyx\StrongTypes\BooleanType',
35
            IO\Util::getClassOrType(
36
                IO\Util::getStrongScalarType('true')
37
            )
38
        );
39
40
        $this->assertEquals('Skyzyx\StrongTypes\BooleanType',
41
            IO\Util::getClassOrType(
42
                IO\Util::getStrongScalarType('false')
43
            )
44
        );
45
46
        $this->assertEquals('Skyzyx\StrongTypes\BooleanType',
47
            IO\Util::getClassOrType(
48
                IO\Util::getStrongScalarType(true)
49
            )
50
        );
51
    }
52
53
    public function testFloatType()
54
    {
55
        $this->assertEquals('Skyzyx\StrongTypes\FloatType',
56
            IO\Util::getClassOrType(
57
                IO\Util::getStrongScalarType('123456.789')
58
            )
59
        );
60
61
        $this->assertEquals('Skyzyx\StrongTypes\FloatType',
62
            IO\Util::getClassOrType(
63
                IO\Util::getStrongScalarType(123456.789)
64
            )
65
        );
66
    }
67
68
    public function testIntegerType()
69
    {
70
        $this->assertEquals('Skyzyx\StrongTypes\IntegerType',
71
            IO\Util::getClassOrType(
72
                IO\Util::getStrongScalarType('123456789')
73
            )
74
        );
75
76
        $this->assertEquals('Skyzyx\StrongTypes\IntegerType',
77
            IO\Util::getClassOrType(
78
                IO\Util::getStrongScalarType(123456789)
79
            )
80
        );
81
    }
82
83
    public function testStringType()
84
    {
85
        $this->assertEquals('Skyzyx\StrongTypes\StringType',
86
            IO\Util::getClassOrType(
87
                IO\Util::getStrongScalarType('abc123')
88
            )
89
        );
90
    }
91
92
    public function testValidatedBooleanType()
93
    {
94
        $this->assertEquals(true,
95
            IO\Util::getValidatedValue(
96
                new IO\BooleanType(true)
97
            )
98
        );
99
    }
100
101
    public function testValidatedFloatType()
102
    {
103
        $this->assertEquals(123456.789,
104
            IO\Util::getValidatedValue(
105
                new IO\FloatType(123456.789)
106
            )
107
        );
108
    }
109
110
    public function testValidatedIntegerType()
111
    {
112
        $this->assertEquals(123456789,
113
            IO\Util::getValidatedValue(
114
                new IO\IntegerType(123456789)
115
            )
116
        );
117
    }
118
119
    public function testValidatedStringType()
120
    {
121
        $this->assertEquals('abc123',
122
            IO\Util::getValidatedValue(
123
                new IO\StringType('abc123')
124
            )
125
        );
126
    }
127
}
128