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')); }
/** * @param null|string $username * @param null|string $password * @param boolean $storeToken * @return string */ public function auth($username = null, $password = null, $storeToken = true) { $this->log("Auth"); $username = $username ?: $this->username; $password = $password ?: $this->password; $token = $this->auth->auth($username, $password); if ($storeToken) { $this->token = $token; } return $token; }