+
+ private function assertWriteForbidden( Database $db ) {
+ try {
+ $db->delete( 'some_table', [ 'id' => 57634126 ], __METHOD__ );
+ $this->fail( 'Write operation should have failed!' );
+ } catch ( DBError $ex ) {
+ // check that the exception message contains "Write operation"
+ $constraint = new PHPUnit_Framework_Constraint_StringContains( 'Write operation' );
+
+ if ( !$constraint->evaluate( $ex->getMessage(), '', true ) ) {
+ // re-throw original error, to preserve stack trace
+ throw $ex;
+ }
+ } finally {
+ $db->rollback( __METHOD__, 'flush' );
+ }
+ }
+
+ private function assertWriteAllowed( Database $db ) {
+ $table = $db->tableName( 'some_table' );
+ try {
+ $db->dropTable( 'some_table' ); // clear for sanity
+ // Use only basic SQL and trivial types for these queries for compatibility
+ $this->assertNotSame(
+ false,
+ $db->query( "CREATE TABLE $table (id INT, time INT)", __METHOD__ ),
+ "table created"
+ );
+ $this->assertNotSame(
+ false,
+ $db->query( "DELETE FROM $table WHERE id=57634126", __METHOD__ ),
+ "delete query"
+ );
+ $this->assertNotSame(
+ false,
+ $db->query( "DROP TABLE $table", __METHOD__ ),
+ "table dropped"
+ );
+ } finally {
+ $db->rollback( __METHOD__, 'flush' );
+ }
+ }
+