PageRenderTime 239ms CodeModel.GetById 110ms app.highlight 4ms RepoModel.GetById 77ms app.codeStats 0ms

/system/tests/kohana/LogTest.php

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