From de2644edcb6e18f96d9bf0453dac36c683ffee77 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 29 Jun 2023 11:36:36 +1000 Subject: [PATCH] Add a test for SelectQueryBuilder::merge caller merging Change-Id: I63a3fdf988dd5e344e409c9ee85c350cbe472e65 --- .../querybuilder/SelectQueryBuilderTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/phpunit/unit/includes/libs/rdbms/querybuilder/SelectQueryBuilderTest.php b/tests/phpunit/unit/includes/libs/rdbms/querybuilder/SelectQueryBuilderTest.php index fcaac341758..5b094f41f5e 100644 --- a/tests/phpunit/unit/includes/libs/rdbms/querybuilder/SelectQueryBuilderTest.php +++ b/tests/phpunit/unit/includes/libs/rdbms/querybuilder/SelectQueryBuilderTest.php @@ -3,6 +3,7 @@ use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\SelectQueryBuilder; use Wikimedia\Rdbms\Subquery; +use Wikimedia\TestingAccessWrapper; /** * @covers \Wikimedia\Rdbms\SelectQueryBuilder @@ -644,6 +645,26 @@ class SelectQueryBuilderTest extends MediaWikiUnitTestCase { $this->assertSQL( "SELECT a,c AS b,d FROM t,u JOIN v ON ((uu=vv)) WHERE a = '1' AND (a = '2') ORDER BY a LIMIT 1" ); } + public function testMergeCaller() { + $tsqb = TestingAccessWrapper::newFromObject( $this->sqb ); + $this->sqb->caller( 'A' ); + $this->assertSame( 'A', $tsqb->caller ); + + // Merging a builder which has the default caller of __CLASS__ + // should not overwrite an explicit caller in the destination. + $this->sqb->merge( new SelectQueryBuilder( $this->db ) ); + $this->assertSame( 'A', $tsqb->caller ); + + // However, by analogy with option merging, an explicitly set caller + // should be copied into the merge destination even when the destination + // already had a caller. + $this->sqb->merge( + ( new SelectQueryBuilder( $this->db ) ) + ->caller( 'B' ) + ); + $this->assertSame( 'B', $tsqb->caller ); + } + public function testAcquireRowLocks() { $this->sqb ->table( 't' )