TextTest.php 727 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. use Workerman\Connection\ConnectionInterface;
  3. use Workerman\Protocols\Text;
  4. test(Text::class, function () {
  5. $connection = Mockery::mock(ConnectionInterface::class);
  6. //::input
  7. //input too long
  8. testWithConnectionClose(function ($connection) {
  9. $connection->maxPackageSize = 5;
  10. expect(Text::input('abcdefgh', $connection))
  11. ->toBe(0);
  12. });
  13. //input without "\n"
  14. expect(Text::input('jhdxr', $connection))
  15. ->toBe(0);
  16. //input with "\n"
  17. expect(Text::input("jhdxr\n", $connection))
  18. ->toBe(6);
  19. //::encode
  20. expect(Text::encode('jhdxr'))
  21. ->toBe("jhdxr\n");
  22. //::decode
  23. expect(Text::decode("jhdxr\n"))
  24. ->toBe('jhdxr');
  25. });