-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub #89 - Add convenience method to delete rule, add related command
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Phue: Philips Hue PHP Client | ||
* | ||
* @author Michael Squires <sqmk@php.net> | ||
* @copyright Copyright (c) 2012 Michael K. Squires | ||
* @license http://github.com/sqmk/Phue/wiki/License | ||
*/ | ||
|
||
namespace Phue\Command; | ||
|
||
use Phue\Client; | ||
use Phue\Transport\TransportInterface; | ||
|
||
/** | ||
* Delete rule command | ||
*/ | ||
class DeleteRule implements CommandInterface | ||
{ | ||
/** | ||
* Rule Id | ||
* | ||
* @var string | ||
*/ | ||
protected $ruleId; | ||
|
||
/** | ||
* Constructs a command | ||
* | ||
* @param mixed $rule Rule Id or Rule object | ||
*/ | ||
public function __construct($rule) | ||
{ | ||
$this->ruleId = (string) $rule; | ||
} | ||
|
||
/** | ||
* Send command | ||
* | ||
* @param Client $client Phue Client | ||
*/ | ||
public function send(Client $client) | ||
{ | ||
$client->getTransport()->sendRequest( | ||
"/api/{$client->getUsername()}/rules/{$this->ruleId}", | ||
TransportInterface::METHOD_DELETE | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Phue: Philips Hue PHP Client | ||
* | ||
* @author Michael Squires <sqmk@php.net> | ||
* @copyright Copyright (c) 2012 Michael K. Squires | ||
* @license http://github.com/sqmk/Phue/wiki/License | ||
*/ | ||
|
||
namespace Phue\Test\Command; | ||
|
||
use Phue\Client; | ||
use Phue\Command\DeleteRule; | ||
use Phue\Transport\TransportInterface; | ||
|
||
/** | ||
* Tests for Phue\Command\DeleteRule | ||
*/ | ||
class DeleteRuleTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Set up | ||
*/ | ||
public function setUp() | ||
{ | ||
// Mock client | ||
$this->mockClient = $this->getMock( | ||
'\Phue\Client', | ||
['getUsername', 'getTransport'], | ||
['127.0.0.1'] | ||
); | ||
|
||
// Mock transport | ||
$this->mockTransport = $this->getMock( | ||
'\Phue\Transport\TransportInterface', | ||
['sendRequest'] | ||
); | ||
|
||
// Stub client's getUsername method | ||
$this->mockClient->expects($this->any()) | ||
->method('getUsername') | ||
->will($this->returnValue('abcdefabcdef01234567890123456789')); | ||
|
||
// Stub client's getTransport method | ||
$this->mockClient->expects($this->any()) | ||
->method('getTransport') | ||
->will($this->returnValue($this->mockTransport)); | ||
} | ||
|
||
/** | ||
* Test: Send command | ||
* | ||
* @covers \Phue\Command\DeleteRule::__construct | ||
* @covers \Phue\Command\DeleteRule::send | ||
*/ | ||
public function testSend() | ||
{ | ||
$command = new DeleteRule(5); | ||
|
||
// Stub transport's sendRequest usage | ||
$this->mockTransport->expects($this->once()) | ||
->method('sendRequest') | ||
->with( | ||
$this->equalTo("/api/{$this->mockClient->getUsername()}/rules/5"), | ||
$this->equalTo(TransportInterface::METHOD_DELETE) | ||
); | ||
|
||
// Send command | ||
$command->send($this->mockClient); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters