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