7use PHPUnit_Framework_MockObject_MockObject;
21 return $this->getMockBuilder( IDatabase::class )
29 $lb = $this->getMockBuilder( LoadBalancer::class )
30 ->disableOriginalConstructor()
40 $lb->expects( $this->once() )
41 ->method(
'getConnection' )
42 ->with(
DB_REPLICA, [
'group1' ],
'someDbName' )
43 ->will( $this->returnValue( $database ) );
46 $actual = $manager->getReadConnection();
48 $this->assertSame( $database, $actual );
55 $lb->expects( $this->once() )
56 ->method(
'getConnection' )
57 ->with(
DB_REPLICA, [
'group2' ],
'someDbName' )
58 ->will( $this->returnValue( $database ) );
61 $actual = $manager->getReadConnection( [
'group2' ] );
63 $this->assertSame( $database, $actual );
70 $lb->expects( $this->once() )
71 ->method(
'getConnection' )
72 ->with(
DB_MASTER, [
'group1' ],
'someDbName' )
73 ->will( $this->returnValue( $database ) );
76 $actual = $manager->getWriteConnection();
78 $this->assertSame( $database, $actual );
85 $lb->expects( $this->once() )
86 ->method(
'reuseConnection' )
88 ->will( $this->returnValue(
null ) );
91 $manager->releaseConnection( $database );
98 $lb->expects( $this->once() )
99 ->method(
'getConnectionRef' )
100 ->with(
DB_REPLICA, [
'group1' ],
'someDbName' )
101 ->will( $this->returnValue( $database ) );
104 $actual = $manager->getReadConnectionRef();
106 $this->assertSame( $database, $actual );
113 $lb->expects( $this->once() )
114 ->method(
'getConnectionRef' )
115 ->with(
DB_REPLICA, [
'group2' ],
'someDbName' )
116 ->will( $this->returnValue( $database ) );
119 $actual = $manager->getReadConnectionRef( [
'group2' ] );
121 $this->assertSame( $database, $actual );
128 $lb->expects( $this->once() )
129 ->method(
'getConnectionRef' )
130 ->with(
DB_MASTER, [
'group1' ],
'someDbName' )
131 ->will( $this->returnValue( $database ) );
134 $actual = $manager->getWriteConnectionRef();
136 $this->assertSame( $database, $actual );