11 use Psr\Log\NullLogger;
15 use Wikimedia\TestingAccessWrapper;
25 $this->tablesUsed[] =
'slot_roles';
36 $insertValues[] = [
'role_name' =>
$name ];
38 $this->db->insert(
'slot_roles', $insertValues );
51 ->disableOriginalConstructor()
53 $mock->expects( $this->
any() )
54 ->method(
'getConnection' )
61 ->disableOriginalConstructor()
63 $mock->expects( $this->exactly( $insertCalls ) )
65 ->willReturnCallback(
function () {
66 return call_user_func_array( [ $this->db,
'insert' ], func_get_args() );
68 $mock->expects( $this->exactly( $selectCalls ) )
70 ->willReturnCallback(
function () {
71 return call_user_func_array( [ $this->db,
'select' ], func_get_args() );
73 $mock->expects( $this->exactly( $insertCalls ) )
74 ->method(
'affectedRows' )
75 ->willReturnCallback(
function () {
76 return call_user_func_array( [ $this->db,
'affectedRows' ], func_get_args() );
78 $mock->expects( $this->
any() )
79 ->method(
'insertId' )
80 ->willReturnCallback(
function () {
81 return call_user_func_array( [ $this->db,
'insertId' ], func_get_args() );
90 $normalizationCallback =
null,
91 $insertCallback =
null
97 'slot_roles',
'role_id',
'role_name',
98 $normalizationCallback,
106 'no wancache, empty table' =>
108 'no wancache, one matching value' =>
110 'no wancache, one not matching value' =>
112 'no wancache, multiple, one matching value' =>
114 'no wancache, multiple, no matching value' =>
116 'wancache, empty table' =>
118 'wancache, one matching value' =>
120 'wancache, one not matching value' =>
122 'wancache, multiple, one matching value' =>
123 [
new HashBagOStuff(),
false, 1, [
'foo',
'bar' ],
'bar', 2 ],
124 'wancache, multiple, no matching value' =>
125 [
new HashBagOStuff(),
true, 1, [
'foo',
'bar' ],
'baz', 3 ],
155 $this->assertSame( $expectedId,
$result );
157 if ( $needsInsert ) {
158 $this->assertTrue(
true );
160 $this->fail(
'Did not expect an exception, but got one: ' .
$e->getMessage() );
165 $this->assertSame( $expectedId, $store->acquireId(
$name ) );
168 $this->assertSame( $expectedId, $store->getId(
$name ) );
171 $this->assertSame( $expectedId, $store->getId(
$name ) );
175 yield [
'A',
'a',
'strtolower' ];
176 yield [
'b',
'B',
'strtoupper' ];
184 yield [
'ZZ',
'ZZ-a', __CLASS__ .
'::appendDashAToString' ];
188 return $string .
'-a';
197 $normalizationCallback
203 $normalizationCallback
205 $acquiredId = $store->acquireId( $nameIn );
206 $this->assertSame( $nameOut, $store->getName( $acquiredId ) );
219 public function testGetName( $cacheBag, $insertCalls, $selectCalls ) {
223 $fooId = $store->acquireId(
'foo' );
224 $this->assertSame(
'foo', $store->getName( $fooId ) );
227 $barId = $store->acquireId(
'bar' );
228 $this->assertSame(
'bar', $store->getName( $barId ) );
231 TestingAccessWrapper::newFromObject( $store )->tableCache =
null;
232 $this->assertSame(
'foo', $store->getName( $fooId ) );
233 $this->assertSame(
'bar', $store->getName( $barId ) );
236 TestingAccessWrapper::newFromObject( $store )->tableCache =
null;
237 $bazId = $store->acquireId(
'baz' );
238 $this->assertSame(
'baz', $store->getName( $bazId ) );
239 $this->assertSame(
'baz', $store->getName( $bazId ) );
246 $fooId = $store->acquireId(
'foo' );
249 TestingAccessWrapper::newFromObject( $store )->tableCache = [];
252 $this->assertSame(
'foo', $store->getName( $fooId ) );
258 $table = $store->getMap();
259 $this->assertSame( [], $table );
268 $table = $store->getMap();
270 $expected = [ 1 =>
'foo', 2 =>
'bar' ];
271 $this->assertSame( $expected, $table );
273 $this->assertSame( $expected, TestingAccessWrapper::newFromObject( $store )->tableCache );
281 $this->assertCount( 1, $store->getMap() );
286 $expected = [ 1 =>
'foo', 2 =>
'bar' ];
287 $this->assertSame( $expected, $store->reloadMap() );
288 $this->assertSame( $expected, $store->getMap() );
304 $fooId = $store1->acquireId(
'foo' );
305 $barId = $store2->acquireId(
'bar' );
308 $this->assertSame( $fooId, $store1->acquireId(
'foo' ) );
309 $this->assertSame( $barId, $store2->acquireId(
'bar' ) );
315 $this->assertSame( $fooId, $store4->getId(
'foo' ) );
316 $this->assertSame( $barId, $store4->getId(
'bar' ) );
319 $this->assertSame( $fooId, $store3->acquireId(
'foo' ) );
320 $this->assertSame( $barId, $store3->acquireId(
'bar' ) );
332 function ( $insertFields ) {
333 $insertFields[
'role_id'] = 7251;
334 return $insertFields;
337 $this->assertSame( 7251, $store->acquireId(
'A' ) );