1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<?php
namespace SMW\Tests;
use SMWDataItem;
/**
* Base class for SMW\DataItem tests.
*
* @group SMW
* @group SMWExtension
* @group SMWDataItems
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
abstract class DataItemTest extends MwDBaseUnitTestCase {
/**
* Returns the name of the \SMW\DataItem deriving class this test tests.
*
* @since 1.8
*
* @return string
*/
public abstract function getClass();
/**
* @since 1.8
*
* @return array
*/
public abstract function constructorProvider();
/**
* Creates and returns a new instance of the data item.
*
* @since 1.8
*
* @return SMWDataItem
*/
public function newInstance() {
$reflector = new \ReflectionClass( $this->getClass() );
$args = func_get_args();
$instance = $reflector->newInstanceArgs( $args );
return $instance;
}
/**
* @since 1.8
*
* @return array
*/
public function instanceProvider() {
$phpFails = [ $this, 'newInstance' ];
return array_map(
function( array $args ) use ( $phpFails ) {
return [ call_user_func_array( $phpFails, $args ) ];
},
$this->constructorProvider()
);
}
/**
* @dataProvider constructorProvider
*
* @since 1.8
*/
public function testConstructor() {
$dataItem = call_user_func_array(
[ $this, 'newInstance' ],
func_get_args()
);
$this->assertInstanceOf( '\SMWDataItem', $dataItem );
$this->assertInstanceOf( $this->getClass(), $dataItem );
}
/**
* @dataProvider instanceProvider
*
* @since 1.8
*
* @param \SMWDataItem $dataItem
*/
public function testSerialization( \SMWDataItem $dataItem ) {
$class = $this->getClass();
$this->assertEquals(
$dataItem,
$class::doUnserialize( $dataItem->getSerialization() )
);
}
/**
* @dataProvider instanceProvider
*/
public function testInstanceEqualsItself( SMWDataItem $di ) {
$this->assertTrue( $di->equals( $di ) );
}
/**
* @dataProvider instanceProvider
*/
public function testInstanceDoesNotEqualNyanData( SMWDataItem $di ) {
$this->assertFalse( $di->equals( new \SMWDIBlob( '~=[,,_,,]:3' ) ) );
}
}
|