1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Compiler; |
4
|
|
|
|
5
|
|
|
use PHPSA\CompiledExpression; |
6
|
|
|
use PHPSA\Compiler\Types; |
7
|
|
|
use Tests\PHPSA\TestCase; |
8
|
|
|
|
9
|
|
|
class TypesTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @dataProvider typesAsStringProvider |
13
|
|
|
*/ |
14
|
|
|
public function testGetType($typeAsString, $expectedType) |
15
|
|
|
{ |
16
|
|
|
static::assertSame($expectedType, Types::getType($typeAsString)); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @expectedException \RuntimeException |
21
|
|
|
* @expectedExceptionMessage Type 'not a valid type' is not supported |
22
|
|
|
*/ |
23
|
|
|
public function testGetTypeWithAnUnknownTypeThrows() |
24
|
|
|
{ |
25
|
|
|
Types::getType('not a valid type'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function typesAsStringProvider() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
['integer', CompiledExpression::INTEGER], |
32
|
|
|
['int', CompiledExpression::INTEGER], |
33
|
|
|
['double', CompiledExpression::DOUBLE], |
34
|
|
|
['string', CompiledExpression::STRING], |
35
|
|
|
['resource', CompiledExpression::RESOURCE], |
36
|
|
|
['callable', CompiledExpression::CALLABLE_TYPE], |
37
|
|
|
['object', CompiledExpression::OBJECT], |
38
|
|
|
['array', CompiledExpression::ARR], |
39
|
|
|
['boolean', CompiledExpression::BOOLEAN], |
40
|
|
|
['bool', CompiledExpression::BOOLEAN], |
41
|
|
|
['NULL', CompiledExpression::NULL], |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|