From: Timo Tijhof Date: Sun, 23 Jul 2017 01:24:33 +0000 (-0700) Subject: config: Add tests for EtcdConfig::fetchAllFromEtcdServer X-Git-Tag: 1.31.0-rc.0~2629^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=1f2daa9132442763a8c7722c353b686864e06675;p=lhc%2Fweb%2Fwiklou.git config: Add tests for EtcdConfig::fetchAllFromEtcdServer Follows-up 9b459d29e0, 110a21ea18. Bug: T156924 Change-Id: Ib68c55ea3386a12e707f6d7d732da9fe727ccc2f --- diff --git a/tests/phpunit/includes/config/EtcdConfigTest.php b/tests/phpunit/includes/config/EtcdConfigTest.php index 763bfa86b8..8e57a01700 100644 --- a/tests/phpunit/includes/config/EtcdConfigTest.php +++ b/tests/phpunit/includes/config/EtcdConfigTest.php @@ -1,5 +1,7 @@ assertSame( 'from-cache-expired', $mock->get( 'known' ) ); } + + public static function provideFetchFromServer() { + return [ + [ + 'http' => [ + 'code' => 200, + 'reason' => 'OK', + 'headers' => [ + 'content-length' => 0, + ], + 'body' => '', + 'error' => '(curl error: no status set)', + ], + 'expect' => [ + // FIXME: Returning 4 values instead of 3 + null, + 200, + "Unexpected JSON response; missing 'nodes' list.", + false + ], + ], + ]; + } + + /** + * @covers EtcdConfig::fetchAllFromEtcdServer + * @dataProvider provideFetchFromServer + */ + public function testFetchFromServer( array $httpResponse, array $expected ) { + $http = $this->getMockBuilder( MultiHttpClient::class ) + ->disableOriginalConstructor() + ->getMock(); + $http->expects( $this->once() )->method( 'run' ) + ->willReturn( array_values( $httpResponse ) ); + + $conf = $this->getMockBuilder( EtcdConfig::class ) + ->disableOriginalConstructor() + ->getMock(); + // Access for protected member and method + $conf = TestingAccessWrapper::newFromObject( $conf ); + $conf->http = $http; + + $this->assertSame( + $expected, + $conf->fetchAllFromEtcdServer( 'etcd-tcp.example.net' ) + ); + } }