Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php

require_once __DIR__ . '/AbstractTestHttpClient.php';

use Mockery as m;
use Facebook\HttpClients\FacebookGuzzleHttpClient;

class FacebookGuzzleHttpClientTest extends AbstractTestHttpClient
{

  protected $guzzleMock;
  protected $guzzleClient;

  public function setUp()
  {
    $this->guzzleMock = m::mock('GuzzleHttp\Client');
    $this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock);
  }

  public function tearDown()
  {
    m::close();
    (new FacebookGuzzleHttpClient()); // Resets the static dependency injection
  }

  public function testCanSendNormalRequest()
  {
    $requestMock = m::mock('GuzzleHttp\Message\RequestInterface');
    $requestMock
      ->shouldReceive('setHeader')
      ->once()
      ->with('X-foo', 'bar')
      ->andReturn(null);

    $responseMock = m::mock('GuzzleHttp\Message\ResponseInterface');
    $responseMock
      ->shouldReceive('getStatusCode')
      ->once()
      ->andReturn(200);
    $responseMock
      ->shouldReceive('getHeaders')
      ->once()
      ->andReturn($this->fakeHeadersAsArray);
    $responseMock
      ->shouldReceive('getBody')
      ->once()
      ->andReturn($this->fakeRawBody);

    $this->guzzleMock
      ->shouldReceive('createRequest')
      ->once()
      ->with('GET', 'http://foo.com/', m::on(function($arg) {
            if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $arg['verify'])) {
              return false;
            }
            return true;
          }))
      ->andReturn($requestMock);

    $this->guzzleMock
      ->shouldReceive('send')
      ->once()
      ->with($requestMock)
      ->andReturn($responseMock);

    $this->guzzleClient->addRequestHeader('X-foo', 'bar');
    $responseBody = $this->guzzleClient->send('http://foo.com/');

    $this->assertEquals($responseBody, $this->fakeRawBody);
    $this->assertEquals($this->guzzleClient->getResponseHeaders(), $this->fakeHeadersAsArray);
    $this->assertEquals(200, $this->guzzleClient->getResponseHttpStatusCode());
  }

  /**
   * @expectedException \Facebook\FacebookSDKException
   */
  public function testThrowsExceptionOnClientError()
  {
    $requestMock = m::mock('GuzzleHttp\Message\RequestInterface');
    $exceptionMock = m::mock(
                      'GuzzleHttp\Exception\RequestException',
                        array(
                          'Foo Error',
                          $requestMock,
                          null,
                          m::mock('GuzzleHttp\Exception\AdapterException'),
                        ));

    $this->guzzleMock
      ->shouldReceive('createRequest')
      ->once()
      ->with('GET', 'http://foo.com/', m::on(function($arg) {
            if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $arg['verify'])) {
              return false;
            }
            return true;
          }))
      ->andReturn($requestMock);

    $this->guzzleMock
      ->shouldReceive('send')
      ->once()
      ->with($requestMock)
      ->andThrow($exceptionMock);

    $this->guzzleClient->send('http://foo.com/');
  }

}

Commits for Nextrek/Android/SmartCharging/endPoints/fb_SDK/tests/HttpClients/FacebookGuzzleHttpClientTest.php

Diff revisions: vs.
Revision Author Commited Message
507 FSallustio picture FSallustio Thu 20 Aug, 2015 07:51:22 +0000

Merge ramo stable con la nightly.