forked from SharkEzz/YeePHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightTest.php
82 lines (68 loc) · 1.97 KB
/
LightTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace SharkEzz\Yeelight\Tests;
use Exception;
use PHPUnit\Framework\TestCase;
use SharkEzz\Yeelight\YeePHP;
class LightTest extends TestCase
{
/**
* Set this variable to the IP of your light
*
* @var string
*/
private string $ip = '192.168.1.21';
private YeePHP $light;
/**
* @throws Exception
*/
protected function setUp(): void
{
parent::setUp();
/**
* You must use a real Yeelight RGB light in order to run this tests and it must be turned on
*/
$this->light = new YeePHP($this->ip);
}
public function testConstructorThrowExceptionIfTheIpAdressIsInvalid()
{
$this->expectException(Exception::class);
new YeePHP('192.1555.0.0');
}
public function testCanSeeIfLightIsOnline(): void
{
$this->assertTrue($this->light->isConnected());
}
public function testLightCanChangeColor(): void
{
$this->light->setColor(0xFF0000);
$this->assertTrue($this->light->commit());
}
public function testLightCanChangeBrightness(): void
{
$this->light->setBrightness(50);
$this->assertTrue($this->light->commit());
}
public function testLightCanChangeColorAndBrightness(): void
{
$res = $this->light
->setColor(0xFF8888)
->setBrightness(100)
->commit();
$this->assertTrue($res);
}
public function testCanGetLightProps()
{
$this->assertNotEmpty($this->light->getName());
$this->assertNotEmpty($this->light->getBrightness());
$this->assertNotEmpty($this->light->getColor());
}
public function testIfDisconnectMethodReturnTrueIfTheSocketHasBeenClosed()
{
$this->assertTrue($this->light->disconnect());
}
public function testIfDisconnectMethodReturnFalseIfTheSocketHasBeenAlreadyClosed()
{
$this->light->disconnect();
$this->assertFalse($this->light->disconnect());
}
}