*/
class DBConnRefTest extends PHPUnit\Framework\TestCase {
+ use MediaWikiCoversValidator;
use PHPUnit4And6Compat;
/**
->disableOriginalConstructor()
->getMock();
- $db->method( 'select' )->willReturn( new FakeResultWrapper( [] ) );
+ $open = true;
+ $db->method( 'select' )->willReturnCallback( function () use ( &$open ) {
+ if ( !$open ) {
+ throw new LogicException( "Not open" );
+ }
+
+ return new FakeResultWrapper( [] );
+ } );
+ $db->method( 'close' )->willReturnCallback( function () use ( &$open ) {
+ $open = false;
+
+ return true;
+ } );
+ $db->method( 'isOpen' )->willReturnCallback( function () use ( &$open ) {
+ return $open;
+ } );
+ $db->method( 'open' )->willReturnCallback( function () use ( &$open ) {
+ $open = true;
+
+ return $open;
+ } );
$db->method( '__toString' )->willReturn( 'MOCK_DB' );
return $db;
new DBConnRef( $lb, 17 ); // bad constructor argument
}
- public function testGetWikiID() {
- $lb = $this->getMock( ILoadBalancer::class );
-
- // getWikiID is optimized to not create a connection
- $lb->expects( $this->never() )
- ->method( 'getConnection' );
-
- $ref = new DBConnRef( $lb, [ DB_REPLICA, [], 'dummy', 0 ] );
-
- $this->assertSame( 'dummy', $ref->getWikiID() );
- }
-
+ /**
+ * @covers Wikimedia\Rdbms\DBConnRef::getDomainId
+ */
public function testGetDomainID() {
$lb = $this->getMock( ILoadBalancer::class );
$this->assertSame( 'dummy', $ref->getDomainID() );
}
+ /**
+ * @covers Wikimedia\Rdbms\DBConnRef::select
+ */
public function testSelect() {
// select should get passed through normally
$ref = $this->getDBConnRef();
$this->assertInternalType( 'string', $ref->__toString() );
}
+ /**
+ * @covers Wikimedia\Rdbms\DBConnRef::close
+ * @expectedException \Wikimedia\Rdbms\DBUnexpectedError
+ */
+ public function testClose() {
+ $lb = $this->getLoadBalancerMock();
+ $ref = new DBConnRef( $lb, [ DB_REPLICA, [], 'dummy', 0 ] );
+ $ref->close();
+ }
}