[MediaWiki-commits] [Gerrit] labs...guc[master]: Add tests for App::getDB()

2017-12-04 Thread jenkins-bot (Code Review)
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 000..d725787
--- /dev/null
+++ b/tests/AppTest.php
@@ -0,0 +1,59 @@
+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 
Gerrit-Reviewer: Krinkle 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] labs...guc[master]: Add tests for App::getDB()

2017-12-01 Thread Krinkle (Code Review)
Krinkle has uploaded a new change for review. ( 
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(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/guc 
refs/changes/05/394705/1

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 000..d725787
--- /dev/null
+++ b/tests/AppTest.php
@@ -0,0 +1,59 @@
+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: newchange
Gerrit-Change-Id: I49bd2762b070d8641d8a7c7faf139a823d2d0421
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/guc
Gerrit-Branch: master
Gerrit-Owner: Krinkle 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits