Failed Conditions
Branch ignore-unknown-keywords (efa676)
by Stéphane
02:58
created

TypesTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 45
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetPrimitiveType() 0 5 1
A testGetPrimitiveTypeThrowsOnUnsupportedType() 0 4 1
A testIsA() 0 9 1
A instanceTypeProvider() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of the JVal package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace JVal;
11
12
use JVal\Testing\BaseTestCase;
13
14
class TypesTest extends BaseTestCase
15
{
16
    /**
17
     * @dataProvider instanceTypeProvider
18
     *
19
     * @param mixed  $instance
20
     * @param string $expectedType
21
     */
22
    public function testGetPrimitiveType($instance, $expectedType)
23
    {
24
        $actualType = Types::getPrimitiveTypeOf($instance);
25
        $this->assertEquals($expectedType, $actualType);
26
    }
27
28
    /**
29
     * @expectedException \JVal\Exception\UnsupportedTypeException
30
     */
31
    public function testGetPrimitiveTypeThrowsOnUnsupportedType()
32
    {
33
        Types::getPrimitiveTypeOf(fopen(__FILE__, 'r'));
34
    }
35
36
    public function testIsA()
37
    {
38
        $this->assertTrue(Types::isA([], Types::TYPE_ARRAY));
39
        $this->assertTrue(Types::isA('foo', Types::TYPE_STRING));
40
        $this->assertTrue(Types::isA(123, Types::TYPE_INTEGER));
41
        $this->assertTrue(Types::isA(123, Types::TYPE_NUMBER));
42
        $this->assertFalse(Types::isA(1.23, Types::TYPE_INTEGER));
43
        $this->assertTrue(Types::isA(1.23, Types::TYPE_NUMBER));
44
    }
45
46
    public function instanceTypeProvider()
47
    {
48
        return [
49
            [[1, 2, 3], Types::TYPE_ARRAY],
50
            [true, Types::TYPE_BOOLEAN],
51
            [123, Types::TYPE_INTEGER],
52
            [1.23, Types::TYPE_NUMBER],
53
            [null, Types::TYPE_NULL],
54
            [new \stdClass(), Types::TYPE_OBJECT],
55
            ['123', Types::TYPE_STRING],
56
        ];
57
    }
58
}
59