PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/system/tests/kohana/LogTest.php

https://bitbucket.org/sklyarov_ivan/trap
PHP | 111 lines | 44 code | 17 blank | 50 comment | 0 complexity | 79abea64fbc2694c3730e71abd57b7c0 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
  2. /**
  3. * Tests Kohana Logging API
  4. *
  5. * @group kohana
  6. * @group kohana.core
  7. * @group kohana.core.logging
  8. *
  9. * @package Kohana
  10. * @category Tests
  11. * @author Kohana Team
  12. * @author Matt Button <matthew@sigswitch.com>
  13. * @copyright (c) 2008-2012 Kohana Team
  14. * @license http://kohanaframework.org/license
  15. */
  16. class Kohana_LogTest extends Unittest_TestCase
  17. {
  18. /**
  19. * Tests that when a new logger is created the list of messages is initially
  20. * empty
  21. *
  22. * @test
  23. * @covers Log
  24. */
  25. public function test_messages_is_initially_empty()
  26. {
  27. $logger = new Log;
  28. $this->assertAttributeSame(array(), '_messages', $logger);
  29. }
  30. /**
  31. * Tests that when a new logger is created the list of writers is initially
  32. * empty
  33. *
  34. * @test
  35. * @covers Log
  36. */
  37. public function test_writers_is_initially_empty()
  38. {
  39. $logger = new Log;
  40. $this->assertAttributeSame(array(), '_writers', $logger);
  41. }
  42. /**
  43. * Test that attaching a log writer using an array of levels adds it to the array of log writers
  44. *
  45. * @TODO Is this test too specific?
  46. *
  47. * @test
  48. * @covers Log::attach
  49. */
  50. public function test_attach_attaches_log_writer_and_returns_this()
  51. {
  52. $logger = new Log;
  53. $writer = $this->getMockForAbstractClass('Log_Writer');
  54. $this->assertSame($logger, $logger->attach($writer));
  55. $this->assertAttributeSame(
  56. array(spl_object_hash($writer) => array('object' => $writer, 'levels' => array())),
  57. '_writers',
  58. $logger
  59. );
  60. }
  61. /**
  62. * Test that attaching a log writer using a min/max level adds it to the array of log writers
  63. *
  64. * @TODO Is this test too specific?
  65. *
  66. * @test
  67. * @covers Log::attach
  68. */
  69. public function test_attach_attaches_log_writer_min_max_and_returns_this()
  70. {
  71. $logger = new Log;
  72. $writer = $this->getMockForAbstractClass('Log_Writer');
  73. $this->assertSame($logger, $logger->attach($writer, Log::NOTICE, Log::CRITICAL));
  74. $this->assertAttributeSame(
  75. array(spl_object_hash($writer) => array('object' => $writer, 'levels' => array(Log::CRITICAL, Log::ERROR, Log::WARNING, Log::NOTICE))),
  76. '_writers',
  77. $logger
  78. );
  79. }
  80. /**
  81. * When we call detach() we expect the specified log writer to be removed
  82. *
  83. * @test
  84. * @covers Log::detach
  85. */
  86. public function test_detach_removes_log_writer_and_returns_this()
  87. {
  88. $logger = new Log;
  89. $writer = $this->getMockForAbstractClass('Log_Writer');
  90. $logger->attach($writer);
  91. $this->assertSame($logger, $logger->detach($writer));
  92. $this->assertAttributeSame(array(), '_writers', $logger);
  93. }
  94. }