Completed
Push — master ( a9f673...d16089 )
by Jeroen De
02:36
created

InProcessCachingDataTypeLookupTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testWhenCacheIsEmpty_decoratedLookupValueIsReturned() 0 15 1
A testWhenValueInCache_cacheValueIsReturned() 0 18 1
1
<?php
2
3
namespace Wikibase\DataModel\Services\Tests\Lookup;
4
5
use PHPUnit_Framework_TestCase;
6
use Wikibase\DataModel\Entity\PropertyId;
7
use Wikibase\DataModel\Services\Lookup\InProcessCachingDataTypeLookup;
8
9
/**
10
 * @covers Wikibase\DataModel\Services\Lookup\InProcessCachingDataTypeLookup
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Katie Filbert < [email protected] >
14
 */
15
class InProcessCachingDataTypeLookupTest extends PHPUnit_Framework_TestCase {
16
17
	public function testWhenCacheIsEmpty_decoratedLookupValueIsReturned() {
18
		$decoratedLookup = $this->getMock( 'Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup' );
19
20
		$decoratedLookup->expects( $this->once() )
21
			->method( 'getDataTypeIdForProperty' )
22
			->with( new PropertyId( 'P1' ) )
23
			->will( $this->returnValue( 'string' ) );
24
25
		$cachingLookup = new InProcessCachingDataTypeLookup( $decoratedLookup );
26
27
		$this->assertSame(
28
			'string',
29
			$cachingLookup->getDataTypeIdForProperty( new PropertyId( 'P1' ) )
30
		);
31
	}
32
33
	public function testWhenValueInCache_cacheValueIsReturned() {
34
		$decoratedLookup = $this->getMock( 'Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup' );
35
36
		$decoratedLookup->expects( $this->once() )
37
			->method( 'getDataTypeIdForProperty' )
38
			->will( $this->returnValue( 'string' ) );
39
40
		$cachingLookup = new InProcessCachingDataTypeLookup( $decoratedLookup );
41
		$cachingLookup->getDataTypeIdForProperty( new PropertyId( 'P1' ) );
42
43
		$decoratedLookup->expects( $this->never() )
44
			->method( 'getDataTypeIdForProperty' );
45
46
		$this->assertSame(
47
			'string',
48
			$cachingLookup->getDataTypeIdForProperty( new PropertyId( 'P1' ) )
49
		);
50
	}
51
52
}
53