PageRenderTime 71ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Log/Filter/MessageTest.php

https://bitbucket.org/ksekar/campus
PHP | 99 lines | 58 code | 11 blank | 30 comment | 3 complexity | e560802e91407c657015b8bc333393cf 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: MessageTest.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Log_Filter_MessageTest::main');
  24. }
  25. /** Zend_Log */
  26. require_once 'Zend/Log.php';
  27. /** Zend_Log_Filter_Message */
  28. require_once 'Zend/Log/Filter/Message.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_MessageTest 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 testMessageFilterRecognizesInvalidRegularExpression()
  45. {
  46. try {
  47. $filter = new Zend_Log_Filter_Message('invalid regexp');
  48. $this->fail();
  49. } catch (Exception $e) {
  50. $this->assertType('Zend_Log_Exception', $e);
  51. $this->assertRegexp('/invalid reg/i', $e->getMessage());
  52. }
  53. }
  54. public function testMessageFilter()
  55. {
  56. $filter = new Zend_Log_Filter_Message('/accept/');
  57. $this->assertTrue($filter->accept(array('message' => 'foo accept bar')));
  58. $this->assertFalse($filter->accept(array('message' => 'foo reject bar')));
  59. }
  60. public function testFactory()
  61. {
  62. $cfg = array('log' => array('memory' => array(
  63. 'writerName' => "Mock",
  64. 'filterName' => "Message",
  65. 'filterParams' => array(
  66. 'regexp' => "/42/"
  67. ),
  68. )));
  69. $logger = Zend_Log::factory($cfg['log']);
  70. $this->assertTrue($logger instanceof Zend_Log);
  71. }
  72. public function testFactoryWithConfig()
  73. {
  74. require_once 'Zend/Config.php';
  75. $config = new Zend_Config(array('log' => array('memory' => array(
  76. 'writerName' => "Mock",
  77. 'filterName' => "Message",
  78. 'filterParams' => array(
  79. 'regexp' => "/42/"
  80. ),
  81. ))));
  82. $filter = Zend_Log_Filter_Message::factory($config->log->memory->filterParams);
  83. $this->assertTrue($filter instanceof Zend_Log_Filter_Message);
  84. }
  85. }
  86. if (PHPUnit_MAIN_METHOD == 'Zend_Log_Filter_MessageTest::main') {
  87. Zend_Log_Filter_MessageTest::main();
  88. }