PageRenderTime 57ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Log/Filter/ChainingTest.php

https://bitbucket.org/ksekar/campus
PHP | 101 lines | 54 code | 16 blank | 31 comment | 3 complexity | 9f02382ed56e512be3e96e4073ed0953 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: ChainingTest.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Log_Filter_ChainingTest::main');
  24. }
  25. /** Zend_Log */
  26. require_once 'Zend/Log.php';
  27. /** Zend_Log_Writer_Stream */
  28. require_once 'Zend/Log/Writer/Stream.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Log
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Log
  36. */
  37. class Zend_Log_Filter_ChainingTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. public function setUp()
  45. {
  46. $this->log = fopen('php://memory', 'w');
  47. $this->logger = new Zend_Log();
  48. $this->logger->addWriter(new Zend_Log_Writer_Stream($this->log));
  49. }
  50. public function tearDown()
  51. {
  52. fclose($this->log);
  53. }
  54. public function testFilterAllWriters()
  55. {
  56. // filter out anything above a WARNing for all writers
  57. $this->logger->addFilter(Zend_Log::WARN);
  58. $this->logger->info($ignored = 'info-message-ignored');
  59. $this->logger->warn($logged = 'warn-message-logged');
  60. rewind($this->log);
  61. $logdata = stream_get_contents($this->log);
  62. $this->assertNotContains($ignored, $logdata);
  63. $this->assertContains($logged, $logdata);
  64. }
  65. public function testFilterOnSpecificWriter()
  66. {
  67. $log2 = fopen('php://memory', 'w');
  68. $writer2 = new Zend_Log_Writer_Stream($log2);
  69. $writer2->addFilter(Zend_Log::ERR);
  70. $this->logger->addWriter($writer2);
  71. $this->logger->warn($warn = 'warn-message');
  72. $this->logger->err($err = 'err-message');
  73. rewind($this->log);
  74. $logdata = stream_get_contents($this->log);
  75. $this->assertContains($warn, $logdata);
  76. $this->assertContains($err, $logdata);
  77. rewind($log2);
  78. $logdata = stream_get_contents($log2);
  79. $this->assertContains($err, $logdata);
  80. $this->assertNotContains($warn, $logdata);
  81. }
  82. }
  83. if (PHPUnit_MAIN_METHOD == 'Zend_Log_Filter_ChainingTest::main') {
  84. Zend_Log_Filter_ChainingTest::main();
  85. }