/** * Get the phones for the given user ID * NOTE: If user is already fetched and phones exist, those are returned * Otherwise, it either tries to use the user_id or the given $userId * * @param $string $userId User ID [optional] * @return array List of phones */ public function getPhones($userId = null) { // if we already have them, return them if (count($this->phones) > 0) { return $this->phones; } else { $phones = array(); $userId = $userId !== null ? $userId : $this->user_id; if ($userId == null) { throw new \InvalidArgumentException('Invalid user ID!'); } // we know the user, let's request their phones $request = $this->getRequest('admin')->setPath('/admin/v1/users/' . $userId . '/phones'); $response = $request->send(); if ($response->success() == true) { $phones = $response->getBody(); foreach ($phones as $index => $phone) { $p = new \DuoAuth\Devices\Phone(); $p->load($phone); $phones[$index] = $p; } } return $phones; } }
/** * Test that a SMS send fails without the "phone ID" * @covers \DuoAuth\Devices\Phone::smsPasscode * @expectedException \InvalidArgumentException */ public function testSendPasscodeFailNoPhoneID() { $phone = new \DuoAuth\Devices\Phone(); $phone->smsPasscode(); }