AuthApiTest.php in TMGMT Translator Smartling 8.4
File
vendor/smartling/api-sdk-php/tests/unit/AuthApiTest.php
View source
<?php
namespace Smartling\Tests;
use Smartling\AuthApi\AuthTokenProvider;
use Smartling\Tests\Unit\ApiTestAbstract;
class AuthApiTest extends ApiTestAbstract {
protected function setUp() {
parent::setUp();
$this
->prepareAuthApiMock();
}
private function prepareAuthApiMock() {
$this->object = $this
->getMockBuilder('Smartling\\AuthApi\\AuthTokenProvider')
->setMethods(NULL)
->setConstructorArgs([
$this->userIdentifier,
$this->secretKey,
$this->client,
])
->getMock();
}
public function testAuthenticate() {
$endpointUrl = vsprintf('%s/authenticate', [
AuthTokenProvider::ENDPOINT_URL,
]);
$this->client
->expects(self::once())
->method('request')
->with('post', $endpointUrl, [
'headers' => [
'Accept' => 'application/json',
],
'exceptions' => false,
'json' => [
'userIdentifier' => 'SomeUserIdentifier',
'userSecret' => 'SomeSecretKey',
],
])
->willReturn($this->responseMock);
$this
->invokeMethod($this->object, 'authenticate');
}
public function testAuthenticateWithInvalidCredentials() {
$response_mock = $this
->getMockBuilder('GuzzleHttp\\Psr7\\Response')
->setMethods(array_merge(self::$responseInterfaceMethods, self::$messageInterfaceMethods))
->disableOriginalConstructor()
->getMock();
$response_mock
->expects($this
->any())
->method('getStatusCode')
->willReturn(401);
$client_mock = $this
->getMockBuilder('GuzzleHttp\\Client')
->setMethods(array_merge(self::$clientInterfaceMethods, self::$hasEmitterInterfaceMethods))
->disableOriginalConstructor()
->getMock();
$client_mock
->expects(self::once())
->method('request')
->willReturn($response_mock);
$auth_api_mock = $this
->getMockBuilder('Smartling\\AuthApi\\AuthTokenProvider')
->setMethods(NULL)
->setConstructorArgs([
$this->userIdentifier,
$this->secretKey,
$client_mock,
])
->getMock();
$this
->invokeMethod($auth_api_mock, 'authenticate');
}
}