Page MenuHomeIn-Portal Phabricator

INP-1889 - Don't use DB Load Balancer during PHPUnit Testing
Needs ReviewPublic

Authored by alex on Mon, Nov 25, 10:19 AM.

Details

Reviewers
erik
Test Plan
  1. in the Database:
    • execute the ALTER TABLE MailingLists ENGINE = InnoDB; (add your table prefix as needed) database query
  2. in the IDE:
    • open the /system/config.php file for editing
    • append this to end of the file:
$_CONFIG['Databases'] = array(
    array(
	'DBHost' => $_CONFIG['Database']['DBHost'],
	'DBUser' => $_CONFIG['Database']['DBUser'],
	'DBUserPassword' => $_CONFIG['Database']['DBUserPassword'],
	'DBLoad' => 1,
	'DBMaxLag' => 15,
    ),
);
  • save changes
  • open the SampleUnitTest PHP class (somewhere inside /modules/custom/tests folder)
  • add this code to that PHP class:
public function testDatabaseTransactions()
{
    $this->Conn->Query('TRUNCATE TABLE ' . TABLE_PREFIX . 'MailingLists');

    $count_sql = '	SELECT COUNT(*)
		    FROM ' . TABLE_PREFIX . 'MailingLists';
    $mailing_list_count_before = $this->Conn->GetOne($count_sql);

    $this->assertEquals(0, $mailing_list_count_before);

    $this->Conn->Query('begin');

    $this->Conn->doInsert(array('Subject' => 'test'), TABLE_PREFIX . 'MailingLists');

    $mailing_list_count_in_transaction = $this->Conn->GetOne($count_sql);
    $this->assertEquals(1, $mailing_list_count_in_transaction);

    $this->Conn->Query('rollback');

    $mailing_list_count_after_rollback = $this->Conn->GetOne($count_sql);
    $this->assertEquals(0, $mailing_list_count_after_rollback);
}
    • save changes
  1. in CLI:
    • run the vendor/bin/phpunit -c tools/build/inc/custom_phpunit.xml --filter testDatabaseTransactions command (prefix that command with a needed php binary version, e.g. php56)
    • confirm, that test passed

Diff Detail

Repository
rINP In-Portal
Branch
/in-portal/branches/5.2.x
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 1345
Build 1345: arc lint + arc unit

Event Timeline

alex created this revision.Mon, Nov 25, 10:19 AM
alex requested review of this revision.Mon, Nov 25, 10:19 AM