11use Psr\Log\NullLogger;
15use Wikimedia\TestingAccessWrapper;
25 $this->tablesUsed[] =
'slot_roles';
31 foreach ( $values as $name ) {
32 $insertValues[] = [
'role_name' =>
$name ];
34 $this->db->insert(
'slot_roles', $insertValues );
46 $mock = $this->getMockBuilder( LoadBalancer::class )
47 ->disableOriginalConstructor()
49 $mock->expects( $this->
any() )
50 ->method(
'getConnection' )
56 $mock = $this->getMockBuilder( Database::class )
57 ->disableOriginalConstructor()
59 $mock->expects( $this->exactly( $insertCalls ) )
61 ->willReturnCallback(
function () {
62 return call_user_func_array( [ $this->db,
'insert' ], func_get_args() );
64 $mock->expects( $this->exactly( $selectCalls ) )
66 ->willReturnCallback(
function () {
67 return call_user_func_array( [ $this->db,
'select' ], func_get_args() );
69 $mock->expects( $this->exactly( $insertCalls ) )
70 ->method(
'affectedRows' )
71 ->willReturnCallback(
function () {
72 return call_user_func_array( [ $this->db,
'affectedRows' ], func_get_args() );
74 $mock->expects( $this->
any() )
75 ->method(
'insertId' )
76 ->willReturnCallback(
function () {
77 return call_user_func_array( [ $this->db,
'insertId' ], func_get_args() );
86 $normalizationCallback =
null
92 'slot_roles',
'role_id',
'role_name',
93 $normalizationCallback
99 'no wancache, empty table' =>
101 'no wancache, one matching value' =>
103 'no wancache, one not matching value' =>
105 'no wancache, multiple, one matching value' =>
107 'no wancache, multiple, no matching value' =>
109 'wancache, empty table' =>
111 'wancache, one matching value' =>
113 'wancache, one not matching value' =>
115 'wancache, multiple, one matching value' =>
116 [
new HashBagOStuff(),
false, 1, [
'foo',
'bar' ],
'bar', 2 ],
117 'wancache, multiple, no matching value' =>
118 [
new HashBagOStuff(),
true, 1, [
'foo',
'bar' ],
'baz', 3 ],
144 $result = $store->getId( $name );
145 $this->assertSame( $expectedId, $result );
147 if ( $needsInsert ) {
148 $this->assertTrue(
true );
150 $this->fail(
'Did not expect an exception, but got one: ' .
$e->getMessage() );
155 $this->assertSame( $expectedId, $store->acquireId( $name ) );
158 $this->assertSame( $expectedId, $store->getId( $name ) );
161 $this->assertSame( $expectedId, $store->getId( $name ) );
165 yield [
'A',
'a',
'strtolower' ];
166 yield [
'b',
'B',
'strtoupper' ];
174 yield [
'ZZ',
'ZZ-a', __CLASS__ .
'::appendDashAToString' ];
178 return $string .
'-a';
187 $normalizationCallback
190 new EmptyBagOStuff(),
193 $normalizationCallback
195 $acquiredId = $store->acquireId( $nameIn );
196 $this->assertSame( $nameOut, $store->getName( $acquiredId ) );
209 public function testGetName( $cacheBag, $insertCalls, $selectCalls ) {
213 $fooId = $store->acquireId(
'foo' );
214 $this->assertSame(
'foo', $store->getName( $fooId ) );
217 $barId = $store->acquireId(
'bar' );
218 $this->assertSame(
'bar', $store->getName( $barId ) );
221 TestingAccessWrapper::newFromObject( $store )->tableCache =
null;
222 $this->assertSame(
'foo', $store->getName( $fooId ) );
223 $this->assertSame(
'bar', $store->getName( $barId ) );
226 TestingAccessWrapper::newFromObject( $store )->tableCache =
null;
227 $bazId = $store->acquireId(
'baz' );
228 $this->assertSame(
'baz', $store->getName( $bazId ) );
229 $this->assertSame(
'baz', $store->getName( $bazId ) );
236 $fooId = $store->acquireId(
'foo' );
239 TestingAccessWrapper::newFromObject( $store )->tableCache = [];
242 $this->assertSame(
'foo', $store->getName( $fooId ) );
248 $table = $store->getMap();
249 $this->assertSame( [], $table );
258 $table = $store->getMap();
260 $expected = [ 1 =>
'foo', 2 =>
'bar' ];
261 $this->assertSame( $expected, $table );
263 $this->assertSame( $expected, TestingAccessWrapper::newFromObject( $store )->tableCache );
279 $fooId = $store1->acquireId(
'foo' );
280 $barId = $store2->acquireId(
'bar' );
283 $this->assertSame( $fooId, $store1->acquireId(
'foo' ) );
284 $this->assertSame( $barId, $store2->acquireId(
'bar' ) );
290 $this->assertSame( $fooId, $store4->getId(
'foo' ) );
291 $this->assertSame( $barId, $store4->getId(
'bar' ) );
294 $this->assertSame( $fooId, $store3->acquireId(
'foo' ) );
295 $this->assertSame( $barId, $store3->acquireId(
'bar' ) );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
interface is intended to be more or less compatible with the PHP memcached client.
A BagOStuff object with no objects in it.
Simple store for keeping values in an associative array for the current process.
Multi-datacenter aware caching interface.
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e