PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Log/Writer/SyslogTest.php

https://bitbucket.org/ksekar/campus
PHP | 145 lines | 85 code | 16 blank | 44 comment | 5 complexity | 5ade1dd7d3e1fa3d5a1330dd3ed6b3fc MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: SyslogTest.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Log_Writer_SyslogTest::main');
  24. }
  25. /** Zend_Log_Writer_Syslog */
  26. require_once 'Zend/Log/Writer/Syslog.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Log
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Log
  34. */
  35. class Zend_Log_Writer_SyslogTest extends PHPUnit_Framework_TestCase
  36. {
  37. public static function main()
  38. {
  39. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  40. $result = PHPUnit_TextUI_TestRunner::run($suite);
  41. }
  42. public function testWrite()
  43. {
  44. $fields = array('message' => 'foo', 'priority' => LOG_NOTICE);
  45. $writer = new Zend_Log_Writer_Syslog();
  46. $writer->write($fields);
  47. }
  48. public function testFactory()
  49. {
  50. $cfg = array(
  51. 'application' => 'my app',
  52. 'facility' => LOG_USER
  53. );
  54. $writer = Zend_Log_Writer_Syslog::factory($cfg);
  55. $this->assertTrue($writer instanceof Zend_Log_Writer_Syslog);
  56. }
  57. /**
  58. * @group ZF-7603
  59. */
  60. public function testThrowExceptionValueNotPresentInFacilities()
  61. {
  62. try {
  63. $writer = new Zend_Log_Writer_Syslog();
  64. $writer->setFacility(LOG_USER * 1000);
  65. } catch (Exception $e) {
  66. $this->assertType('Zend_Log_Exception', $e);
  67. $this->assertContains('Invalid log facility provided', $e->getMessage());
  68. }
  69. }
  70. /**
  71. * @group ZF-7603
  72. */
  73. public function testThrowExceptionIfFacilityInvalidInWindows()
  74. {
  75. if ('WIN' != strtoupper(substr(PHP_OS, 0, 3))) {
  76. $this->markTestSkipped('Run only in windows');
  77. }
  78. try {
  79. $writer = new Zend_Log_Writer_Syslog();
  80. $writer->setFacility(LOG_AUTH);
  81. } catch (Exception $e) {
  82. $this->assertType('Zend_Log_Exception', $e);
  83. $this->assertContains('Only LOG_USER is a valid', $e->getMessage());
  84. }
  85. }
  86. /**
  87. * @group ZF-8953
  88. */
  89. public function testFluentInterface()
  90. {
  91. $writer = new Zend_Log_Writer_Syslog();
  92. $instance = $writer->setFacility(LOG_USER)
  93. ->setApplicationName('my_app');
  94. $this->assertTrue($instance instanceof Zend_Log_Writer_Syslog);
  95. }
  96. /**
  97. * @group ZF-10769
  98. */
  99. public function testPastFacilityViaConstructor()
  100. {
  101. $writer = new WriterSyslogCustom(array('facility' => LOG_USER));
  102. $this->assertEquals(LOG_USER, $writer->getFacility());
  103. }
  104. /**
  105. * @group ZF-8382
  106. */
  107. public function testWriteWithFormatter()
  108. {
  109. $event = array(
  110. 'message' => 'tottakai',
  111. 'priority' => Zend_Log::ERR
  112. );
  113. $writer = Zend_Log_Writer_Syslog::factory(array());
  114. require_once 'Zend/Log/Formatter/Simple.php';
  115. $formatter = new Zend_Log_Formatter_Simple('%message% (this is a test)');
  116. $writer->setFormatter($formatter);
  117. $writer->write($event);
  118. }
  119. }
  120. class WriterSyslogCustom extends Zend_Log_Writer_Syslog
  121. {
  122. public function getFacility()
  123. {
  124. return $this->_facility;
  125. }
  126. }
  127. if (PHPUnit_MAIN_METHOD == 'Zend_Log_Writer_SyslogTest::main') {
  128. Zend_Log_Writer_SyslogTest::main();
  129. }