Skip to content

Commit

Permalink
factory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Dec 25, 2024
1 parent 0b1d55f commit f490985
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Unit/Message/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down

0 comments on commit f490985

Please sign in to comment.