-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
144 additions
and
7 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
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,21 @@ | ||
<?php | ||
|
||
namespace jkniest\HueIt\Clients; | ||
|
||
class LocalHueClient implements HueClient | ||
{ | ||
public function get(string $endpoint): array | ||
{ | ||
// TODO: Implement get() method. | ||
Check failure on line 9 in src/Clients/LocalHueClient.php GitHub Actions / PHPstan (8.1, lowest)
|
||
} | ||
|
||
public function isAuthenticated(): bool | ||
{ | ||
// TODO: Implement isAuthenticated() method. | ||
Check failure on line 14 in src/Clients/LocalHueClient.php GitHub Actions / PHPstan (8.1, lowest)
|
||
} | ||
|
||
public function authenticate(): void | ||
{ | ||
// TODO: Implement authenticate() method. | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace jkniest\HueIt\Exceptions; | ||
|
||
use Exception; | ||
|
||
class HueItException extends Exception | ||
{ | ||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace jkniest\HueIt\Exceptions; | ||
|
||
use Throwable; | ||
|
||
class NotAuthenticatedException extends HueItException | ||
{ | ||
public function __construct(int $code = 0, ?Throwable $previous = null) | ||
{ | ||
parent::__construct('Not authenticated', $code, $previous); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,26 +1,41 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Collection; | ||
use jkniest\HueIt\Exceptions\NotAuthenticatedException; | ||
use jkniest\HueIt\Fake\FakeHueClient; | ||
use jkniest\HueIt\Fake\Model\FakeLight; | ||
use jkniest\HueIt\Models\Light; | ||
use jkniest\HueIt\PhillipsHue; | ||
|
||
it('can return a collection of lights', function () { | ||
$client = new FakeHueClient(); | ||
|
||
$client->setFakeLights([ | ||
FakeLight::create()->name('Example Light 1'), | ||
FakeLight::create(), | ||
FakeLight::create(), | ||
]); | ||
|
||
$hue = new PhillipsHue('123.456.789.1', 'my-token-123'); | ||
expect($client->isAuthenticated())->toBeFalse(); | ||
|
||
$hue = new PhillipsHue(); | ||
$hue->setClient($client); | ||
|
||
$authResult = $hue->authenticate(FakeHueClient::VALID_HOST, FakeHueClient::VALID_TOKEN); | ||
expect($authResult)->toBe($hue) | ||
->and($client->isAuthenticated())->toBeTrue(); | ||
|
||
$lights = $hue->getLights(); | ||
|
||
expect($lights)->toBeInstanceOf(Collection::class) | ||
->and($lights)->toHaveCount(3) | ||
->and($lights->first())->toBeInstanceOf(Light::class) | ||
->and($lights->first()->name)->toBe('Example Light 1'); | ||
}); | ||
|
||
it('throws an exception if not authenticated', function () { | ||
$hue = new PhillipsHue(); | ||
$hue->setClient(new FakeHueClient()); | ||
|
||
$hue->getLights(); | ||
})->throws(NotAuthenticatedException::class); |
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,25 @@ | ||
<?php | ||
|
||
use jkniest\HueIt\Clients\LocalHueClient; | ||
|
||
todo('can authenticate', function (): void { | ||
$client = new LocalHueClient(); | ||
|
||
expect($client->isAuthenticated())->toBeFalse(); | ||
|
||
$client->authenticate('127.0.0.1', 'my-token-123'); | ||
|
||
expect($client->isAuthenticated())->toBeTrue() | ||
->and($client->getHost())->toBe('127.0.0.1') | ||
->and($client->getToken())->toBe('my-token-123'); | ||
}); | ||
|
||
todo('can fetch resources'); | ||
|
||
todo('it throws an exception if not authenticated'); | ||
|
||
todo('it throws an exception if the bridge is not reachable'); | ||
|
||
todo('it throws an exception if the resource is not found'); | ||
|
||
todo('it throws an exception if the request is invalid'); |
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