SyslogTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Log
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** PHPUnit_Framework_TestCase */
  23. require_once 'PHPUnit/Framework/TestCase.php';
  24. /** Zend_Log_Writer_Syslog */
  25. require_once 'Zend/Log/Writer/Syslog.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Log
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Log
  33. */
  34. class Zend_Log_Writer_SyslogTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testWrite()
  37. {
  38. $fields = array('message' => 'foo', 'priority' => LOG_NOTICE);
  39. $writer = new Zend_Log_Writer_Syslog();
  40. $writer->write($fields);
  41. }
  42. public function testFactory()
  43. {
  44. $cfg = array(
  45. 'application' => 'my app',
  46. 'facility' => LOG_USER
  47. );
  48. $writer = Zend_Log_Writer_Syslog::factory($cfg);
  49. $this->assertTrue($writer instanceof Zend_Log_Writer_Syslog);
  50. }
  51. /**
  52. * @group ZF-7603
  53. */
  54. public function testThrowExceptionValueNotPresentInFacilities()
  55. {
  56. try {
  57. $writer = new Zend_Log_Writer_Syslog();
  58. $writer->setFacility(LOG_USER * 1000);
  59. } catch (Exception $e) {
  60. $this->assertType('Zend_Log_Exception', $e);
  61. $this->assertContains('Invalid log facility provided', $e->getMessage());
  62. }
  63. }
  64. /**
  65. * @group ZF-7603
  66. */
  67. public function testThrowExceptionIfFacilityInvalidInWindows()
  68. {
  69. if ('WIN' != strtoupper(substr(PHP_OS, 0, 3))) {
  70. $this->markTestSkipped('Run only in windows');
  71. }
  72. try {
  73. $writer = new Zend_Log_Writer_Syslog();
  74. $writer->setFacility(LOG_AUTH);
  75. } catch (Exception $e) {
  76. $this->assertType('Zend_Log_Exception', $e);
  77. $this->assertContains('Only LOG_USER is a valid', $e->getMessage());
  78. }
  79. }
  80. /**
  81. * @group ZF-8953
  82. */
  83. public function testFluentInterface()
  84. {
  85. $writer = new Zend_Log_Writer_Syslog();
  86. $instance = $writer->setFacility(LOG_USER)
  87. ->setApplicationName('my_app');
  88. $this->assertTrue($instance instanceof Zend_Log_Writer_Syslog);
  89. }
  90. }