Phue\Command\CreateGroup::send PHP Method

send() public method

Send command
public send ( Client $client ) : integer
$client Phue\Client Phue Client
return integer Group Id
    public function send(Client $client)
    {
        $response = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/groups", TransportInterface::METHOD_POST, (object) array('name' => $this->name, 'lights' => $this->lights));
        $r = explode('/', $response->id);
        return $r[0];
    }

Usage Example

Example #1
0
 /**
  * Test: Send command
  *
  * @covers \Phue\Command\CreateGroup::__construct
  * @covers \Phue\Command\CreateGroup::send
  */
 public function testSend()
 {
     $command = new CreateGroup('Dummy', [2, 3]);
     // Stub transport's sendRequest usage
     $this->mockTransport->expects($this->once())->method('sendRequest')->with($this->equalTo("/api/{$this->mockClient->getUsername()}/groups"), $this->equalTo(TransportInterface::METHOD_POST), $this->equalTo((object) ['name' => 'Dummy', 'lights' => [2, 3]]))->will($this->returnValue((object) ['id' => '/path/5']));
     // Send command and get response
     $groupId = $command->send($this->mockClient);
     // Ensure we have a group id
     $this->assertEquals(5, $groupId);
 }