config: Add tests for EtcdConfig::fetchAllFromEtcdServer
Follows-up9b459d29e0,110a21ea18. Bug: T156924 Change-Id: Ib68c55ea3386a12e707f6d7d732da9fe727ccc2f
This commit is contained in:
parent
029a17005c
commit
1f2daa9132
1 changed files with 49 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
class EtcConfigTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
private function createConfigMock( array $options = [] ) {
|
||||
|
|
@ -359,4 +361,51 @@ class EtcConfigTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
$this->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' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue