TypedObjectDeserializerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenDefaultObjectKey_isDeserializerForReturnsTrue() 0 4 1
A newMockDeserializer() 0 9 1
A newStubSerializationWithTypeKey() 0 3 1
A testGivenUnknownObjectKey_isDeserializerForReturnsFalse() 0 4 1
A testGivenSpecifiedObjectKey_isDeserializerForReturnsTrue() 0 7 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