Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4106619
PoolCounterTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
PoolCounterTest.php
View Options
<?php
use
MediaWiki\PoolCounter\PoolCounter
;
/**
* @covers \MediaWiki\PoolCounter\PoolCounter
*/
class
PoolCounterTest
extends
MediaWikiUnitTestCase
{
public
function
testConstruct
()
{
$poolCounterConfig
=
[
'class'
=>
'PoolCounterMock'
,
'timeout'
=>
10
,
'workers'
=>
10
,
'maxqueue'
=>
100
,
];
$poolCounter
=
$this
->
getMockBuilder
(
PoolCounterAbstractMock
::
class
)
->
setConstructorArgs
(
[
$poolCounterConfig
,
'testCounter'
,
'someKey'
]
)
->
onlyMethods
(
[]
)
->
getMockForAbstractClass
();
$this
->
assertInstanceOf
(
PoolCounter
::
class
,
$poolCounter
);
}
public
function
testConstructWithSlots
()
{
$poolCounterConfig
=
[
'class'
=>
'PoolCounterMock'
,
'timeout'
=>
10
,
'workers'
=>
10
,
'slots'
=>
2
,
'maxqueue'
=>
100
,
];
$poolCounter
=
$this
->
getMockBuilder
(
PoolCounterAbstractMock
::
class
)
->
setConstructorArgs
(
[
$poolCounterConfig
,
'testCounter'
,
'key'
]
)
->
onlyMethods
(
[]
)
// don't mock anything
->
getMockForAbstractClass
();
$this
->
assertInstanceOf
(
PoolCounter
::
class
,
$poolCounter
);
}
public
function
testHashKeyIntoSlots
()
{
$poolCounter
=
$this
->
createMock
(
PoolCounterAbstractMock
::
class
);
$hashKeyIntoSlots
=
new
ReflectionMethod
(
$poolCounter
,
'hashKeyIntoSlots'
);
$hashKeyIntoSlots
->
setAccessible
(
true
);
$keysWithTwoSlots
=
$keysWithFiveSlots
=
[];
foreach
(
range
(
1
,
100
)
as
$i
)
{
$keysWithTwoSlots
[]
=
$hashKeyIntoSlots
->
invoke
(
$poolCounter
,
'test'
,
'key '
.
$i
,
2
);
$keysWithFiveSlots
[]
=
$hashKeyIntoSlots
->
invoke
(
$poolCounter
,
'test'
,
'key '
.
$i
,
5
);
}
$twoSlotKeys
=
[];
for
(
$i
=
0
;
$i
<=
1
;
$i
++
)
{
$twoSlotKeys
[]
=
"test:$i"
;
}
$fiveSlotKeys
=
[];
for
(
$i
=
0
;
$i
<=
4
;
$i
++
)
{
$fiveSlotKeys
[]
=
"test:$i"
;
}
$this
->
assertArrayEquals
(
$twoSlotKeys
,
array_unique
(
$keysWithTwoSlots
)
);
$this
->
assertArrayEquals
(
$fiveSlotKeys
,
array_unique
(
$keysWithFiveSlots
)
);
// make sure it is deterministic
$this
->
assertEquals
(
$hashKeyIntoSlots
->
invoke
(
$poolCounter
,
'test'
,
'asdfgh'
,
1000
),
$hashKeyIntoSlots
->
invoke
(
$poolCounter
,
'test'
,
'asdfgh'
,
1000
)
);
}
}
// We will use this class with getMockForAbstractClass to create a concrete mock class.
// That call will die if the contructor is not public, unless we use disableOriginalConstructor(),
// in which case we could not test the constructor.
abstract
class
PoolCounterAbstractMock
extends
PoolCounter
{
public
function
__construct
(
...
$args
)
{
parent
::
__construct
(
...
$args
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 19:39 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
1b/30/1ebd4d961a512ebc87ff34665833
Default Alt Text
PoolCounterTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment