Completed
Push — master ( 910d18...e35b88 )
by Jeroen De
06:07 queued 03:25
created

tests/unit/Serializers/TermSerializerTest.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Tests\Wikibase\DataModel\Serializers;
4
5
use Wikibase\DataModel\Serializers\TermSerializer;
6
use Wikibase\DataModel\Term\Term;
7
use Wikibase\DataModel\Term\TermFallback;
8
9
/**
10
 * @covers Wikibase\DataModel\Serializers\TermSerializer
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Addshore
14
 */
15
class TermSerializerTest extends \PHPUnit_Framework_TestCase {
16
17
	/**
18
	 * @dataProvider serializationProvider
19
	 */
20
	public function testSerialization( Term $input, array $expected ) {
21
		$serializer = new TermSerializer();
22
23
		$output = $serializer->serialize( $input );
24
25
		$this->assertEquals( $expected, $output );
26
	}
27
28
	public function serializationProvider() {
29
		return array(
30
			array(
31
				new Term ( 'en', 'SomeValue' ),
32
				array(
33
					'language' => 'en',
34
					'value' => 'SomeValue',
35
				)
36
			),
37
			array(
38
				new TermFallback( 'en', 'SomeValue', 'en-gb', 'en' ),
39
				array(
40
					'language' => 'en-gb',
41
					'value' => 'SomeValue',
42
					'source' => 'en',
43
				)
44
			),
45
		);
46
	}
47
48
	public function testWithUnsupportedObject() {
49
		$serializer = new TermSerializer();
50
		$this->setExpectedException( 'Serializers\Exceptions\UnsupportedObjectException' );
51
		$serializer->serialize( new \stdClass() );
0 ignored issues
show
new \stdClass() is of type object<stdClass>, but the function expects a object<Wikibase\DataModel\Term\Term>.

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...
52
	}
53
54
}
55