SyslogLogTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. *
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @since 2.4.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Log\Engine;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * SyslogLogTest class
  21. */
  22. class SyslogLogTest extends TestCase {
  23. /**
  24. * Tests that the connection to the logger is open with the right arguments
  25. *
  26. * @return void
  27. */
  28. public function testOpenLog() {
  29. $log = $this->getMock('Cake\Log\Engine\SyslogLog', array('_open', '_write'));
  30. $log->expects($this->once())->method('_open')->with('', LOG_ODELAY, LOG_USER);
  31. $log->write('debug', 'message');
  32. $log = $this->getMock('Cake\Log\Engine\SyslogLog', array('_open', '_write'));
  33. $log->config(array(
  34. 'prefix' => 'thing',
  35. 'flag' => LOG_NDELAY,
  36. 'facility' => LOG_MAIL,
  37. 'format' => '%s: %s'
  38. ));
  39. $log->expects($this->once())->method('_open')
  40. ->with('thing', LOG_NDELAY, LOG_MAIL);
  41. $log->write('debug', 'message');
  42. }
  43. /**
  44. * Tests that single lines are written to syslog
  45. *
  46. * @dataProvider typesProvider
  47. * @return void
  48. */
  49. public function testWriteOneLine($type, $expected) {
  50. $log = $this->getMock('Cake\Log\Engine\SyslogLog', array('_open', '_write'));
  51. $log->expects($this->once())->method('_write')->with($expected, $type . ': Foo');
  52. $log->write($type, 'Foo');
  53. }
  54. /**
  55. * Tests that multiple lines are split and logged separately
  56. *
  57. * @return void
  58. */
  59. public function testWriteMultiLine() {
  60. $log = $this->getMock('Cake\Log\Engine\SyslogLog', array('_open', '_write'));
  61. $log->expects($this->at(1))->method('_write')->with(LOG_DEBUG, 'debug: Foo');
  62. $log->expects($this->at(2))->method('_write')->with(LOG_DEBUG, 'debug: Bar');
  63. $log->expects($this->exactly(2))->method('_write');
  64. $log->write('debug', "Foo\nBar");
  65. }
  66. /**
  67. * Data provider for the write function test
  68. *
  69. * @return array
  70. */
  71. public function typesProvider() {
  72. return array(
  73. array('emergency', LOG_EMERG),
  74. array('alert', LOG_ALERT),
  75. array('critical', LOG_CRIT),
  76. array('error', LOG_ERR),
  77. array('warning', LOG_WARNING),
  78. array('notice', LOG_NOTICE),
  79. array('info', LOG_INFO),
  80. array('debug', LOG_DEBUG)
  81. );
  82. }
  83. }