Author: marco
Date: Sat Jan 14 09:01:58 2006
New Revision: 369054

URL: http://svn.apache.org/viewcvs?rev=369054&view=rev
Log:
spi subpackage test cases

Added:
    logging/log4php/trunk/src/php5/tests/spi/AllTests.php
    logging/log4php/trunk/src/php5/tests/spi/LoggerLoggingEventTestCase.php

Added: logging/log4php/trunk/src/php5/tests/spi/AllTests.php
URL: 
http://svn.apache.org/viewcvs/logging/log4php/trunk/src/php5/tests/spi/AllTests.php?rev=369054&view=auto
==============================================================================
--- logging/log4php/trunk/src/php5/tests/spi/AllTests.php (added)
+++ logging/log4php/trunk/src/php5/tests/spi/AllTests.php Sat Jan 14 09:01:58 
2006
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * @category   tests   
+ * @package    log4php
+ * @author     Marco Vassura
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, 
Version 2.0
+ * @version    SVN: $Id$
+ * @link       http://logging.apache.org/log4php
+ */
+
+/** */
+if (!defined('PHPUnit2_MAIN_METHOD')) {
+    define('PHPUnit2_MAIN_METHOD', 'spi_AllTests::main');
+}
+if (!defined('LOG4PHP_DIR')) {
+    define('LOG4PHP_DIR', '../log4php');
+}
+
+if (!defined('LOG4PHP_DEFAULT_INIT_OVERRIDE')) {
+    define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true);
+}
+
+require_once('PHPUnit2/Framework/TestSuite.php');
+require_once('PHPUnit2/TextUI/TestRunner.php');
+
+require_once('spi/LoggerLoggingEventTestCase.php');
+
+class spi_AllTests {
+
+    public static function main() {
+        PHPUnit2_TextUI_TestRunner::run(self::suite());
+    }
+
+    public static function suite() {
+        $suite = new PHPUnit2_Framework_TestSuite('spi');
+
+        $suite->addTestSuite('LoggerLoggingEventTestCase');
+        
+        return $suite;
+    }
+}
+
+if (PHPUnit2_MAIN_METHOD == 'spi_AllTests::main') {
+    spi_AllTests::main();
+}
+?>

Added: logging/log4php/trunk/src/php5/tests/spi/LoggerLoggingEventTestCase.php
URL: 
http://svn.apache.org/viewcvs/logging/log4php/trunk/src/php5/tests/spi/LoggerLoggingEventTestCase.php?rev=369054&view=auto
==============================================================================
--- logging/log4php/trunk/src/php5/tests/spi/LoggerLoggingEventTestCase.php 
(added)
+++ logging/log4php/trunk/src/php5/tests/spi/LoggerLoggingEventTestCase.php Sat 
Jan 14 09:01:58 2006
@@ -0,0 +1,104 @@
+<?php
+
+/**
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * @category   tests
+ * @package    log4php
+ * @subpackage spi
+ * @author     Marco Vassura
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, 
Version 2.0
+ * @version    SVN: $Id$
+ * @link       http://logging.apache.org/log4php
+ */
+
+/**  */
+require_once 'PHPUnit2/Framework/TestCase.php';
+
+require_once LOG4PHP_DIR.'/appenders/LoggerAppenderNull.php';
+require_once LOG4PHP_DIR.'/spi/LoggerLoggingEvent.php';
+require_once LOG4PHP_DIR.'/LoggerHierarchy.php';
+require_once LOG4PHP_DIR.'/LoggerLayout.php';
+
+class LoggerLoggingEventTestCaseAppender extends LoggerAppenderNull {
+       
+       protected $requiresLayout = true;
+
+       protected function append($event) {
+               $this->layout->format($event);
+       }
+
+}
+
+class LoggerLoggingEventTestCaseLayout extends LoggerLayout { 
+       
+       public function activateOptions() {
+               return;
+       }
+       
+       public function format($event) {
+               LoggerLoggingEventTestCase::$locationInfo = 
$event->getLocationInformation();
+       }
+}
+
+class LoggerLoggingEventTestCase extends PHPUnit2_Framework_TestCase {
+       
+       public static $locationInfo;
+
+       public function testConstructWithLoggerName() {
+               $l = LoggerLevel :: getLevelDebug();
+               $e = new LoggerLoggingEvent('fqcn', 'TestLogger', $l, 'test');
+               $this->assertEquals($e->getLoggerName(), 'TestLogger');
+       }
+
+       public function testConstructWithTimestamp() {
+               $l = LoggerLevel :: getLevelDebug();
+               $timestamp = microtime(true);
+               $e = new LoggerLoggingEvent('fqcn', 'TestLogger', $l, 'test', 
$timestamp);
+               $this->assertEquals($e->getTimeStamp(), $timestamp);
+       }
+
+       public function testGetStartTime() {
+               $time = LoggerLoggingEvent :: getStartTime();
+               $this->assertType('double', $time);
+               $time2 = LoggerLoggingEvent :: getStartTime();
+               $this->assertEquals($time, $time2);
+       }
+
+       public function testGetLocationInformation() {
+               $hierarchy = LoggerHierarchy :: singleton();
+               $root = $hierarchy->getRootLogger();
+
+               $a = new LoggerLoggingEventTestCaseAppender('A1');
+               $a->setLayout( new LoggerLoggingEventTestCaseLayout() );
+               $root->addAppender($a);
+               
+               $logger = $hierarchy->getLogger('test');
+
+               $line = __LINE__; $logger->debug('test');
+               $hierarchy->shutdown();
+               
+               $li = self::$locationInfo;
+               
+               $this->assertEquals($li->getClassName(), get_class($this));
+               $this->assertEquals($li->getFileName(), __FILE__);
+               $this->assertEquals($li->getLineNumber(), $line);
+               $this->assertEquals($li->getMethodName(), __FUNCTION__);
+
+       }
+
+}
+?>
+


Reply via email to