Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue #33 - Cleanup. Additional exception.

  • Loading branch information...
commit 0bcf89e82a3dbdd29220e4e2afefcd5977621173 1 parent 50ef1f6
@sqmk authored
Showing with 164 additions and 125 deletions.
  1. +1 −1  .travis.yml
  2. +7 −0 composer.json
  3. +2 −2 library/Phue/Command/Authenticate.php
  4. +2 −2 library/Phue/Command/CreateGroup.php
  5. +4 −2 library/Phue/Command/CreateSchedule.php
  6. +2 −2 library/Phue/Command/DeleteGroup.php
  7. +2 −2 library/Phue/Command/DeleteSchedule.php
  8. +2 −2 library/Phue/Command/SetBridgeConfig.php
  9. +2 −2 library/Phue/Command/SetGroupAction.php
  10. +2 −2 library/Phue/Command/SetGroupConfig.php
  11. +2 −2 library/Phue/Command/SetLightName.php
  12. +2 −2 library/Phue/Command/SetLightState.php
  13. +2 −2 library/Phue/Command/StartLightScan.php
  14. +3 −1 library/Phue/Transport/Exception/InvalidBodyException.php
  15. +3 −1 library/Phue/Transport/Exception/InvalidParameterException.php
  16. +3 −1 library/Phue/Transport/Exception/InvalidValueException.php
  17. +3 −1 library/Phue/Transport/Exception/MethodException.php
  18. +3 −1 library/Phue/Transport/Exception/ParameterUnavailableException.php
  19. +23 −0 library/Phue/Transport/Exception/ParameterUnmodifiableException.php
  20. +3 −1 library/Phue/Transport/Exception/ResourceException.php
  21. +2 −22 library/Phue/Transport/Http.php
  22. +6 −4 tests/PhueTest/Command/CreateGroupTest.php
  23. +21 −15 tests/PhueTest/Command/CreateScheduleTest.php
  24. +5 −3 tests/PhueTest/Command/IsAuthorizedTest.php
  25. +5 −3 tests/PhueTest/Command/SetGroupActionTest.php
  26. +6 −4 tests/PhueTest/Command/SetGroupConfigTest.php
  27. +45 −27 tests/PhueTest/Command/SetLightStateTest.php
  28. +1 −18 tests/PhueTest/Transport/HttpTest.php
  29. 0  tests/{codesniffer.xml → phpcs.xml}
