LogTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  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) Kohana Team
  14. * @license https://koseven.ga/LICENSE.md
  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([], '_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([], '_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. [spl_object_hash($writer) => ['object' => $writer, 'levels' => []]],
  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. [spl_object_hash($writer) => ['object' => $writer, 'levels' => [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([], '_writers', $logger);
  93. }
  94. }