1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DataTypes\Tests\Phpunit; |
4
|
|
|
|
5
|
|
|
use DataTypes\DataType; |
6
|
|
|
use DataTypes\Message; |
7
|
|
|
use PHPUnit_Framework_TestCase; |
8
|
|
|
use ReflectionClass; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers DataTypes\DataType |
12
|
|
|
* |
13
|
|
|
* @group DataTypes |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0+ |
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
17
|
|
|
* @author Thiemo Mättig |
18
|
|
|
*/ |
19
|
|
|
class DataTypeTest extends PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var callable|null |
23
|
|
|
*/ |
24
|
|
|
private $textFunction; |
25
|
|
|
|
26
|
|
|
protected function setUp() { |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
$class = new ReflectionClass( 'DataTypes\Message' ); |
30
|
|
|
$properties = $class->getStaticProperties(); |
31
|
|
|
$this->textFunction = $properties['textFunction']; |
32
|
|
|
|
33
|
|
|
Message::registerTextFunction( function( $key, $languageCode ) { |
|
|
|
|
34
|
|
|
return implode( '|', func_get_args() ); |
35
|
|
|
} ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function tearDown() { |
39
|
|
|
Message::registerTextFunction( $this->textFunction ); |
|
|
|
|
40
|
|
|
|
41
|
|
|
parent::tearDown(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @dataProvider invalidConstructorArgumentsProvider |
46
|
|
|
*/ |
47
|
|
|
public function testConstructorThrowsException( $propertyType, $valueType ) { |
48
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
49
|
|
|
new DataType( $propertyType, $valueType ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function invalidConstructorArgumentsProvider() { |
53
|
|
|
return array( |
54
|
|
|
array( 'propertyType', '' ), |
55
|
|
|
array( 'propertyType', null ), |
56
|
|
|
array( 'propertyType', false ), |
57
|
|
|
array( 'propertyType', 1 ), |
58
|
|
|
array( '', 'valueType' ), |
59
|
|
|
array( null, 'valueType' ), |
60
|
|
|
array( false, 'valueType' ), |
61
|
|
|
array( 0, 'valueType' ), |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testGetId() { |
66
|
|
|
$type = new DataType( 'propertyType', 'valueType' ); |
67
|
|
|
$this->assertSame( 'propertyType', $type->getId() ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testGetDataValueType() { |
71
|
|
|
$type = new DataType( 'propertyType', 'valueType' ); |
72
|
|
|
$this->assertSame( 'valueType', $type->getDataValueType() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetLabel() { |
76
|
|
|
$type = new DataType( 'propertyType', 'valueType' ); |
77
|
|
|
$this->assertSame( 'datatypes-type-propertyType|en', $type->getLabel( 'en' ) ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testToArray() { |
81
|
|
|
$type = new DataType( 'propertyType', 'valueType' ); |
82
|
|
|
$this->assertSame( array( 'dataValueType' => 'valueType' ), $type->toArray() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.