eZ\Publish\Core\REST\Client\HttpClient\Authentication\BasicAuth::request PHP Method

request() public method

Returns the result from the remote server. The client sets the correct headers for Basic Auth into the $message transmitted to the inner client.
public request ( string $method, string $path, Message $message = null ) : Message
$method string
$path string
$message eZ\Publish\Core\REST\Common\Message
return eZ\Publish\Core\REST\Common\Message
    public function request($method, $path, Message $message = null)
    {
        if ($message === null) {
            $message = new Message();
        }
        $message->headers['Authorization'] = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->password)));
        return $this->innerClient->request($method, $path, $message);
    }

Usage Example

 /**
  * Tests authentication with message
  */
 public function testAuthWithMessage()
 {
     $innerClientMock = $this->getInnerHttpClientMock();
     $client = new BasicAuth($innerClientMock, 'sindelfingen', 's3cr3t');
     $innerClientMock->expects($this->once())->method('request')->with('PUT', '/some/path', new Message(array('X-Some-Header' => 'foobar', 'Authorization' => 'Basic c2luZGVsZmluZ2VuOnMzY3IzdA=='), 'body content'))->will($this->returnValue(new \stdClass()));
     $result = $client->request('PUT', '/some/path', new Message(array('X-Some-Header' => 'foobar'), 'body content'));
     $this->assertInstanceOf('\\stdClass', $result);
 }