diff --git a/tests/Unit/Message/FactoryTest.php b/tests/Unit/Message/FactoryTest.php index ae884c3..0bd5882 100644 --- a/tests/Unit/Message/FactoryTest.php +++ b/tests/Unit/Message/FactoryTest.php @@ -4,8 +4,14 @@ namespace Tests\Unit\Message; +use Basis\Nats\Client; +use Basis\Nats\Message\Ack; use Basis\Nats\Message\Factory; use Basis\Nats\Message\Info; +use Basis\Nats\Message\Msg; +use Basis\Nats\Message\Payload; +use Basis\Nats\Message\Pong; +use ReflectionProperty; use Tests\TestCase; class FactoryTest extends TestCase @@ -32,6 +38,34 @@ public function testInfo() $this->assertSame($infoString, $message->render()); } + public function testMsgParseTrim() + { + $body = 'MSG {"length":3,"sid":"123","subject":"tester","hlength":null,"timestampNanos":null,"replyTo":null}'; + $this->assertSame(Msg::create("tester 123 3 ")->render(), $body); + } + + public function testClientGetter() + { + $msg = Msg::create("a b c"); + $this->assertNull($msg->getClient()); + $client = new Client(); + $msg->setClient($client); + $this->assertSame($client, $msg->getClient()); + } + + public function testInvalidMsgLength() + { + $this->expectExceptionMessage("Invalid Msg: a b"); + $this->assertSame(Msg::create("a b ")->subject, 'tester'); + } + + public function testPayloadValidation() + { + new Pong(new Payload('')); + $this->expectExceptionMessage("Invalid property nick for message " . Pong::class); + new Pong(new Payload(json_encode(['nick' => 'nekufa']))); + } + public function testRendering() { $this->assertSame("PONG", Factory::create("PONG")->render());