ArrayLoggerTest.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once 'Swift/Tests/SwiftUnitTestCase.php';
  3. require_once 'Swift/Plugins/Loggers/ArrayLogger.php';
  4. class Swift_Plugins_Loggers_ArrayLoggerTest
  5. extends Swift_Tests_SwiftUnitTestCase
  6. {
  7. public function testAddingSingleEntryDumpsSingleLine()
  8. {
  9. $logger = new Swift_Plugins_Loggers_ArrayLogger();
  10. $logger->add(">> Foo\r\n");
  11. $this->assertEqual(">> Foo\r\n", $logger->dump());
  12. }
  13. public function testAddingMultipleEntriesDumpsMultipleLines()
  14. {
  15. $logger = new Swift_Plugins_Loggers_ArrayLogger();
  16. $logger->add(">> FOO\r\n");
  17. $logger->add("<< 502 That makes no sense\r\n");
  18. $logger->add(">> RSET\r\n");
  19. $logger->add("<< 250 OK\r\n");
  20. $this->assertEqual(
  21. ">> FOO\r\n" . PHP_EOL .
  22. "<< 502 That makes no sense\r\n" . PHP_EOL .
  23. ">> RSET\r\n" . PHP_EOL .
  24. "<< 250 OK\r\n",
  25. $logger->dump()
  26. );
  27. }
  28. public function testLogCanBeCleared()
  29. {
  30. $logger = new Swift_Plugins_Loggers_ArrayLogger();
  31. $logger->add(">> FOO\r\n");
  32. $logger->add("<< 502 That makes no sense\r\n");
  33. $logger->add(">> RSET\r\n");
  34. $logger->add("<< 250 OK\r\n");
  35. $this->assertEqual(
  36. ">> FOO\r\n" . PHP_EOL .
  37. "<< 502 That makes no sense\r\n" . PHP_EOL .
  38. ">> RSET\r\n" . PHP_EOL .
  39. "<< 250 OK\r\n",
  40. $logger->dump()
  41. );
  42. $logger->clear();
  43. $this->assertEqual('', $logger->dump());
  44. }
  45. public function testLengthCanBeTruncated()
  46. {
  47. $logger = new Swift_Plugins_Loggers_ArrayLogger(2);
  48. $logger->add(">> FOO\r\n");
  49. $logger->add("<< 502 That makes no sense\r\n");
  50. $logger->add(">> RSET\r\n");
  51. $logger->add("<< 250 OK\r\n");
  52. $this->assertEqual(
  53. ">> RSET\r\n" . PHP_EOL .
  54. "<< 250 OK\r\n",
  55. $logger->dump(),
  56. '%s: Log should be truncated to last 2 entries'
  57. );
  58. }
  59. }