newStubSerializationWithTypeKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Deserializers\Tests\Phpunit\Deserializers;
4
5
use Deserializers\TypedObjectDeserializer;
6
7
/**
8
 * @covers Deserializers\TypedObjectDeserializer
9
 *
10
 * @license GPL-2.0-or-later
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class TypedObjectDeserializerTest extends \PHPUnit\Framework\TestCase {
14
15
	private const DEFAULT_TYPE_KEY = 'objectType';
16
	private const DUMMY_TYPE_VALUE = 'someType';
17
18
	public function testGivenDefaultObjectKey_isDeserializerForReturnsTrue() {
19
		$serialization = $this->newStubSerializationWithTypeKey( self::DEFAULT_TYPE_KEY );
20
		$this->assertTrue( $this->newMockDeserializer()->isDeserializerFor( $serialization ) );
0 ignored issues
show
Bug introduced by
The method isDeserializerFor() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
	}
22
23
	/**
24
	 * @param string $typeKey
25
	 * @return TypedObjectDeserializer
26
	 */
27
	private function newMockDeserializer( $typeKey = self::DEFAULT_TYPE_KEY ) {
28
		return $this->getMockForAbstractClass(
29
			TypedObjectDeserializer::class,
30
			[
31
				self::DUMMY_TYPE_VALUE,
32
				$typeKey
33
			]
34
		);
35
	}
36
37
	private function newStubSerializationWithTypeKey( $typeKey ) {
38
		return [ $typeKey => self::DUMMY_TYPE_VALUE ];
39
	}
40
41
	public function testGivenUnknownObjectKey_isDeserializerForReturnsFalse() {
42
		$serialization = $this->newStubSerializationWithTypeKey( 'someNonsenseTypeKey' );
43
		$this->assertFalse( $this->newMockDeserializer()->isDeserializerFor( $serialization ) );
0 ignored issues
show
Bug introduced by
The method isDeserializerFor() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
	}
45
46
	public function testGivenSpecifiedObjectKey_isDeserializerForReturnsTrue() {
47
		$specifiedTypeKey = 'myAwesomeTypeKey';
48
49
		$serialization = $this->newStubSerializationWithTypeKey( $specifiedTypeKey );
50
		$deserializer = $this->newMockDeserializer( $specifiedTypeKey );
51
		$this->assertTrue( $deserializer->isDeserializerFor( $serialization ) );
0 ignored issues
show
Bug introduced by
The method isDeserializerFor() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
	}
53
54
}
55