MediaWiki REL1_32
PoolCounterTest.php
Go to the documentation of this file.
1<?php
2
3// We will use this class with getMockForAbstractClass to create a concrete mock class.
4// That call will die if the contructor is not public, unless we use disableOriginalConstructor(),
5// in which case we could not test the constructor.
6abstract class PoolCounterAbstractMock extends PoolCounter {
7 public function __construct() {
8 call_user_func_array( 'parent::__construct', func_get_args() );
9 }
10}
11
16 public function testConstruct() {
17 $poolCounterConfig = [
18 'class' => 'PoolCounterMock',
19 'timeout' => 10,
20 'workers' => 10,
21 'maxqueue' => 100,
22 ];
23
24 $poolCounter = $this->getMockBuilder( PoolCounterAbstractMock::class )
25 ->setConstructorArgs( [ $poolCounterConfig, 'testCounter', 'someKey' ] )
26 // don't mock anything - the proper syntax would be setMethods(null), but due
27 // to a PHPUnit bug that does not work with getMockForAbstractClass()
28 ->setMethods( [ 'idontexist' ] )
29 ->getMockForAbstractClass();
30 $this->assertInstanceOf( PoolCounter::class, $poolCounter );
31 }
32
33 public function testConstructWithSlots() {
34 $poolCounterConfig = [
35 'class' => 'PoolCounterMock',
36 'timeout' => 10,
37 'workers' => 10,
38 'slots' => 2,
39 'maxqueue' => 100,
40 ];
41
42 $poolCounter = $this->getMockBuilder( PoolCounterAbstractMock::class )
43 ->setConstructorArgs( [ $poolCounterConfig, 'testCounter', 'key' ] )
44 ->setMethods( [ 'idontexist' ] ) // don't mock anything
45 ->getMockForAbstractClass();
46 $this->assertInstanceOf( PoolCounter::class, $poolCounter );
47 }
48
49 public function testHashKeyIntoSlots() {
50 $poolCounter = $this->getMockBuilder( PoolCounterAbstractMock::class )
51 // don't mock anything - the proper syntax would be setMethods(null), but due
52 // to a PHPUnit bug that does not work with getMockForAbstractClass()
53 ->setMethods( [ 'idontexist' ] )
54 ->disableOriginalConstructor()
55 ->getMockForAbstractClass();
56
57 $hashKeyIntoSlots = new ReflectionMethod( $poolCounter, 'hashKeyIntoSlots' );
58 $hashKeyIntoSlots->setAccessible( true );
59
60 $keysWithTwoSlots = $keysWithFiveSlots = [];
61 foreach ( range( 1, 100 ) as $i ) {
62 $keysWithTwoSlots[] = $hashKeyIntoSlots->invoke( $poolCounter, 'test', 'key ' . $i, 2 );
63 $keysWithFiveSlots[] = $hashKeyIntoSlots->invoke( $poolCounter, 'test', 'key ' . $i, 5 );
64 }
65
66 $twoSlotKeys = [];
67 for ( $i = 0; $i <= 1; $i++ ) {
68 $twoSlotKeys[] = "test:$i";
69 }
70 $fiveSlotKeys = [];
71 for ( $i = 0; $i <= 4; $i++ ) {
72 $fiveSlotKeys[] = "test:$i";
73 }
74
75 $this->assertArrayEquals( $twoSlotKeys, array_unique( $keysWithTwoSlots ) );
76 $this->assertArrayEquals( $fiveSlotKeys, array_unique( $keysWithFiveSlots ) );
77
78 // make sure it is deterministic
79 $this->assertEquals(
80 $hashKeyIntoSlots->invoke( $poolCounter, 'test', 'asdfgh', 1000 ),
81 $hashKeyIntoSlots->invoke( $poolCounter, 'test', 'asdfgh', 1000 )
82 );
83 }
84}
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
When you have many workers (threads/servers) giving service, and a cached item expensive to produce e...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37