Happyr\LinkedIn\LinkedInTest::testApi PHP Method

testApi() public method

public testApi ( )
    public function testApi()
    {
        $resource = 'resource';
        $token = 'token';
        $urlParams = ['url' => 'foo'];
        $postParams = ['post' => 'bar'];
        $method = 'GET';
        $expected = ['foobar' => 'test'];
        $response = new Response(200, [], json_encode($expected));
        $url = 'http://example.com/test';
        $headers = ['Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json', 'x-li-format' => 'json'];
        $generator = $this->getMock('Happyr\\LinkedIn\\Http\\UrlGenerator', ['getUrl']);
        $generator->expects($this->once())->method('getUrl')->with($this->equalTo('api'), $this->equalTo($resource), $this->equalTo(['url' => 'foo', 'format' => 'json']))->willReturn($url);
        $requestManager = $this->getMock('Happyr\\LinkedIn\\Http\\RequestManager', ['sendRequest']);
        $requestManager->expects($this->once())->method('sendRequest')->with($this->equalTo($method), $this->equalTo($url), $this->equalTo($headers), $this->equalTo(json_encode($postParams)))->willReturn($response);
        $linkedIn = $this->getMock('Happyr\\LinkedIn\\LinkedIn', ['getAccessToken', 'getUrlGenerator', 'getRequestManager'], [self::APP_ID, self::APP_SECRET]);
        $linkedIn->expects($this->once())->method('getAccessToken')->willReturn($token);
        $linkedIn->expects($this->once())->method('getUrlGenerator')->willReturn($generator);
        $linkedIn->expects($this->once())->method('getRequestManager')->willReturn($requestManager);
        $result = $linkedIn->api($method, $resource, ['query' => $urlParams, 'json' => $postParams]);
        $this->assertEquals($expected, $result);
    }