MediaWiki REL1_33
RESTBagOStuffTest.php
Go to the documentation of this file.
1<?php
8
12 private $client;
16 private $bag;
17
18 public function setUp() {
19 parent::setUp();
20 $this->client =
21 $this->getMockBuilder( MultiHttpClient::class )
22 ->setConstructorArgs( [ [] ] )
23 ->setMethods( [ 'run' ] )
24 ->getMock();
25 $this->bag = new RESTBagOStuff( [ 'client' => $this->client, 'url' => 'http://test/rest/' ] );
26 }
27
28 public function testGet() {
29 $this->client->expects( $this->once() )->method( 'run' )->with( [
30 'method' => 'GET',
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 );
36 }
37
38 public function testGetNotExist() {
39 $this->client->expects( $this->once() )->method( 'run' )->with( [
40 'method' => 'GET',
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 );
46 }
47
48 public function testGetBadClient() {
49 $this->client->expects( $this->once() )->method( 'run' )->with( [
50 'method' => 'GET',
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() );
57 }
58
59 public function testGetBadServer() {
60 $this->client->expects( $this->once() )->method( 'run' )->with( [
61 'method' => 'GET',
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() );
68 }
69
70 public function testPut() {
71 $this->client->expects( $this->once() )->method( 'run' )->with( [
72 'method' => 'PUT',
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 );
79 }
80
81 public function testDelete() {
82 $this->client->expects( $this->once() )->method( 'run' )->with( [
83 'method' => 'DELETE',
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 );
89 }
90}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Class to handle multiple HTTP requests.
MultiHttpClient $client
Interface to key-value storage behind an HTTP server.