summaryrefslogtreecommitdiff
path: root/plugins/broadcast/root/tests/Broadcast/BroadcastTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/broadcast/root/tests/Broadcast/BroadcastTest.php')
-rw-r--r--plugins/broadcast/root/tests/Broadcast/BroadcastTest.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/broadcast/root/tests/Broadcast/BroadcastTest.php b/plugins/broadcast/root/tests/Broadcast/BroadcastTest.php
new file mode 100644
index 00000000..d6014bf0
--- /dev/null
+++ b/plugins/broadcast/root/tests/Broadcast/BroadcastTest.php
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * Spiral Framework.
+ *
+ * @license MIT
+ * @author Anton Titov (Wolfy-J)
+ */
+
+declare(strict_types=1);
+
+namespace Spiral\Broadcast\Tests;
+
+use PHPUnit\Framework\TestCase;
+use Spiral\Broadcast\Broadcast;
+use Spiral\Broadcast\Exception\BroadcastException;
+use Spiral\Broadcast\Message;
+use Spiral\Goridge\RPC;
+use Spiral\Goridge\SocketRelay;
+
+class BroadcastTest extends TestCase
+{
+ public function testBroadcast(): void
+ {
+ $rpc = new RPC(new SocketRelay('localhost', 6001));
+ $br = new Broadcast($rpc);
+
+ $br->publish(
+ new Message('tests/topic', 'hello'),
+ new Message('tests/123', ['key' => 'value'])
+ );
+
+ while (filesize(__DIR__ . '/../log.txt') < 40) {
+ clearstatcache(true, __DIR__ . '/../log.txt');
+ usleep(1000);
+ }
+
+ clearstatcache(true, __DIR__ . '/../log.txt');
+ $content = file_get_contents(__DIR__ . '/../log.txt');
+
+ $this->assertSame('tests/topic: "hello"
+tests/123: {"key":"value"}
+', $content);
+ }
+
+ public function testBroadcastException(): void
+ {
+ $rpc = new RPC(new SocketRelay('localhost', 6002));
+ $br = new Broadcast($rpc);
+
+ $this->expectException(BroadcastException::class);
+ $br->publish(
+ new Message('topic', 'hello')
+ );
+ }
+}