Skip to content

Commit

Permalink
MW 1.32, Modify tests to avoid "Call to a member function getSchema()…
Browse files Browse the repository at this point in the history
… on null", refs 3571 (#3573)
  • Loading branch information
mwjames committed Jan 6, 2019
1 parent d0ce354 commit 7ca92d6
Show file tree
Hide file tree
Showing 3 changed files with 605 additions and 145 deletions.
192 changes: 188 additions & 4 deletions tests/phpunit/Unit/SQLStore/TableBuilder/MySQLTableBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,42 @@
*/
class MySQLTableBuilderTest extends \PHPUnit_Framework_TestCase {

public function testCanConstruct() {
private $connection;

$connection = $this->getMockBuilder( '\DatabaseBase' )
protected function setUp() {

$this->connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'tableExists', 'query', 'dbSchema', 'tablePrefix' ] )
->getMockForAbstractClass();

$connection->expects( $this->any() )
$this->connection->expects( $this->any() )
->method( 'getType' )
->will( $this->returnValue( 'mysql' ) );

$this->connection->expects( $this->any() )
->method( 'dbSchema' )
->will( $this->returnValue( '' ) );

$this->connection->expects( $this->any() )
->method( 'tablePrefix' )
->will( $this->returnValue( '' ) );
}

public function testCanConstruct() {

$this->assertInstanceOf(
MySQLTableBuilder::class,
MySQLTableBuilder::factory( $connection )
MySQLTableBuilder::factory( $this->connection )
);
}

public function testCreateNewTable() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '>=' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'tableExists', 'query' ] )
Expand All @@ -60,8 +78,35 @@ public function testCreateNewTable() {
$instance->create( $table );
}

public function testCreateNewTable_132() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$this->connection->expects( $this->any() )
->method( 'tableExists' )
->will( $this->returnValue( false ) );

$this->connection->expects( $this->once() )
->method( 'query' )
->with( $this->stringContains( 'CREATE TABLE `xyz`."foo"' ) );

$instance = MySQLTableBuilder::factory( $this->connection );
$instance->addConfig( 'wgDBname', 'xyz' );

$table = new Table( 'foo' );
$table->addColumn( 'bar', 'text' );

$instance->create( $table );
}

public function testUpdateExistingTableWithNewField() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '>=' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'tableExists', 'query' ] )
Expand Down Expand Up @@ -92,8 +137,39 @@ public function testUpdateExistingTableWithNewField() {
$instance->create( $table );
}

public function testUpdateExistingTableWithNewField_132() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$this->connection->expects( $this->any() )
->method( 'tableExists' )
->will( $this->returnValue( true ) );

$this->connection->expects( $this->at( 4 ) )
->method( 'query' )
->with( $this->stringContains( 'DESCRIBE' ) )
->will( $this->returnValue( [] ) );

$this->connection->expects( $this->at( 5 ) )
->method( 'query' )
->with( $this->stringContains( 'ALTER TABLE "foo" ADD `bar` text FIRST' ) );

$instance = MySQLTableBuilder::factory( $this->connection );

$table = new Table( 'foo' );
$table->addColumn( 'bar', 'text' );

$instance->create( $table );
}

public function testUpdateExistingTableWithNewFieldAndDefault() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '>=' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'tableExists', 'query' ] )
Expand Down Expand Up @@ -125,8 +201,40 @@ public function testUpdateExistingTableWithNewFieldAndDefault() {
$instance->create( $table );
}

public function testUpdateExistingTableWithNewFieldAndDefault_132() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$this->connection->expects( $this->any() )
->method( 'tableExists' )
->will( $this->returnValue( true ) );

$this->connection->expects( $this->at( 4 ) )
->method( 'query' )
->with( $this->stringContains( 'DESCRIBE' ) )
->will( $this->returnValue( [] ) );

$this->connection->expects( $this->at( 5 ) )
->method( 'query' )
->with( $this->stringContains( 'ALTER TABLE "foo" ADD `bar` text' . " DEFAULT '0'" . ' FIRST' ) );

$instance = MySQLTableBuilder::factory( $this->connection );

$table = new Table( 'foo' );
$table->addColumn( 'bar', 'text' );
$table->addDefault( 'bar', 0 );

$instance->create( $table );
}

public function testCreateIndex() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '>=' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'tableExists', 'query' ] )
Expand Down Expand Up @@ -158,8 +266,40 @@ public function testCreateIndex() {
$instance->create( $table );
}

public function testCreateIndex_132() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$this->connection->expects( $this->any() )
->method( 'tableExists' )
->will( $this->returnValue( false ) );

$this->connection->expects( $this->at( 7 ) )
->method( 'query' )
->with( $this->stringContains( 'SHOW INDEX' ) )
->will( $this->returnValue( [] ) );

$this->connection->expects( $this->at( 10 ) )
->method( 'query' )
->with( $this->stringContains( 'ALTER TABLE "foo" ADD INDEX (bar)' ) );

$instance = MySQLTableBuilder::factory( $this->connection );

$table = new Table( 'foo' );
$table->addColumn( 'bar', 'text' );
$table->addIndex( 'bar' );

$instance->create( $table );
}

public function testDropTable() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '>=' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'tableExists', 'query' ] )
Expand All @@ -183,8 +323,32 @@ public function testDropTable() {
$instance->drop( $table );
}

public function testDropTable_132() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$this->connection->expects( $this->once() )
->method( 'tableExists' )
->will( $this->returnValue( true ) );

$this->connection->expects( $this->once() )
->method( 'query' )
->with( $this->stringContains( 'DROP TABLE "foo"' ) );

$instance = MySQLTableBuilder::factory( $this->connection );

$table = new Table( 'foo' );
$instance->drop( $table );
}

public function testOptimizeTable() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '>=' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$connection = $this->getMockBuilder( '\DatabaseBase' )
->disableOriginalConstructor()
->setMethods( [ 'query' ] )
Expand All @@ -208,4 +372,24 @@ public function testOptimizeTable() {
$instance->optimize( $table );
}

public function testOptimizeTable_132() {

if ( version_compare( $GLOBALS['wgVersion'], '1.32', '<' ) ) {
$this->markTestSkipped( 'MediaWiki changed the Database signature!' );
}

$this->connection->expects( $this->at( 3 ) )
->method( 'query' )
->with( $this->stringContains( 'ANALYZE TABLE "foo"' ) );

$this->connection->expects( $this->at( 6 ) )
->method( 'query' )
->with( $this->stringContains( 'OPTIMIZE TABLE "foo"' ) );

$instance = MySQLTableBuilder::factory( $this->connection );

$table = new Table( 'foo' );
$instance->optimize( $table );
}

}
Loading

0 comments on commit 7ca92d6

Please sign in to comment.