33namespace Wikibase \DataModel \Tests \Snak ;
44
55use DataValues \StringValue ;
6+ use InvalidArgumentException ;
67use Wikibase \DataModel \Entity \PropertyId ;
78use Wikibase \DataModel \Snak \PropertyNoValueSnak ;
89use Wikibase \DataModel \Snak \PropertyValueSnak ;
2627 * @licence GNU GPL v2+
2728 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
2829 * @author Adam Shorland
30+ * @author Thiemo Mättig
2931 */
3032class SnakListTest extends HashArrayTest {
3133
@@ -70,6 +72,29 @@ public function constructorProvider() {
7072 );
7173 }
7274
75+ /**
76+ * @dataProvider invalidConstructorArgumentsProvider
77+ * @param mixed $input
78+ * @expectedException InvalidArgumentException
79+ */
80+ public function testGivenInvalidConstructorArguments_constructorThrowsException ( $ input ) {
81+ new SnakList ( $ input );
82+ }
83+
84+ public function invalidConstructorArgumentsProvider () {
85+ $ id1 = new PropertyId ( 'P1 ' );
86+
87+ return array (
88+ array ( false ),
89+ array ( 1 ),
90+ array ( 0.1 ),
91+ array ( 'string ' ),
92+ array ( $ id1 ),
93+ array ( new PropertyNoValueSnak ( $ id1 ) ),
94+ array ( new PropertyValueSnak ( $ id1 , new StringValue ( 'a ' ) ) ),
95+ );
96+ }
97+
7398 /**
7499 * @dataProvider instanceProvider
75100 * @param SnakList $array
@@ -223,11 +248,12 @@ public function orderByPropertyProvider() {
223248
224249 $ arguments = array ();
225250
226- foreach ( $ rawArguments as $ rawArgument ) {
227- if ( !array_key_exists ( 2 , $ rawArgument ) ){
228- $ rawArgument [2 ] = array ();
229- }
230- $ arguments [] = array ( new $ class ( $ rawArgument [0 ] ), new $ class ( $ rawArgument [1 ] ), $ rawArgument [2 ] );
251+ foreach ( $ rawArguments as $ rawArgument ) {
252+ $ arguments [] = array (
253+ new $ class ( $ rawArgument [0 ] ),
254+ new $ class ( $ rawArgument [1 ] ),
255+ array_key_exists ( 2 , $ rawArgument ) ? $ rawArgument [2 ] : array ()
256+ );
231257 }
232258
233259 return $ arguments ;
@@ -237,7 +263,7 @@ public function orderByPropertyProvider() {
237263 * @dataProvider orderByPropertyProvider
238264 * @param SnakList $snakList
239265 * @param SnakList $expected
240- * @param array $order
266+ * @param string[] $order
241267 */
242268 public function testOrderByProperty ( SnakList $ snakList , SnakList $ expected , $ order = array () ) {
243269 $ initialSnakList = new SnakList ( array_values ( iterator_to_array ( $ snakList ) ) );
@@ -250,7 +276,7 @@ public function testOrderByProperty( SnakList $snakList, SnakList $expected, $or
250276
251277 $ this ->assertEquals ( $ expected , $ orderedSnakList );
252278
253- if ( $ orderedSnakList ->equals ( $ initialSnakList ) ) {
279+ if ( $ orderedSnakList ->equals ( $ initialSnakList ) ) {
254280 $ this ->assertTrue ( $ initialSnakList ->getHash () === $ snakList ->getHash () );
255281 } else {
256282 $ this ->assertFalse ( $ initialSnakList ->getHash () === $ snakList ->getHash () );
0 commit comments