From 1f2daa9132442763a8c7722c353b686864e06675 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 22 Jul 2017 18:24:33 -0700 Subject: [PATCH] config: Add tests for EtcdConfig::fetchAllFromEtcdServer Follows-up 9b459d29e0, 110a21ea18. Bug: T156924 Change-Id: Ib68c55ea3386a12e707f6d7d732da9fe727ccc2f --- .../includes/config/EtcdConfigTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) 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' ) + ); + } } -- 2.20.1