jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/394705 )
Change subject: Add tests for App::getDB() ...................................................................... Add tests for App::getDB() Change-Id: I49bd2762b070d8641d8a7c7faf139a823d2d0421 --- M src/App.php A tests/AppTest.php 2 files changed, 60 insertions(+), 1 deletion(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/src/App.php b/src/App.php index 9fa292b..ec1d471 100644 --- a/src/App.php +++ b/src/App.php @@ -24,7 +24,7 @@ * @param string $host * @return PDO */ - private function openDB($dbname, $host) { + protected function openDB($dbname, $host) { $this->aTP('Create connection to ' . $host); try { diff --git a/tests/AppTest.php b/tests/AppTest.php new file mode 100644 index 0000000..d725787 --- /dev/null +++ b/tests/AppTest.php @@ -0,0 +1,59 @@ +<?php + +use Guc\App; + +class AppTest extends PHPUnit_Framework_TestCase { + + public function testGetDB() { + $app = $this->getMockBuilder(App::class) + ->setMethods(['openDB']) + ->getMock(); + + $pdo = $this->createMock(PDO::class); + $pdo->expects($this->once())->method('prepare') + ->with('USE `testwiki_p`;') + ->willReturn($this->createMock(PDOStatement::class)); + + $app->expects($this->once())->method('openDB') + ->with('testwiki_p', 'eg1.web.db.svc.eqiad.wmflabs') + ->willReturn($pdo); + + $this->assertInstanceOf( + PDO::class, + $app->getDB('testwiki', 'eg1') + ); + } + + public function testGetDBCached() { + $app = $this->getMockBuilder(App::class) + ->setMethods(['openDB']) + ->getMock(); + $pdo = $this->createMock(PDO::class); + $pdo->method('prepare')->willReturn($this->createMock(PDOStatement::class)); + + $app->expects($this->exactly(2))->method('openDB') + ->withConsecutive( + ['testwiki_p', 'eg1.web.db.svc.eqiad.wmflabs'], + ['otherwiki_p', 'eg2.web.db.svc.eqiad.wmflabs'] + ) + ->willReturn($pdo); + + $this->assertInstanceOf( + PDO::class, + $app->getDB('testwiki', 'eg1'), + 'First on eg1' + ); + + $this->assertInstanceOf( + PDO::class, + $app->getDB('otherwiki', 'eg1'), + 'Second on eg1' + ); + + $this->assertInstanceOf( + PDO::class, + $app->getDB('otherwiki', 'eg2'), + 'First on eg2' + ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/394705 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I49bd2762b070d8641d8a7c7faf139a823d2d0421 Gerrit-PatchSet: 2 Gerrit-Project: labs/tools/guc Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits