public function testSocketSendFailed() { $s = new \Test\Mock\Phpwol\Socket(); $s->socketShouldFail = true; $m = new \Phpwol\MagicPacket($s); $mac = '50:46:5C:53:94:25'; $r = $m->send($mac, '192.168.1.255'); $this->assertFalse($r, "Socket send should have failed"); $this->assertEquals(\Phpwol\MagicPacket::ERR_SOCKET_SEND_FAILED, $m->getLastError(), "Last error should have been ERR_SOCKET_SEND_FAILED"); }
public function testPacketData() { $s = new \Test\Mock\Phpwol\Socket(); $m = new \Phpwol\MagicPacket($s); $mac = '50:46:5C:53:94:25'; $m->send($mac, '192.168.1.255'); $expected = strToLower(str_repeat('FF', 6) . str_repeat(str_replace(':', '', $mac), 16)); // 102 is the expected length of a WOL packet $nibbles = 102 * 2; $unpacked = unpack("H{$nibbles}hex", $s->lastData); $actual = strToLower($unpacked['hex']); $this->assertEquals($expected, $actual, "Last data should match expected"); }