GrowlTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\analysis\logger\adapter;
  9. use lithium\analysis\logger\adapter\Growl;
  10. class GrowlTest extends \lithium\test\Unit {
  11. public function testGrowlWrite() {
  12. $connection = fopen('php://memory', 'w+');
  13. $growl = new Growl(compact('connection') + array(
  14. 'name' => 'Lithium',
  15. 'title' => 'Lithium log'
  16. ));
  17. $writer = $growl->write('info', 'info: Test message.', array());
  18. $params = array('message' => 'info: Test message.', 'options' => array());
  19. $result = $writer('lithium\analysis\Logger', $params, null);
  20. $bytes = array(
  21. 1, 0, 0, 7, 2, 2, 76, 105, 116, 104, 105, 117, 109, 0, 6, 69, 114, 114, 111, 114, 115,
  22. 0, 8, 77, 101, 115, 115, 97, 103, 101, 115, 0, 1, 126, 154, 165, 127, 162, 58, 0, 172,
  23. 243, 11, 201, 119, 62, 33, 133, 55, 1, 1, 0, 0, 0, 8, 0, 11, 0, 19, 0, 7, 77, 101, 115,
  24. 115, 97, 103, 101, 115, 76, 105, 116, 104, 105, 117, 109, 32, 108, 111, 103, 105, 110,
  25. 102, 111, 58, 32, 84, 101, 115, 116, 32, 109, 101, 115, 115, 97, 103, 101, 46, 76, 105,
  26. 116, 104, 105, 117, 109, 213, 182, 8, 47, 80, 71, 225, 173, 12, 228, 108, 152, 140, 126,
  27. 102, 14
  28. );
  29. rewind($connection);
  30. $result = array_map('ord', str_split(stream_get_contents($connection)));
  31. $this->assertEqual($bytes, $result);
  32. }
  33. public function testInvalidConnection() {
  34. $growl = new Growl(array(
  35. 'name' => 'Lithium',
  36. 'title' => 'Lithium log',
  37. 'port' => 0
  38. ));
  39. $this->expectException('/^Growl connection failed/');
  40. $this->expectException('/Failed to parse address/');
  41. $message = 'info: Test message.';
  42. $params = compact('message') + array('priority' => 'info', 'options' => array());
  43. $writer = $growl->write('info', $message, array());
  44. $writer('lithium\analysis\Logger', $params, null);
  45. }
  46. public function testInvalidConnectionWithForcedRegistration() {
  47. $growl = new Growl(array(
  48. 'name' => 'Lithium',
  49. 'title' => 'Lithium log',
  50. 'port' => 0,
  51. 'registered' => true
  52. ));
  53. $this->expectException('/^Growl connection failed/');
  54. $this->expectException('/Failed to parse address/');
  55. $message = 'info: Test message.';
  56. $params = compact('message') + array('priority' => 'info', 'options' => array());
  57. $writer = $growl->write('info', $message, array());
  58. $writer('lithium\analysis\Logger', $params, null);
  59. }
  60. public function testStickyMessages() {
  61. $connection = fopen('php://memory', 'w+');
  62. $growl = new Growl(compact('connection') + array(
  63. 'name' => 'Lithium',
  64. 'title' => 'Lithium log'
  65. ));
  66. $writer = $growl->write('info', 'info: Test message.', array());
  67. $params = array('message' => 'info: Test message.', 'options' => array('sticky' => true));
  68. $result = $writer('lithium\analysis\Logger', $params, null);
  69. $bytes = array(
  70. 1, 0, 0, 7, 2, 2, 76, 105, 116, 104, 105, 117, 109, 0, 6, 69, 114, 114, 111, 114, 115,
  71. 0, 8, 77, 101, 115, 115, 97, 103, 101, 115, 0, 1, 126, 154, 165, 127, 162, 58, 0, 172,
  72. 243, 11, 201, 119, 62, 33, 133, 55, 1, 1, 1, 0, 0, 8, 0, 11, 0, 19, 0, 7, 77, 101, 115,
  73. 115, 97, 103, 101, 115, 76, 105, 116, 104, 105, 117, 109, 32, 108, 111, 103, 105, 110,
  74. 102, 111, 58, 32, 84, 101, 115, 116, 32, 109, 101, 115, 115, 97, 103, 101, 46, 76, 105,
  75. 116, 104, 105, 117, 109, 123, 79, 163, 67, 106, 115, 6, 31, 170, 247, 50, 98, 144, 44,
  76. 105, 89
  77. );
  78. rewind($connection);
  79. $result = array_map('ord', str_split(stream_get_contents($connection)));
  80. $this->assertEqual($bytes, $result);
  81. }
  82. public function testMessagePriority() {
  83. $connection = fopen('php://memory', 'w+');
  84. $growl = new Growl(compact('connection') + array(
  85. 'name' => 'Lithium',
  86. 'title' => 'Lithium log'
  87. ));
  88. $writer = $growl->write('info', 'info: Test message.', array());
  89. $params = array('message' => 'info: Test message.', 'options' => array(
  90. 'priority' => 'emergency'
  91. ));
  92. $result = $writer('lithium\analysis\Logger', $params, null);
  93. $bytes = array(
  94. 1, 0, 0, 7, 2, 2, 76, 105, 116, 104, 105, 117, 109, 0, 6, 69, 114, 114, 111, 114, 115,
  95. 0, 8, 77, 101, 115, 115, 97, 103, 101, 115, 0, 1, 126, 154, 165, 127, 162, 58, 0, 172,
  96. 243, 11, 201, 119, 62, 33, 133, 55, 1, 1, 0, 4, 0, 8, 0, 11, 0, 19, 0, 7, 77, 101, 115,
  97. 115, 97, 103, 101, 115, 76, 105, 116, 104, 105, 117, 109, 32, 108, 111, 103, 105, 110,
  98. 102, 111, 58, 32, 84, 101, 115, 116, 32, 109, 101, 115, 115, 97, 103, 101, 46, 76, 105,
  99. 116, 104, 105, 117, 109, 180, 219, 185, 111, 150, 248, 170, 144, 208, 88, 63, 48, 171,
  100. 130, 209, 32
  101. );
  102. rewind($connection);
  103. $result = array_map('ord', str_split(stream_get_contents($connection)));
  104. $this->assertEqual($bytes, $result);
  105. }
  106. }
  107. ?>