aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/objectcache/ObjectCacheFactoryTest.php
blob: ebbadce1bf4820deae021d80aabff40e28f2b44c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

use MediaWiki\Config\ServiceOptions;
use MediaWiki\Logger\NullSpi;
use Wikimedia\ObjectCache\HashBagOStuff;
use Wikimedia\Stats\StatsFactory;
use Wikimedia\Telemetry\NoopTracer;

/**
 * @covers \ObjectCacheFactory
 */
class ObjectCacheFactoryTest extends MediaWikiUnitTestCase {
	private function newObjectCacheFactory() {
		return new ObjectCacheFactory(
			$this->createMock( ServiceOptions::class ),
			StatsFactory::newNull(),
			new NullSpi(),
			static function () {
			},
			'testWikiId',
			new NoopTracer()
		);
	}

	public function testNewObjectCacheFactory() {
		$this->assertInstanceOf(
			ObjectCacheFactory::class,
			$this->newObjectCacheFactory()
		);
	}

	public function testNewFromParams() {
		$factory = $this->newObjectCacheFactory();

		$objCache = $factory->newFromParams( [
			'class' => HashBagOStuff::class,
			'args' => [ 'foo', 'bar' ],
		] );

		$this->assertInstanceOf( HashBagOStuff::class, $objCache );
	}

	public function testShouldPassTracer(): void {
		$factory = $this->newObjectCacheFactory();

		$cache = $factory->newFromParams( [
			'factory' => function ( array $params ): HashBagOStuff {
				$this->assertInstanceOf( NoopTracer::class, $params['telemetry'] );
				return new HashBagOStuff();
			}
		] );

		$this->assertInstanceOf( HashBagOStuff::class, $cache );
	}
}