X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fpoolcounter%2FPoolCounterTest.php;h=6caf3e545071b0a005bbe60f49638c485efb0626;hp=019e532c930f9f88af31744a28ba690e1abafffa;hb=0c77841534d9139b0042696fe015a15d3e349ef5;hpb=d78b4eeff8cdf47ba6f5da1257c4a6e9de688316 diff --git a/tests/phpunit/includes/poolcounter/PoolCounterTest.php b/tests/phpunit/includes/poolcounter/PoolCounterTest.php index 019e532c93..6caf3e5450 100644 --- a/tests/phpunit/includes/poolcounter/PoolCounterTest.php +++ b/tests/phpunit/includes/poolcounter/PoolCounterTest.php @@ -9,36 +9,39 @@ abstract class PoolCounterAbstractMock extends PoolCounter { } } +/** + * @covers PoolCounter + */ class PoolCounterTest extends MediaWikiTestCase { public function testConstruct() { - $poolCounterConfig = array( + $poolCounterConfig = [ 'class' => 'PoolCounterMock', 'timeout' => 10, 'workers' => 10, 'maxqueue' => 100, - ); + ]; $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' ) - ->setConstructorArgs( array( $poolCounterConfig, 'testCounter', 'someKey' ) ) + ->setConstructorArgs( [ $poolCounterConfig, 'testCounter', 'someKey' ] ) // don't mock anything - the proper syntax would be setMethods(null), but due // to a PHPUnit bug that does not work with getMockForAbstractClass() - ->setMethods( array( 'idontexist' ) ) + ->setMethods( [ 'idontexist' ] ) ->getMockForAbstractClass(); $this->assertInstanceOf( 'PoolCounter', $poolCounter ); } public function testConstructWithSlots() { - $poolCounterConfig = array( + $poolCounterConfig = [ 'class' => 'PoolCounterMock', 'timeout' => 10, 'workers' => 10, 'slots' => 2, 'maxqueue' => 100, - ); + ]; $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' ) - ->setConstructorArgs( array( $poolCounterConfig, 'testCounter', 'key' ) ) - ->setMethods( array( 'idontexist' ) ) // don't mock anything + ->setConstructorArgs( [ $poolCounterConfig, 'testCounter', 'key' ] ) + ->setMethods( [ 'idontexist' ] ) // don't mock anything ->getMockForAbstractClass(); $this->assertInstanceOf( 'PoolCounter', $poolCounter ); } @@ -47,26 +50,35 @@ class PoolCounterTest extends MediaWikiTestCase { $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' ) // don't mock anything - the proper syntax would be setMethods(null), but due // to a PHPUnit bug that does not work with getMockForAbstractClass() - ->setMethods( array( 'idontexist' ) ) + ->setMethods( [ 'idontexist' ] ) ->disableOriginalConstructor() ->getMockForAbstractClass(); $hashKeyIntoSlots = new ReflectionMethod( $poolCounter, 'hashKeyIntoSlots' ); $hashKeyIntoSlots->setAccessible( true ); - $keysWithTwoSlots = $keysWithFiveSlots = array(); + $keysWithTwoSlots = $keysWithFiveSlots = []; foreach ( range( 1, 100 ) as $i ) { - $keysWithTwoSlots[] = $hashKeyIntoSlots->invoke( $poolCounter, 'key ' . $i, 2 ); - $keysWithFiveSlots[] = $hashKeyIntoSlots->invoke( $poolCounter, 'key ' . $i, 5 ); + $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( range( 0, 1 ), array_unique( $keysWithTwoSlots ) ); - $this->assertArrayEquals( range( 0, 4 ), array_unique( $keysWithFiveSlots ) ); + $this->assertArrayEquals( $twoSlotKeys, array_unique( $keysWithTwoSlots ) ); + $this->assertArrayEquals( $fiveSlotKeys, array_unique( $keysWithFiveSlots ) ); // make sure it is deterministic $this->assertEquals( - $hashKeyIntoSlots->invoke( $poolCounter, 'asdfgh', 1000 ), - $hashKeyIntoSlots->invoke( $poolCounter, 'asdfgh', 1000 ) + $hashKeyIntoSlots->invoke( $poolCounter, 'test', 'asdfgh', 1000 ), + $hashKeyIntoSlots->invoke( $poolCounter, 'test', 'asdfgh', 1000 ) ); } }