4ef4aabb92963e46b8e50a1b0dadf2c826a491fc
5 * @covers RESTBagOStuff
7 class RESTBagOStuffTest
extends MediaWikiTestCase
{
10 * @var MultiHttpClient
18 public function setUp() {
21 $this->getMockBuilder( 'MultiHttpClient' )
22 ->setConstructorArgs( [ [] ] )
23 ->setMethods( [ 'run' ] )
25 $this->bag
= new RESTBagOStuff( [ 'client' => $this->client
, 'url' => 'http://test/rest/' ] );
28 public function testGet() {
29 $this->client
->expects( $this->once() )->method( 'run' )->with( [
31 'url' => 'http://test/rest/42xyz42'
32 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
33 ] )->willReturn( [ 200, 'OK', [], 's:8:"somedata";', 0 ] );
34 $result = $this->bag
->get( '42xyz42' );
35 $this->assertEquals( 'somedata', $result );
38 public function testGetNotExist() {
39 $this->client
->expects( $this->once() )->method( 'run' )->with( [
41 'url' => 'http://test/rest/42xyz42'
42 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
43 ] )->willReturn( [ 404, 'Not found', [], 'Nothing to see here', 0 ] );
44 $result = $this->bag
->get( '42xyz42' );
45 $this->assertFalse( $result );
48 public function testGetBadClient() {
49 $this->client
->expects( $this->once() )->method( 'run' )->with( [
51 'url' => 'http://test/rest/42xyz42'
52 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
53 ] )->willReturn( [ 0, '', [], '', 'cURL has failed you today' ] );
54 $result = $this->bag
->get( '42xyz42' );
55 $this->assertFalse( $result );
56 $this->assertEquals( BagOStuff
::ERR_UNREACHABLE
, $this->bag
->getLastError() );
59 public function testGetBadServer() {
60 $this->client
->expects( $this->once() )->method( 'run' )->with( [
62 'url' => 'http://test/rest/42xyz42'
63 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
64 ] )->willReturn( [ 500, 'Too busy', [], 'Server is too busy', '' ] );
65 $result = $this->bag
->get( '42xyz42' );
66 $this->assertFalse( $result );
67 $this->assertEquals( BagOStuff
::ERR_UNEXPECTED
, $this->bag
->getLastError() );
70 public function testPut() {
71 $this->client
->expects( $this->once() )->method( 'run' )->with( [
73 'url' => 'http://test/rest/42xyz42',
74 'body' => 's:8:"postdata";'
75 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
76 ] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] );
77 $result = $this->bag
->set( '42xyz42', 'postdata' );
78 $this->assertTrue( $result );
81 public function testDelete() {
82 $this->client
->expects( $this->once() )->method( 'run' )->with( [
84 'url' => 'http://test/rest/42xyz42',
85 // list( $rcode, $rdesc, $rhdrs, $rbody, $rerr )
86 ] )->willReturn( [ 200, 'OK', [], 'Done', 0 ] );
87 $result = $this->bag
->delete( '42xyz42' );
88 $this->assertTrue( $result );