TextTest.php 791 B

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