/** * Send command * * @param Client $client Pushy client * * @return bool true if valid, false if not */ public function send(Client $client) { // Create request message $requestMessage = (new RequestMessage())->setMethod('POST')->setPath('users/validate.json')->setQueryParam('token', $client->getApiToken())->setQueryParam('user', $this->user->getId()); // Set device name if one is available on the user if ($device = $this->user->getDeviceName()) { $requestMessage->setQueryParam('device', $device); } // Send request, and if no exception, user is valid $client->getTransport()->sendRequest($requestMessage); return true; }
/** * Test: Send command * * @covers \Pushy\Command\VerifyUser::send */ public function testSend() { // Stub mock client getAPiToken and getTransport $this->mockClient->shouldReceive('getApiToken')->andReturn('abc'); $this->mockClient->shouldReceive('getTransport')->andReturn($this->mockTransport); // Stub mock transport sendRequest $this->mockTransport->shouldReceive('sendRequest')->andReturn(new \stdClass()); // Stub mock user getId and getDeviceName $this->mockUser->shouldReceive('getId')->andReturn('pQiRzpo4DXghDmr9QzzfQu27cmVRsG'); $this->mockUser->shouldReceive('getDeviceName')->andReturn('droid2'); // Ensure we get true back $this->assertTrue($this->verifyUserCommand->send($this->mockClient)); }
/** * Test: Set device name with an invalid value * * @covers \Pushy\User::setDeviceName * * @expectedException \InvalidArgumentException */ public function testSetDeviceNameWithInvalidValue() { $this->user->setDeviceName('du.mmy'); }