View
2  .travis.yml
@@ -7,7 +7,7 @@ before_install:
- composer install --dev
script:
- - ./vendor/bin/phpcs --standard=tests/codesniffer.xml library/
+ - ./vendor/bin/phpcs --standard=tests/phpcs.xml library/
- ./vendor/bin/phpunit --configuration=tests
notifications:
View
7 composer.json
@@ -10,6 +10,13 @@
],
"homepage": "http://github.com/sqmk/phue",
"license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Michael Squires",
+ "email": "sqmk@php.net",
+ "role": "lead"
+ }
+ ],
"require": {
"php": "5.4.*"
},
View
4 library/Phue/Command/Authenticate.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -34,7 +34,7 @@ public function send(Client $client)
// Get response
$response = $client->getTransport()->sendRequest(
'',
- Http::METHOD_POST,
+ TransportInterface::METHOD_POST,
$this->buildRequestData($client)
);
View
4 library/Phue/Command/CreateGroup.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -92,7 +92,7 @@ public function send(Client $client)
{
$response = $client->getTransport()->sendRequest(
"{$client->getUsername()}/groups",
- Http::METHOD_POST,
+ TransportInterface::METHOD_POST,
(object) [
'name' => $this->name,
'lights' => $this->lights
View
6 library/Phue/Command/CreateSchedule.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
use Phue\Command\SchedulableInterface;
@@ -70,6 +70,8 @@ public function __construct(
$time !== null && $this->time($time);
$command !== null && $this->command($command);
+ // Copy description
+ $this->description = $this->name;
}
/**
@@ -141,7 +143,7 @@ public function send(Client $client)
{
$scheduleId = $client->getTransport()->sendRequest(
"{$client->getUsername()}/schedules",
- Http::METHOD_POST,
+ TransportInterface::METHOD_POST,
(object) [
'name' => $this->name,
'description' => $this->description,
View
4 library/Phue/Command/DeleteGroup.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/groups/{$this->groupId}",
- Http::METHOD_DELETE
+ TransportInterface::METHOD_DELETE
);
}
}
View
4 library/Phue/Command/DeleteSchedule.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/schedules/{$this->scheduleId}",
- Http::METHOD_DELETE
+ TransportInterface::METHOD_DELETE
);
}
}
View
4 library/Phue/Command/SetBridgeConfig.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -50,7 +50,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/config",
- Http::METHOD_PUT,
+ TransportInterface::METHOD_PUT,
(object) $this->config
);
}
View
4 library/Phue/Command/SetGroupAction.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\SetLightState;
use Phue\Command\SchedulableInterface;
@@ -72,7 +72,7 @@ public function getSchedulableParams(Client $client)
{
return [
'address' => "{$client->getUsername()}/groups/{$this->groupId}/action",
- 'method' => Http::METHOD_PUT,
+ 'method' => TransportInterface::METHOD_PUT,
'body' => (object) $this->params
];
}
View
4 library/Phue/Command/SetGroupConfig.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -91,7 +91,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/groups/{$this->groupId}",
- Http::METHOD_PUT,
+ TransportInterface::METHOD_PUT,
(object) $this->params
);
}
View
4 library/Phue/Command/SetLightName.php
@@ -12,7 +12,7 @@
use Phue\Client;
use Phue\Light;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -60,7 +60,7 @@ public function send(Client $client)
{
$client->getTransport()->sendRequest(
"{$client->getUsername()}/lights/{$this->lightId}",
- Http::METHOD_PUT,
+ TransportInterface::METHOD_PUT,
(object) [
'name' => $this->name
]
View
4 library/Phue/Command/SetLightState.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
use Phue\Command\SchedulableInterface;
@@ -327,7 +327,7 @@ public function getSchedulableParams(Client $client)
{
return [
'address' => "{$client->getUsername()}/lights/{$this->lightId}/state",
- 'method' => Http::METHOD_PUT,
+ 'method' => TransportInterface::METHOD_PUT,
'body' => (object) $this->params
];
}
View
4 library/Phue/Command/StartLightScan.php
@@ -11,7 +11,7 @@
namespace Phue\Command;
use Phue\Client;
-use Phue\Transport\Http;
+use Phue\Transport\TransportInterface;
use Phue\Command\CommandInterface;
/**
@@ -34,7 +34,7 @@ public function send(Client $client)
// Get response
$response = $client->getTransport()->sendRequest(
"{$client->getUsername()}/lights",
- Http::METHOD_POST
+ TransportInterface::METHOD_POST
);
return $response;
View
4 library/Phue/Transport/Exception/InvalidBodyException.php
@@ -10,12 +10,14 @@
namespace Phue\Transport\Exception;
+use Phue\Transport\Exception\BridgeException;
+
/**
* Invalid body exception
*
* @category Phue
* @package Phue
*/
-class InvalidBodyException extends \Exception
+class InvalidBodyException extends BridgeException
{
}
View
4 library/Phue/Transport/Exception/InvalidParameterException.php
@@ -10,12 +10,14 @@
namespace Phue\Transport\Exception;
+use Phue\Transport\Exception\BridgeException;
+
/**
* Invalid parameter exception
*
* @category Phue
* @package Phue
*/
-class InvalidParameterException extends \Exception
+class InvalidParameterException extends BridgeException
{
}
View
4 library/Phue/Transport/Exception/InvalidValueException.php
@@ -10,12 +10,14 @@
namespace Phue\Transport\Exception;
+use Phue\Transport\Exception\BridgeException;
+
/**
* Invalid value exception
*
* @category Phue
* @package Phue
*/
-class InvalidValueException extends \Exception
+class InvalidValueException extends BridgeException
{
}
View
4 library/Phue/Transport/Exception/MethodException.php
@@ -10,12 +10,14 @@
namespace Phue\Transport\Exception;
+use Phue\Transport\Exception\BridgeException;
+
/**
* Method exception
*
* @category Phue
* @package Phue
*/
-class MethodException extends \Exception
+class MethodException extends BridgeException
{
}
View
4 library/Phue/Transport/Exception/ParameterUnavailableException.php
@@ -10,12 +10,14 @@
namespace Phue\Transport\Exception;
+use Phue\Transport\Exception\BridgeException;
+
/**
* Parameter unavailable exception
*
* @category Phue
* @package Phue
*/
-class ParameterUnavailableException extends \Exception
+class ParameterUnavailableException extends BridgeException
{
}
View
23 library/Phue/Transport/Exception/ParameterUnmodifiableException.php
@@ -0,0 +1,23 @@
+<?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
+ * @package Phue
+ */
+
+namespace Phue\Transport\Exception;
+
+use Phue\Transport\Exception\BridgeException;
+
+/**
+ * Parameter unmodifiable exception
+ *
+ * @category Phue
+ * @package Phue
+ */
+class ParameterUnmodifiableException extends BridgeException
+{
+}
View
4 library/Phue/Transport/Exception/ResourceException.php
@@ -10,12 +10,14 @@
namespace Phue\Transport\Exception;
+use Phue\Transport\Exception\BridgeException;
+
/**
* Resource exception
*
* @category Phue
* @package Phue
*/
-class ResourceException extends \Exception
+class ResourceException extends BridgeException
{
}
View
24 library/Phue/Transport/Http.php
@@ -54,6 +54,7 @@ class Http implements TransportInterface
6 => 'Phue\Transport\Exception\ParameterUnavailableException',
7 => 'Phue\Transport\Exception\InvalidValueException',
101 => 'Phue\Transport\Exception\LinkButtonException',
+ 201 => 'Phue\Transport\Exception\ParameterUnmodifiableException',
301 => 'Phue\Transport\Exception\GroupTableFullException',
901 => 'Phue\Transport\Exception\ThrottleException',
];
@@ -110,7 +111,7 @@ public function setAdapter(AdapterInterface $adapter)
public function sendRequest($address, $method = self::METHOD_GET, \stdClass $body = null)
{
// Build request url
- $url = $this->buildRequestUrl($address, true);
+ $url = "http://{$this->client->getHost()}/api/{$address}";
// Open connection
$this->getAdapter()->open();
@@ -153,27 +154,6 @@ public function sendRequest($address, $method = self::METHOD_GET, \stdClass $bod
}
/**
- * Build request URL
- *
- * @param string $path Request path
- * @param bool $includeHost Include host in path
- *
- * @return string Request URL
- */
- public function buildRequestUrl($path, $includeHost = false)
- {
- // Start with full path
- $fullPath = "/api/{$path}";
-
- // Include host if necessary
- if ($includeHost) {
- $fullPath = "http://{$this->client->getHost()}" . $fullPath;
- }
-
- return $fullPath;
- }
-
- /**
* Get exception by type
*
* @param string $type Error type
View
10 tests/PhueTest/Command/CreateGroupTest.php
@@ -111,10 +111,12 @@ public function testSend()
->with(
$this->equalTo("{$this->mockClient->getUsername()}/groups"),
$this->equalTo(TransportInterface::METHOD_POST),
- $this->equalTo((object) [
- 'name' => 'Dummy',
- 'lights' => [2, 3]
- ])
+ $this->equalTo(
+ (object) [
+ 'name' => 'Dummy',
+ 'lights' => [2, 3]
+ ]
+ )
)
->will($this->returnValue((object)['id' => '/path/5']));
View
36 tests/PhueTest/Command/CreateScheduleTest.php
@@ -64,11 +64,15 @@ public function setUp()
// Stub command's getSchedulableParams method
$this->mockCommand->expects($this->any())
->method('getSchedulableParams')
- ->will($this->returnValue([
- 'address' => '/api/endpoint',
- 'method' => 'POST',
- 'body' => 'Dummy'
- ]));
+ ->will(
+ $this->returnValue(
+ [
+ 'address' => '/api/endpoint',
+ 'method' => 'POST',
+ 'body' => 'Dummy'
+ ]
+ )
+ );
}
/**
@@ -156,7 +160,7 @@ public function testCommand()
// Ensure properties are set properly
$this->assertAttributeEquals(
- $this->mockCommand,
+ $this->mockCommand,
'command',
$command
);
@@ -182,16 +186,18 @@ public function testSend()
->with(
$this->equalTo("{$this->mockClient->getUsername()}/schedules"),
$this->equalTo(TransportInterface::METHOD_POST),
- $this->equalTo((object) [
- 'name' => 'Dummy!',
- 'description' => 'Description!',
- 'time' => '2012-12-30T10:11:12',
- 'command' => [
- 'method' => TransportInterface::METHOD_POST,
- 'address' => "/api/endpoint",
- 'body' => "Dummy"
+ $this->equalTo(
+ (object) [
+ 'name' => 'Dummy!',
+ 'description' => 'Description!',
+ 'time' => '2012-12-30T10:11:12',
+ 'command' => [
+ 'method' => TransportInterface::METHOD_POST,
+ 'address' => "/api/endpoint",
+ 'body' => "Dummy"
+ ]
]
- ])
+ )
)
->will($this->returnValue(4));
View
8 tests/PhueTest/Command/IsAuthorizedTest.php
@@ -82,9 +82,11 @@ public function testIsNotAuthorized()
$this->mockTransport->expects($this->once())
->method('sendRequest')
->with($this->equalTo($this->mockClient->getUsername()))
- ->will($this->throwException(
- $this->getMock('\Phue\Transport\Exception\AuthorizationException')
- ));
+ ->will(
+ $this->throwException(
+ $this->getMock('\Phue\Transport\Exception\AuthorizationException')
+ )
+ );
$this->assertFalse(
(new IsAuthorized)->send($this->mockClient)
View
8 tests/PhueTest/Command/SetGroupActionTest.php
@@ -72,9 +72,11 @@ public function testSend()
$setGroupActionCmd = new SetGroupAction($this->mockGroup);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'ct' => '300'
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'ct' => '300'
+ ]
+ );
// Change color temp and set state
$setGroupActionCmd->colorTemp(300)
View
10 tests/PhueTest/Command/SetGroupConfigTest.php
@@ -74,10 +74,12 @@ public function testSend()
$setGroupConfigCmd = new SetGroupConfig($this->mockGroup);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'name' => 'Dummy!',
- 'lights' => [3]
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'name' => 'Dummy!',
+ 'lights' => [3]
+ ]
+ );
// Change name and lights
$setGroupConfigCmd->name('Dummy!')
View
72 tests/PhueTest/Command/SetLightStateTest.php
@@ -74,9 +74,11 @@ public function testOnSend($state)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'on' => $state
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'on' => $state
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -116,9 +118,11 @@ public function testBrightnessSend($brightness)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'bri' => $brightness
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'bri' => $brightness
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -156,9 +160,11 @@ public function testHueSend($value)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'hue' => $value
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'hue' => $value
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -196,9 +202,11 @@ public function testSaturationSend($value)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'sat' => $value
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'sat' => $value
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -238,9 +246,11 @@ public function testXYSend($x, $y)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'xy' => [$x, $y]
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'xy' => [$x, $y]
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -280,9 +290,11 @@ public function testColorTempSend($temp)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'ct' => $temp
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'ct' => $temp
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -336,9 +348,11 @@ public function testAlertSend($mode)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'alert' => $mode
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'alert' => $mode
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -376,9 +390,11 @@ public function testTransitionTimeSend($time)
$command = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'transitiontime' => $time * 10
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'transitiontime' => $time * 10
+ ]
+ );
// Ensure instance is returned
$this->assertEquals(
@@ -402,9 +418,11 @@ public function testSend()
$setLightStateCmd = new SetLightState($this->mockLight);
// Set expected payload
- $this->stubTransportSendRequestWithPayload((object) [
- 'alert' => 'select'
- ]);
+ $this->stubTransportSendRequestWithPayload(
+ (object) [
+ 'alert' => 'select'
+ ]
+ );
// Change alert and set state
$setLightStateCmd->alert('select')
View
19 tests/PhueTest/Transport/HttpTest.php
@@ -203,24 +203,6 @@ public function testSendRequestSuccess()
}
/**
- * Test: Build request URL
- *
- * @covers Phue\Transport\Http::buildRequestUrl
- */
- public function testBuildRequestUrl()
- {
- $this->assertEquals(
- $this->transport->buildRequestUrl('dummy', true),
- "http://{$this->mockClient->getHost()}/api/dummy"
- );
-
- $this->assertEquals(
- $this->transport->buildRequestUrl('dummy'),
- "/api/dummy"
- );
- }
-
- /**
* Test: Throw exception by type
*
* @dataProvider providerErrorTypes
@@ -251,6 +233,7 @@ public function providerErrorTypes()
[6, 'Phue\Transport\Exception\ParameterUnavailableException'],
[7, 'Phue\Transport\Exception\InvalidValueException'],
[101, 'Phue\Transport\Exception\LinkButtonException'],
+ [201, 'Phue\Transport\Exception\ParameterUnmodifiableException'],
[301, 'Phue\Transport\Exception\GroupTableFullException'],
[901, 'Phue\Transport\Exception\ThrottleException'],
[-1, 'Phue\Transport\Exception\BridgeException'],
View
0  tests/codesniffer.xml → tests/phpcs.xml
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.