Completed
Push — tearDown ( d20aa4 )
by no
03:34
created

DataTypeTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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
 * @group DataTypes
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 * @author Thiemo Mättig
17
 */
18
class DataTypeTest extends PHPUnit_Framework_TestCase {
19
20
	protected function setUp() {
21
		parent::setUp();
22
23
		Message::registerTextFunction( function( $key, $languageCode ) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $languageCode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
			return implode( '|', func_get_args() );
25
		} );
26
	}
27
28
	protected function tearDown() {
29
		Message::registerTextFunction( null );
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
31
		parent::tearDown();
32
	}
33
34
	/**
35
	 * @dataProvider invalidConstructorArgumentsProvider
36
	 */
37
	public function testConstructorThrowsException( $propertyType, $valueType ) {
38
		$this->setExpectedException( 'InvalidArgumentException' );
39
		new DataType( $propertyType, $valueType );
40
	}
41
42
	public function invalidConstructorArgumentsProvider() {
43
		return array(
44
			array( 'propertyType', null ),
45
			array( 'propertyType', false ),
46
			array( null, 'valueType' ),
47
			array( false, 'valueType' ),
48
		);
49
	}
50
51
	public function testGetId() {
52
		$type = new DataType( 'propertyType', 'valueType' );
53
		$this->assertSame( 'propertyType', $type->getId() );
54
	}
55
56
	public function testGetDataValueType() {
57
		$type = new DataType( 'propertyType', 'valueType' );
58
		$this->assertSame( 'valueType', $type->getDataValueType() );
59
	}
60
61
	public function testGetLabel() {
62
		$type = new DataType( 'propertyType', 'valueType' );
63
		$this->assertSame( 'datatypes-type-propertyType|en', $type->getLabel( 'en' ) );
64
	}
65
66
	public function testToArray() {
67
		$type = new DataType( 'propertyType', 'valueType' );
68
		$this->assertSame( array( 'dataValueType' => 'valueType' ), $type->toArray() );
69
	}
70
71
}
72