Completed
Push — master ( d56754...360c32 )
by
unknown
06:40 queued 10s
created

getTermFallbackCacheFacade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
namespace Wikibase\Lib\Tests\FormatterCache;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\SimpleCache\CacheInterface;
8
use Wikibase\DataModel\Entity\ItemId;
9
use Wikibase\DataModel\Term\TermFallback;
10
use Wikibase\DataModel\Term\TermTypes;
11
use Wikibase\Lib\FormatterCache\TermFallbackCacheFacade;
12
use Wikibase\Lib\FormatterCache\TermFallbackSerializerTrait;
13
14
/**
15
 * @covers \Wikibase\Lib\FormatterCache\TermFallbackCacheFacade
16
 *
17
 * @group Wikibase
18
 *
19
 * @license GPL-2.0-or-later
20
 */
21
class TermFallbackCacheFacadeTest extends TestCase {
22
23
	use TermFallbackSerializerTrait;
24
25
	public const REVISION_ID = 1;
26
	public const CACHE_TTL = 1;
27
28
	/**
29
	 * @var \PHPUnit\Framework\MockObject\MockObject|CacheInterface
30
	 */
31
	private $cache;
32
33
	public function setUp(): void {
34
		parent::setUp();
35
		$this->cache = $this->createMock( CacheInterface::class );
36
	}
37
38
	public function getTermFallbackCacheFacade(): TermFallbackCacheFacade {
39
		return new TermFallbackCacheFacade(
40
			$this->cache,
41
			self::CACHE_TTL
42
		);
43
	}
44
45
	public function testGettingNoValue() {
46
		$facade = $this->getTermFallbackCacheFacade();
47
		$entityId = new ItemId( 'Q1' );
48
49
		$this->cache->expects( $this->once() )
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Psr\SimpleCache\CacheInterface>.

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...
50
			->method( 'get' )
51
			->with( 'Q1_1_en_label' )
52
			->willReturn( TermFallbackCacheFacade::NO_VALUE );
53
54
		$value = $facade->get( $entityId, self::REVISION_ID, 'en', TermTypes::TYPE_LABEL );
55
		$this->assertEquals( $value, TermFallbackCacheFacade::NO_VALUE );
56
	}
57
58
	public function setProvider() {
59
		return [
60
			'TermFallback' => [ new TermFallback( 'en', 'label', 'en', null ) ],
61
			'null' => [ null ],
62
		];
63
	}
64
65
	/**
66
	 * @dataProvider setProvider
67
	 */
68
	public function testSettingCache( $value ) {
69
		$facade = $this->getTermFallbackCacheFacade();
70
		$entityId = new ItemId( 'Q1' );
71
72
		$this->cache->expects( $this->once() )
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Psr\SimpleCache\CacheInterface>.

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...
73
			->method( 'set' )
74
			->with( 'Q1_1_en_label', $this->serialize( $value ), self::CACHE_TTL );
75
76
		$facade->set( $value, $entityId, self::REVISION_ID, 'en', TermTypes::TYPE_LABEL );
77
	}
78
79
	public function testGettingCache() {
80
		$facade = $this->getTermFallbackCacheFacade();
81
		$entityId = new ItemId( 'Q1' );
82
		$value = new TermFallback( 'en', 'label', 'en', null );
83
84
		$this->cache->expects( $this->once() )
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Psr\SimpleCache\CacheInterface>.

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...
85
			->method( 'get' )
86
			->with( 'Q1_1_en_label' )
87
			->willReturn( $this->serialize( $value ) );
88
89
		$actual = $facade->get( $entityId, self::REVISION_ID, 'en', TermTypes::TYPE_LABEL );
90
91
		$this->assertEquals( $value, $actual );
92
	}
93
94
}
95