PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Log/Filter/PriorityTest.php

https://bitbucket.org/ksekar/campus
PHP | 109 lines | 64 code | 13 blank | 32 comment | 3 complexity | f43abb114222d6084dcce91fcb28f6e6 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: PriorityTest.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Log_Filter_PriorityTest::main');
  24. }
  25. /** Zend_Log */
  26. require_once 'Zend/Log.php';
  27. /** Zend_Log_Filter_Priority */
  28. require_once 'Zend/Log/Filter/Priority.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_PriorityTest 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 testComparisonDefaultsToLessThanOrEqual()
  45. {
  46. // accept at or below priority 2
  47. $filter = new Zend_Log_Filter_Priority(2);
  48. $this->assertTrue($filter->accept(array('priority' => 2)));
  49. $this->assertTrue($filter->accept(array('priority' => 1)));
  50. $this->assertFalse($filter->accept(array('priority' => 3)));
  51. }
  52. public function testComparisonOperatorCanBeChanged()
  53. {
  54. // accept above priority 2
  55. $filter = new Zend_Log_Filter_Priority(2, '>');
  56. $this->assertTrue($filter->accept(array('priority' => 3)));
  57. $this->assertFalse($filter->accept(array('priority' => 2)));
  58. $this->assertFalse($filter->accept(array('priority' => 1)));
  59. }
  60. public function testConstructorThrowsOnInvalidPriority()
  61. {
  62. try {
  63. new Zend_Log_Filter_Priority('foo');
  64. $this->fail();
  65. } catch (Exception $e) {
  66. $this->assertType('Zend_Log_Exception', $e);
  67. $this->assertRegExp('/must be an integer/i', $e->getMessage());
  68. }
  69. }
  70. public function testFactory()
  71. {
  72. $cfg = array('log' => array('memory' => array(
  73. 'writerName' => "Mock",
  74. 'filterName' => "Priority",
  75. 'filterParams' => array(
  76. 'priority' => "Zend_Log::CRIT",
  77. 'operator' => "<="
  78. ),
  79. )));
  80. $logger = Zend_Log::factory($cfg['log']);
  81. $this->assertTrue($logger instanceof Zend_Log);
  82. try {
  83. $logger = Zend_Log::factory(array('Null' => array(
  84. 'writerName' => 'Mock',
  85. 'filterName' => 'Priority',
  86. 'filterParams' => array(),
  87. )));
  88. } catch(Exception $e) {
  89. $this->assertType('Zend_Log_Exception', $e);
  90. $this->assertRegExp('/must be an integer/', $e->getMessage());
  91. }
  92. }
  93. }
  94. if (PHPUnit_MAIN_METHOD == 'Zend_Log_Filter_PriorityTest::main') {
  95. Zend_Log_Filter_PriorityTest::main();
  96. }