/** * @param string $username * @param string $password * @param null|string $token * @param IServiceFactory $serviceFactory * @param ClientInterface $client * @param Auth $auth * @param null|string $appNexusApiUrl */ public function __construct($username, $password, $token = null, IServiceFactory $serviceFactory = null, ClientInterface $client = null, Auth $auth = null, $appNexusApiUrl = null) { $appNexusApiUrl = $appNexusApiUrl ?: self::APP_NEXUS_API_URL; $this->username = $username; $this->password = $password; $this->token = $token; $this->serviceFactory = $serviceFactory ?: new ServiceFactory(); $this->client = $client ?: new Client($appNexusApiUrl); $this->auth = $auth ?: new Auth(); $this->auth->setClient($this->client); }
public function testTokenReturnedOnSuccess() { $stubLocalDataResponse = $this->getMock('\\SWCO\\AppNexusAPI\\Tests\\LocalDataResponse'); $stubLocalDataResponse->expects($this->once())->method('json')->will($this->returnValue(array('response' => array('token' => 'the-token')))); $stubLocalDataRequest = $this->getMock('\\SWCO\\AppNexusAPI\\Tests\\LocalDataRequest'); $stubLocalDataRequest->expects($this->once())->method('send')->will($this->returnValue($stubLocalDataResponse)); $stubLocalDataClient = $this->getMock('\\SWCO\\AppNexusAPI\\Tests\\LocalDataClient'); $stubLocalDataClient->expects($this->once())->method('post')->will($this->returnValue($stubLocalDataRequest)); $auth = new Auth(); $auth->setClient($stubLocalDataClient); $this->assertEquals('the-token', $auth->auth('username', 'password')); }