Merge "Vector: Label the more actions menu "More", not "Actions""
[lhc/web/wiklou.git] / tests / phpunit / includes / poolcounter / PoolCounterTest.php
1 <?php
2
3 // We will use this class with getMockForAbstractClass to create a concrete mock class. That call will die if the
4 // contructor is not public, unless we use disableOriginalConstructor(), in which case we could not test the constructor.
5 abstract class PoolCounterAbstractMock extends PoolCounter {
6 public function __construct() {
7 call_user_func_array( 'parent::__construct', func_get_args() );
8 }
9 }
10
11 class PoolCounterTest extends MediaWikiTestCase {
12 public function testConstruct() {
13 $poolCounterConfig = array(
14 'class' => 'PoolCounterMock',
15 'timeout' => 10,
16 'workers' => 10,
17 'maxqueue' => 100,
18 );
19
20 $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' )
21 ->setConstructorArgs( array( $poolCounterConfig, 'testCounter', 'someKey' ) )
22 // don't mock anything - the proper syntax would be setMethods(null), but due to a PHPUnit bug that
23 // does not work with getMockForAbstractClass()
24 ->setMethods( array( 'idontexist' ) )
25 ->getMockForAbstractClass();
26 $this->assertInstanceOf( 'PoolCounter', $poolCounter );
27 }
28
29 public function testConstructWithSlots() {
30 $poolCounterConfig = array(
31 'class' => 'PoolCounterMock',
32 'timeout' => 10,
33 'workers' => 10,
34 'slots' => 2,
35 'maxqueue' => 100,
36 );
37
38 $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' )
39 ->setConstructorArgs( array( $poolCounterConfig, 'testCounter', 'key' ) )
40 ->setMethods( array( 'idontexist' ) ) // don't mock anything
41 ->getMockForAbstractClass();
42 $this->assertInstanceOf( 'PoolCounter', $poolCounter );
43 }
44
45 public function testHashKeyIntoSlots() {
46 $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' )
47 // don't mock anything - the proper syntax would be setMethods(null), but due to a PHPUnit bug that
48 // does not work with getMockForAbstractClass()
49 ->setMethods( array( 'idontexist' ) )
50 ->disableOriginalConstructor()
51 ->getMockForAbstractClass();
52
53 $hashKeyIntoSlots = new ReflectionMethod($poolCounter, 'hashKeyIntoSlots' );
54 $hashKeyIntoSlots->setAccessible( true );
55
56
57 $keysWithTwoSlots = $keysWithFiveSlots = array();
58 foreach ( range( 1, 100 ) as $i ) {
59 $keysWithTwoSlots[] = $hashKeyIntoSlots->invoke( $poolCounter, 'key ' . $i, 2 );
60 $keysWithFiveSlots[] = $hashKeyIntoSlots->invoke( $poolCounter, 'key ' . $i, 5 );
61 }
62
63 $this->assertArrayEquals( range( 0, 1 ), array_unique( $keysWithTwoSlots ) );
64 $this->assertArrayEquals( range( 0, 4 ), array_unique( $keysWithFiveSlots ) );
65
66 // make sure it is deterministic
67 $this->assertEquals(
68 $hashKeyIntoSlots->invoke( $poolCounter, 'asdfgh', 1000 ),
69 $hashKeyIntoSlots->invoke( $poolCounter, 'asdfgh', 1000 )
70 );
71 }
72 }