PageRenderTime 49ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/system/tests/kohana/LogTest.php

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