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 ) {
224 $fooId = $store->acquireId(
'foo' );
225 $this->assertSame(
'foo', $store->getName( $fooId ) );
228 $barId = $store->acquireId(
'bar' );
229 $this->assertSame(
'bar', $store->getName( $barId ) );
232 TestingAccessWrapper::newFromObject( $store )->tableCache =
null;
233 $this->assertSame(
'foo', $store->getName( $fooId ) );
234 $this->assertSame(
'bar', $store->getName( $barId ) );
237 TestingAccessWrapper::newFromObject( $store )->tableCache =
null;
238 $bazId = $store->acquireId(
'baz' );
239 $this->assertSame(
'baz', $store->getName( $bazId ) );
240 $this->assertSame(
'baz', $store->getName( $bazId ) );
247 $fooId = $store->acquireId(
'foo' );
250 TestingAccessWrapper::newFromObject( $store )->tableCache = [];
253 $this->assertSame(
'foo', $store->getName( $fooId ) );
259 $table = $store->getMap();
260 $this->assertSame( [], $table );
269 $table = $store->getMap();
271 $expected = [ 1 =>
'foo', 2 =>
'bar' ];
272 $this->assertSame( $expected, $table );
274 $this->assertSame( $expected, TestingAccessWrapper::newFromObject( $store )->tableCache );
282 $this->assertCount( 1, $store->getMap() );
287 $expected = [ 1 =>
'foo', 2 =>
'bar' ];
288 $this->assertSame( $expected, $store->reloadMap() );
289 $this->assertSame( $expected, $store->getMap() );
305 $fooId = $store1->acquireId(
'foo' );
306 $barId = $store2->acquireId(
'bar' );
309 $this->assertSame( $fooId, $store1->acquireId(
'foo' ) );
310 $this->assertSame( $barId, $store2->acquireId(
'bar' ) );
316 $this->assertSame( $fooId, $store4->getId(
'foo' ) );
317 $this->assertSame( $barId, $store4->getId(
'bar' ) );
320 $this->assertSame( $fooId, $store3->acquireId(
'foo' ) );
321 $this->assertSame( $barId, $store3->acquireId(
'bar' ) );
333 function ( $insertFields ) {
334 $insertFields[
'role_id'] = 7251;
335 return $insertFields;
338 $this->assertSame( 7251, $store->acquireId(
'A' ) );