You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ih...@apache.org on 2013/11/28 17:03:37 UTC
[07/43] LOG4PHP-121: Reorganized classes into namespaces
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerAppenderTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerAppenderTest.php b/src/test/php/LoggerAppenderTest.php
deleted file mode 100644
index 9b5aac8..0000000
--- a/src/test/php/LoggerAppenderTest.php
+++ /dev/null
@@ -1,173 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group appenders
- */
-class LoggerAppenderTest extends PHPUnit_Framework_TestCase {
-
- public function testThreshold() {
- $appender = new LoggerAppenderEcho("LoggerAppenderTest");
-
- $layout = new LoggerLayoutSimple();
- $appender->setLayout($layout);
-
- $warn = LoggerLevel::getLevelWarn();
- $appender->setThreshold($warn);
- $appender->activateOptions();
-
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelFatal(), "testmessage");
- ob_start();
- $appender->doAppend($event);
- $v = ob_get_contents();
- ob_end_clean();
- $e = "FATAL - testmessage" . PHP_EOL;
- self::assertEquals($e, $v);
-
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
- ob_start();
- $appender->doAppend($event);
- $v = ob_get_contents();
- ob_end_clean();
- $e = "ERROR - testmessage" . PHP_EOL;
- self::assertEquals($e, $v);
-
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(), "testmessage");
- ob_start();
- $appender->doAppend($event);
- $v = ob_get_contents();
- ob_end_clean();
- $e = "WARN - testmessage" . PHP_EOL;
- self::assertEquals($e, $v);
-
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelInfo(), "testmessage");
- ob_start();
- $appender->doAppend($event);
- $v = ob_get_contents();
- ob_end_clean();
- $e = "";
- self::assertEquals($e, $v);
-
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(), "testmessage");
- ob_start();
- $appender->doAppend($event);
- $v = ob_get_contents();
- ob_end_clean();
- $e = "";
- self::assertEquals($e, $v);
- }
-
- public function testGetThreshold() {
- $appender = new LoggerAppenderEcho("LoggerAppenderTest");
-
- $layout = new LoggerLayoutSimple();
- $appender->setLayout($layout);
-
- $warn = LoggerLevel::getLevelWarn();
- $appender->setThreshold($warn);
-
- $a = $appender->getThreshold();
- self::assertEquals($warn, $a);
- }
-
- public function testSetStringThreshold() {
- $appender = new LoggerAppenderEcho("LoggerAppenderTest");
-
- $layout = new LoggerLayoutSimple();
- $appender->setLayout($layout);
-
- $warn = LoggerLevel::getLevelWarn();
- $appender->setThreshold('WARN');
- $a = $appender->getThreshold();
- self::assertEquals($warn, $a);
-
- $e = LoggerLevel::getLevelFatal();
- $appender->setThreshold('FATAL');
- $a = $appender->getThreshold();
- self::assertEquals($e, $a);
-
- $e = LoggerLevel::getLevelError();
- $appender->setThreshold('ERROR');
- $a = $appender->getThreshold();
- self::assertEquals($e, $a);
-
- $e = LoggerLevel::getLevelDebug();
- $appender->setThreshold('DEBUG');
- $a = $appender->getThreshold();
- self::assertEquals($e, $a);
-
- $e = LoggerLevel::getLevelInfo();
- $appender->setThreshold('INFO');
- $a = $appender->getThreshold();
- self::assertEquals($e, $a);
- }
-
- public function testSetFilter() {
- $appender = new LoggerAppenderEcho("LoggerAppenderTest");
-
- $layout = new LoggerLayoutSimple();
- $appender->setLayout($layout);
-
- $filter = new LoggerFilterDenyAll();
- $appender->addFilter($filter);
-
- $filter2 = new LoggerFilterLevelMatch();
- $appender->addFilter($filter2);
-
- $first = $appender->getFilter();
- self::assertEquals($first, $filter);
-
- $next = $first->getNext();
- self::assertEquals($next, $filter2);
-
- $appender->clearFilters();
- $nullfilter = $appender->getFilter();
- self::assertNull($nullfilter);
- }
-
- public function testInstanciateWithLayout() {
- $appender = new LoggerAppenderEcho("LoggerAppenderTest");
-
- $expected = "LoggerLayoutSimple";
- $actual = $appender->getLayout();
- $this->assertInstanceof($expected, $actual);
- }
-
- public function testOverwriteLayout() {
- $layout = new LoggerLayoutSimple();
- $appender = new LoggerAppenderEcho("LoggerAppenderTest");
- $appender->setLayout($layout);
-
- $actual = $appender->getLayout();
- $this->assertEquals($layout, $actual);
- }
-
- public function testRequiresNoLayout() {
- $appender = new LoggerAppenderNull("LoggerAppenderTest");
-
- $actual = $appender->getLayout();
- $this->assertNull($actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerConfiguratorTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerConfiguratorTest.php b/src/test/php/LoggerConfiguratorTest.php
deleted file mode 100644
index e8ff410..0000000
--- a/src/test/php/LoggerConfiguratorTest.php
+++ /dev/null
@@ -1,452 +0,0 @@
-<?php
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-
-class CostumDefaultRenderer implements LoggerRenderer {
- public function render($o) { }
-}
-
-
-/**
- *
- * @group configurators
- *
- */
- class LoggerConfiguratorTest extends PHPUnit_Framework_TestCase
- {
- /** Reset configuration after each test. */
- public function setUp() {
- Logger::resetConfiguration();
- }
- /** Reset configuration after each test. */
- public function tearDown() {
- Logger::resetConfiguration();
- }
-
- /** Check default setup. */
- public function testDefaultConfig() {
- Logger::configure();
-
- $actual = Logger::getCurrentLoggers();
- $expected = array();
- $this->assertSame($expected, $actual);
-
- $appenders = Logger::getRootLogger()->getAllAppenders();
- $this->assertInternalType('array', $appenders);
- $this->assertEquals(count($appenders), 1);
-
- $names = array_keys($appenders);
- $this->assertSame('default', $names[0]);
-
- $appender = array_shift($appenders);
- $this->assertInstanceOf('LoggerAppenderEcho', $appender);
- $this->assertSame('default', $appender->getName());
-
- $layout = $appender->getLayout();
- $this->assertInstanceOf('LoggerLayoutSimple', $layout);
-
- $root = Logger::getRootLogger();
- $appenders = $root->getAllAppenders();
- $this->assertInternalType('array', $appenders);
- $this->assertEquals(count($appenders), 1);
-
- $actual = $root->getLevel();
- $expected = LoggerLevel::getLevelDebug();
- $this->assertEquals($expected, $actual);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid configuration param given. Reverting to default configuration.
- */
- public function testInputIsInteger() {
- Logger::configure(12345);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage log4php: Configuration failed. Unsupported configuration file extension: yml
- */
- public function testYAMLFile() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/config.yml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid configuration provided for appender
- */
- public function testAppenderConfigNotArray() {
- $hierachyMock = $this->getMock('LoggerHierarchy', array(), array(), '', false);
-
- $config = array(
- 'appenders' => array(
- 'default',
- ),
- );
-
- $configurator = new LoggerConfiguratorDefault();
- $configurator->configure($hierachyMock, $config);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage No class given for appender
- */
- public function testNoAppenderClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_no_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid class [unknownClass] given for appender [foo]. Class does not exist. Skipping appender definition.
- */
- public function testNotExistingAppenderClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_not_existing_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid class [stdClass] given for appender [foo]. Not a valid LoggerAppender class. Skipping appender definition.
- */
- public function testInvalidAppenderClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_invalid_appender_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Nonexistant filter class [Foo] specified on appender [foo]. Skipping filter definition.
- */
- public function testNotExistingAppenderFilterClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_not_existing_filter_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Nonexistant option [fooParameter] specified on [LoggerFilterStringMatch]. Skipping.
- */
- public function testInvalidAppenderFilterParamter() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_invalid_filter_parameters.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid filter class [stdClass] sepcified on appender [foo]. Skipping filter definition.
- */
- public function testInvalidAppenderFilterClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_invalid_filter_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Nonexistant layout class [Foo] specified for appender [foo]. Reverting to default layout.
- */
- public function testNotExistingAppenderLayoutClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_not_existing_layout_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid layout class [stdClass] sepcified for appender [foo]. Reverting to default layout.
- */
- public function testInvalidAppenderLayoutClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_invalid_layout_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Layout class not specified for appender [foo]. Reverting to default layout.
- */
- public function testNoAppenderLayoutClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/appenders/config_no_layout_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Failed adding renderer. Rendering class [stdClass] does not implement the LoggerRenderer interface.
- */
- public function testInvalidRenderingClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/renderers/config_invalid_rendering_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Rendering class not specified. Skipping renderer definition.
- */
- public function testNoRenderingClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/renderers/config_no_rendering_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Rendered class not specified. Skipping renderer definition.
- */
- public function testNoRenderedClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/renderers/config_no_rendered_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Failed adding renderer. Rendering class [DoesNotExistRenderer] not found.
- */
- public function testNotExistingRenderingClassSet() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/renderers/config_not_existing_rendering_class.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid additivity value [4711] specified for logger [myLogger].
- */
- public function testInvalidLoggerAddivity() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/loggers/config_invalid_additivity.xml');
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Nonexistnant appender [unknownAppender] linked to logger [myLogger].
- */
- public function testNotExistingLoggerAppendersClass() {
- Logger::configure(PHPUNIT_CONFIG_DIR . '/loggers/config_not_existing_appenders.xml');
- }
-
- /**
- * Test that an error is reported when config file is not found.
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage log4php: Configuration failed. File not found
- */
- public function testNonexistantFile() {
- Logger::configure('hopefully/this/path/doesnt/exist/config.xml');
-
- }
-
- /** Test correct fallback to the default configuration. */
- public function testNonexistantFileFallback() {
- @Logger::configure('hopefully/this/path/doesnt/exist/config.xml');
- $this->testDefaultConfig();
- }
-
- public function testAppendersWithLayout() {
- $config = Logger::configure(array(
- 'rootLogger' => array(
- 'appenders' => array('app1', 'app2')
- ),
- 'loggers' => array(
- 'myLogger' => array(
- 'appenders' => array('app1'),
- 'additivity'=> true
- )
- ),
- 'renderers' => array(
- array('renderedClass' => 'stdClass', 'renderingClass' => 'LoggerRendererDefault')
- ),
- 'appenders' => array(
- 'app1' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutSimple'
- ),
- 'params' => array(
- 'htmlLineBreaks' => false
- )
- ),
- 'app2' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutPattern',
- 'params' => array(
- 'conversionPattern' => 'message: %m%n'
- )
- ),
- 'filters' => array(
- array(
- 'class' => 'LoggerFilterStringMatch',
- 'params'=> array(
- 'stringToMatch' => 'foo',
- 'acceptOnMatch' => false
- )
- )
- )
- ),
- )
- ));
-
- ob_start();
- Logger::getRootLogger()->info('info');
- $actual = ob_get_contents();
- ob_end_clean();
-
- $expected = "INFO - info" . PHP_EOL . "message: info" . PHP_EOL;
- $this->assertSame($expected, $actual);
- }
-
- public function testThreshold()
- {
- Logger::configure(array(
- 'threshold' => 'WARN',
- 'rootLogger' => array(
- 'appenders' => array('default')
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- ),
- )
- ));
-
- $actual = Logger::getHierarchy()->getThreshold();
- $expected = LoggerLevel::getLevelWarn();
-
- self::assertSame($expected, $actual);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid threshold value [FOO] specified. Ignoring threshold definition.
- */
- public function testInvalidThreshold()
- {
- Logger::configure(array(
- 'threshold' => 'FOO',
- 'rootLogger' => array(
- 'appenders' => array('default')
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- ),
- )
- ));
- }
-
- public function testAppenderThreshold()
- {
- Logger::configure(array(
- 'rootLogger' => array(
- 'appenders' => array('default')
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'threshold' => 'INFO'
- ),
- )
- ));
-
- $actual = Logger::getRootLogger()->getAppender('default')->getThreshold();
- $expected = LoggerLevel::getLevelInfo();
-
- self::assertSame($expected, $actual);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid threshold value [FOO] specified for appender [default]. Ignoring threshold definition.
- */
- public function testAppenderInvalidThreshold()
- {
- Logger::configure(array(
- 'rootLogger' => array(
- 'appenders' => array('default')
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'threshold' => 'FOO'
- ),
- )
- ));
- }
-
- public function testLoggerThreshold()
- {
- Logger::configure(array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- 'level' => 'ERROR'
- ),
- 'loggers' => array(
- 'default' => array(
- 'appenders' => array('default'),
- 'level' => 'WARN'
- )
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- ),
- )
- ));
-
- // Check root logger
- $actual = Logger::getRootLogger()->getLevel();
- $expected = LoggerLevel::getLevelError();
- self::assertSame($expected, $actual);
-
- // Check default logger
- $actual = Logger::getLogger('default')->getLevel();
- $expected = LoggerLevel::getLevelWarn();
- self::assertSame($expected, $actual);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid level value [FOO] specified for logger [default]. Ignoring level definition.
- */
- public function testInvalidLoggerThreshold()
- {
- Logger::configure(array(
- 'loggers' => array(
- 'default' => array(
- 'appenders' => array('default'),
- 'level' => 'FOO'
- )
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- ),
- )
- ));
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Invalid level value [FOO] specified for logger [root]. Ignoring level definition.
- */
- public function testInvalidRootLoggerThreshold()
- {
- Logger::configure(array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- 'level' => 'FOO'
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- ),
- )
- ));
- }
- }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerExceptionTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerExceptionTest.php b/src/test/php/LoggerExceptionTest.php
deleted file mode 100644
index 5cb9978..0000000
--- a/src/test/php/LoggerExceptionTest.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-class MyException extends Exception { }
-
-/**
- * @group main
- */
-class LoggerExceptionTest extends PHPUnit_Framework_TestCase {
- /**
- * @expectedException LoggerException
- */
- public function testMessage() {
- try {
- throw new LoggerException("TEST");
- } catch (LoggerException $e) {
- self::assertEquals("TEST", $e->getMessage());
- throw $e;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerFilterTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerFilterTest.php b/src/test/php/LoggerFilterTest.php
deleted file mode 100644
index 3d32445..0000000
--- a/src/test/php/LoggerFilterTest.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 filters
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-class MyFilter extends LoggerFilter {}
-
-/**
- * @group filters
- */
-class LoggerFilterTest extends PHPUnit_Framework_TestCase {
-
- public function testDecide() {
- $filter = new MyFilter();
- // activateOptions is empty, but should at least throw no exeception
- $filter->activateOptions();
- $eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
- $eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(), "testmessage");
- $eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(), "testmessage");
-
- $result = $filter->decide($eventError);
- self::assertEquals($result, LoggerFilter::NEUTRAL);
-
- $result = $filter->decide($eventDebug);
- self::assertEquals($result, LoggerFilter::NEUTRAL);
-
- $result = $filter->decide($eventWarn);
- self::assertEquals($result, LoggerFilter::NEUTRAL);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerHierarchyTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerHierarchyTest.php b/src/test/php/LoggerHierarchyTest.php
deleted file mode 100644
index dabc4bc..0000000
--- a/src/test/php/LoggerHierarchyTest.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerHierarchyTest extends PHPUnit_Framework_TestCase {
-
- private $hierarchy;
-
- protected function setUp() {
- $this->hierarchy = new LoggerHierarchy(new LoggerRoot());
- }
-
- public function testResetConfiguration() {
- $root = $this->hierarchy->getRootLogger();
- $appender = new LoggerAppenderConsole('A1');
- $root->addAppender($appender);
-
- $logger = $this->hierarchy->getLogger('test');
- self::assertEquals(1, count($this->hierarchy->getCurrentLoggers()));
-
- $this->hierarchy->resetConfiguration();
- self::assertEquals(LoggerLevel::getLevelDebug(), $root->getLevel());
- self::assertEquals(LoggerLevel::getLevelAll(), $this->hierarchy->getThreshold());
- self::assertEquals(1, count($this->hierarchy->getCurrentLoggers()));
-
- foreach($this->hierarchy->getCurrentLoggers() as $logger) {
- self::assertNull($logger->getLevel());
- self::assertTrue($logger->getAdditivity());
- self::assertEquals(0, count($logger->getAllAppenders()), 0);
- }
- }
-
- public function testSettingParents() {
- $hierarchy = $this->hierarchy;
- $loggerDE = $hierarchy->getLogger("de");
- $root = $loggerDE->getParent();
- self::assertEquals('root', $root->getName());
-
- $loggerDEBLUB = $hierarchy->getLogger("de.blub");
- self::assertEquals('de.blub', $loggerDEBLUB->getName());
- $p = $loggerDEBLUB->getParent();
- self::assertEquals('de', $p->getName());
-
- $loggerDEBLA = $hierarchy->getLogger("de.bla");
- $p = $loggerDEBLA->getParent();
- self::assertEquals('de', $p->getName());
-
- $logger3 = $hierarchy->getLogger("de.bla.third");
- $p = $logger3->getParent();
- self::assertEquals('de.bla', $p->getName());
-
- $p = $p->getParent();
- self::assertEquals('de', $p->getName());
- }
-
- public function testExists() {
- $hierarchy = $this->hierarchy;
- $logger = $hierarchy->getLogger("de");
-
- self::assertTrue($hierarchy->exists("de"));
-
- $logger = $hierarchy->getLogger("de.blub");
- self::assertTrue($hierarchy->exists("de.blub"));
- self::assertTrue($hierarchy->exists("de"));
-
- $logger = $hierarchy->getLogger("de.de");
- self::assertTrue($hierarchy->exists("de.de"));
- }
-
- public function testClear() {
- $hierarchy = $this->hierarchy;
- $logger = $hierarchy->getLogger("de");
- self::assertTrue($hierarchy->exists("de"));
- $hierarchy->clear();
- self::assertFalse($hierarchy->exists("de"));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerLevelTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerLevelTest.php b/src/test/php/LoggerLevelTest.php
deleted file mode 100644
index 283c9c5..0000000
--- a/src/test/php/LoggerLevelTest.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerLevelTest extends PHPUnit_Framework_TestCase {
-
- protected function doTestLevel($level, $code, $str, $syslog) {
- self::assertTrue($level instanceof LoggerLevel);
- self::assertEquals($level->toInt(), $code);
- self::assertEquals($level->toString(), $str);
- self::assertEquals($level->getSyslogEquivalent(), $syslog);
- }
-
- public function testLevelOff() {
- $this->doTestLevel(LoggerLevel::getLevelOff(), LoggerLevel::OFF, 'OFF', LOG_ALERT);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::OFF), LoggerLevel::OFF, 'OFF', LOG_ALERT);
- $this->doTestLevel(LoggerLevel::toLevel('OFF'), LoggerLevel::OFF, 'OFF', LOG_ALERT);
- }
-
- public function testLevelFatal() {
- $this->doTestLevel(LoggerLevel::getLevelFatal(), LoggerLevel::FATAL, 'FATAL', LOG_ALERT);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::FATAL), LoggerLevel::FATAL, 'FATAL', LOG_ALERT);
- $this->doTestLevel(LoggerLevel::toLevel('FATAL'), LoggerLevel::FATAL, 'FATAL', LOG_ALERT);
- }
-
- public function testLevelError() {
- $this->doTestLevel(LoggerLevel::getLevelError(), LoggerLevel::ERROR, 'ERROR', LOG_ERR);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::ERROR), LoggerLevel::ERROR, 'ERROR', LOG_ERR);
- $this->doTestLevel(LoggerLevel::toLevel('ERROR'), LoggerLevel::ERROR, 'ERROR', LOG_ERR);
- }
-
- public function testLevelWarn() {
- $this->doTestLevel(LoggerLevel::getLevelWarn(), LoggerLevel::WARN, 'WARN', LOG_WARNING);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::WARN), LoggerLevel::WARN, 'WARN', LOG_WARNING);
- $this->doTestLevel(LoggerLevel::toLevel('WARN'), LoggerLevel::WARN, 'WARN', LOG_WARNING);
- }
-
- public function testLevelInfo() {
- $this->doTestLevel(LoggerLevel::getLevelInfo(), LoggerLevel::INFO, 'INFO', LOG_INFO);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::INFO), LoggerLevel::INFO, 'INFO', LOG_INFO);
- $this->doTestLevel(LoggerLevel::toLevel('INFO'), LoggerLevel::INFO, 'INFO', LOG_INFO);
- }
-
- public function testLevelDebug() {
- $this->doTestLevel(LoggerLevel::getLevelDebug(), LoggerLevel::DEBUG, 'DEBUG', LOG_DEBUG);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::DEBUG), LoggerLevel::DEBUG, 'DEBUG', LOG_DEBUG);
- $this->doTestLevel(LoggerLevel::toLevel('DEBUG'), LoggerLevel::DEBUG, 'DEBUG', LOG_DEBUG);
- }
-
- public function testLevelTrace() {
- $this->doTestLevel(LoggerLevel::getLevelTrace(), LoggerLevel::TRACE, 'TRACE', LOG_DEBUG);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::TRACE), LoggerLevel::TRACE, 'TRACE', LOG_DEBUG);
- $this->doTestLevel(LoggerLevel::toLevel('TRACE'), LoggerLevel::TRACE, 'TRACE', LOG_DEBUG);
- }
-
- public function testLevelAll() {
- $this->doTestLevel(LoggerLevel::getLevelAll(), LoggerLevel::ALL, 'ALL', LOG_DEBUG);
- $this->doTestLevel(LoggerLevel::toLevel(LoggerLevel::ALL), LoggerLevel::ALL, 'ALL', LOG_DEBUG);
- $this->doTestLevel(LoggerLevel::toLevel('ALL'), LoggerLevel::ALL, 'ALL', LOG_DEBUG);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerLoggingEventTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerLoggingEventTest.php b/src/test/php/LoggerLoggingEventTest.php
deleted file mode 100644
index 3f1ea3e..0000000
--- a/src/test/php/LoggerLoggingEventTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-class LoggerLoggingEventTestCaseAppender extends LoggerAppenderNull {
-
- protected $requiresLayout = true;
-
- public function append(LoggerLoggingEvent $event) {
- $this->layout->format($event);
- }
-
-}
-
-class LoggerLoggingEventTestCaseLayout extends LoggerLayout {
-
- public function activateOptions() {
- return;
- }
-
- public function format(LoggerLoggingEvent $event) {
- LoggerLoggingEventTest::$locationInfo = $event->getLocationInformation();
- LoggerLoggingEventTest::$throwableInfo = $event->getThrowableInformation();
- }
-}
-
-/**
- * @group main
- */
-class LoggerLoggingEventTest extends PHPUnit_Framework_TestCase {
-
- public static $locationInfo;
- public static $throwableInfo;
-
- public function testConstructWithLoggerName() {
- $l = LoggerLevel :: getLevelDebug();
- $e = new LoggerLoggingEvent('fqcn', 'TestLogger', $l, 'test');
- self::assertEquals($e->getLoggerName(), 'TestLogger');
- }
-
- public function testConstructWithTimestamp() {
- $l = LoggerLevel :: getLevelDebug();
- $timestamp = microtime(true);
- $e = new LoggerLoggingEvent('fqcn', 'TestLogger', $l, 'test', $timestamp);
- self::assertEquals($e->getTimeStamp(), $timestamp);
- }
-
- public function testGetStartTime() {
- $time = LoggerLoggingEvent :: getStartTime();
- self::assertInternalType('float', $time);
- $time2 = LoggerLoggingEvent :: getStartTime();
- self::assertEquals($time, $time2);
- }
-
- public function testGetLocationInformation() {
- $hierarchy = Logger::getHierarchy();
- $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;
-
- self::assertEquals($li->getClassName(), get_class($this));
- self::assertEquals($li->getFileName(), __FILE__);
- self::assertEquals($li->getLineNumber(), $line);
- self::assertEquals($li->getMethodName(), __FUNCTION__);
-
- }
-
- public function testGetThrowableInformation1() {
- $hierarchy = Logger::getHierarchy();
- $root = $hierarchy->getRootLogger();
-
- $a = new LoggerLoggingEventTestCaseAppender('A1');
- $a->setLayout( new LoggerLoggingEventTestCaseLayout() );
- $root->addAppender($a);
-
- $logger = $hierarchy->getLogger('test');
- $logger->debug('test');
- $hierarchy->shutdown();
-
- $ti = self::$throwableInfo;
-
- self::assertEquals($ti, null);
- }
-
- public function testGetThrowableInformation2() {
- $hierarchy = Logger::getHierarchy();
- $root = $hierarchy->getRootLogger();
-
- $a = new LoggerLoggingEventTestCaseAppender('A1');
- $a->setLayout( new LoggerLoggingEventTestCaseLayout() );
- $root->addAppender($a);
-
- $ex = new Exception('Message1');
- $logger = $hierarchy->getLogger('test');
- $logger->debug('test', $ex);
- $hierarchy->shutdown();
-
- $ti = self::$throwableInfo;
-
- self::assertTrue($ti instanceof LoggerThrowableInformation);
-
- $result = $ti->getStringRepresentation();
- self::assertInternalType('array', $result);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerMDCTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerMDCTest.php b/src/test/php/LoggerMDCTest.php
deleted file mode 100644
index 20db81a..0000000
--- a/src/test/php/LoggerMDCTest.php
+++ /dev/null
@@ -1,116 +0,0 @@
-<?php
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerMDCTest extends PHPUnit_Framework_TestCase {
-
- /** A pattern with 1 key. */
- private $pattern1 = "%-5p %c: %X{key1} %m";
-
- /** A pattern with 2 keys. */
- private $pattern2 = "%-5p %c: %X{key1} %X{key2} %m";
-
- /** A pattern with 3 keys (one is numeric). */
- private $pattern3 = "%-5p %c: %X{key1} %X{key2} %X{3} %m";
-
- /** A pattern with a non-existant key. */
- private $pattern4 = "%-5p %c: %X{key_does_not_exist} %m";
-
- /** A pattern without a key. */
- private $pattern5 = "%-5p %c: %X %m";
-
- protected function setUp() {
- LoggerMDC::clear();
- }
-
- protected function tearDown() {
- LoggerMDC::clear();
- }
-
- public function testPatterns() {
-
- // Create some data to test with
- LoggerMDC::put('key1', 'valueofkey1');
- LoggerMDC::put('key2', 'valueofkey2');
- LoggerMDC::put(3, 'valueofkey3');
-
- $expected = array(
- 'key1' => 'valueofkey1',
- 'key2' => 'valueofkey2',
- 3 => 'valueofkey3',
- );
- $actual = LoggerMDC::getMap();
-
- self::assertSame($expected, $actual);
-
- $event = LoggerTestHelper::getInfoEvent("Test message");
-
- // Pattern with 1 key
- $actual = $this->formatEvent($event, $this->pattern1);
- $expected = "INFO test: valueofkey1 Test message";
- self::assertEquals($expected, $actual);
-
- // Pattern with 2 keys
- $actual = $this->formatEvent($event, $this->pattern2);
- $expected = "INFO test: valueofkey1 valueofkey2 Test message";
- self::assertEquals($expected, $actual);
-
- // Pattern with 3 keys (one numeric)
- $actual = $this->formatEvent($event, $this->pattern3);
- $expected = "INFO test: valueofkey1 valueofkey2 valueofkey3 Test message";
- self::assertEquals($expected, $actual);
-
- // Pattern with non-existant key
- $actual = $this->formatEvent($event, $this->pattern4);
- $expected = "INFO test: Test message";
- self::assertEquals($expected, $actual);
-
- // Pattern with an empty key
- $actual = $this->formatEvent($event, $this->pattern5);
- $expected = "INFO test: key1=valueofkey1, key2=valueofkey2, 3=valueofkey3 Test message";
- self::assertEquals($expected, $actual);
-
- // Test key removal
- LoggerMDC::remove('key1');
- $value = LoggerMDC::get('key1');
- self::assertEquals('', $value);
-
- // Pattern with 1 key, now removed
- $actual = $this->formatEvent($event, $this->pattern1);
- $expected = "INFO test: Test message";
- self::assertEquals($expected, $actual);
- }
-
- private function formatEvent($event, $pattern) {
- $layout = new LoggerLayoutPattern();
- $layout->setConversionPattern($pattern);
- $layout->activateOptions();
- return $layout->format($event);
- }
-}
-
-?>
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerNDCTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerNDCTest.php b/src/test/php/LoggerNDCTest.php
deleted file mode 100644
index 380f3ae..0000000
--- a/src/test/php/LoggerNDCTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerNDCTest extends PHPUnit_Framework_TestCase {
-
- public function testItemHandling()
- {
- // Test the empty stack
- self::assertSame('', LoggerNDC::get());
- self::assertSame('', LoggerNDC::peek());
- self::assertSame(0, LoggerNDC::getDepth());
- self::assertSame('', LoggerNDC::pop());
-
- // Add some data to the stack
- LoggerNDC::push('1');
- LoggerNDC::push('2');
- LoggerNDC::push('3');
-
- self::assertSame('1 2 3', LoggerNDC::get());
- self::assertSame('3', LoggerNDC::peek());
- self::assertSame(3, LoggerNDC::getDepth());
-
- // Remove last item
- self::assertSame('3', LoggerNDC::pop());
- self::assertSame('1 2', LoggerNDC::get());
- self::assertSame('2', LoggerNDC::peek());
- self::assertSame(2, LoggerNDC::getDepth());
-
- // Remove all items
- LoggerNDC::remove();
-
- // Test the empty stack
- self::assertSame('', LoggerNDC::get());
- self::assertSame('', LoggerNDC::peek());
- self::assertSame(0, LoggerNDC::getDepth());
- self::assertSame('', LoggerNDC::pop());
- }
-
- public function testMaxDepth()
- {
- // Clear stack; add some testing data
- LoggerNDC::clear();
- LoggerNDC::push('1');
- LoggerNDC::push('2');
- LoggerNDC::push('3');
- LoggerNDC::push('4');
- LoggerNDC::push('5');
- LoggerNDC::push('6');
-
- self::assertSame('1 2 3 4 5 6', LoggerNDC::get());
-
- // Edge case, should not change stack
- LoggerNDC::setMaxDepth(6);
- self::assertSame('1 2 3 4 5 6', LoggerNDC::get());
- self::assertSame(6, LoggerNDC::getDepth());
-
- LoggerNDC::setMaxDepth(3);
- self::assertSame('1 2 3', LoggerNDC::get());
- self::assertSame(3, LoggerNDC::getDepth());
-
- LoggerNDC::setMaxDepth(0);
- self::assertSame('', LoggerNDC::get());
- self::assertSame(0, LoggerNDC::getDepth());
- }
-}
-
-?>
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerReflectionUtilsTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerReflectionUtilsTest.php b/src/test/php/LoggerReflectionUtilsTest.php
deleted file mode 100644
index 5fe9cba..0000000
--- a/src/test/php/LoggerReflectionUtilsTest.php
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-
-class Simple {
- private $name;
- private $male;
-
- public function getName() {
- return $this->name;
- }
-
- public function isMale() {
- return $this->male;
- }
-
- public function setName($name) {
- $this->name = $name;
- }
-
- public function setMale($male) {
- $this->male = $male;
- }
-}
-
-/**
- * @group main
- */
-class LoggerReflectionUtilsTest extends PHPUnit_Framework_TestCase {
-
- public function testSimpleSet() {
- $s = new Simple();
- $ps = new LoggerReflectionUtils($s);
- $ps->setProperty("name", "Joe");
- $ps->setProperty("male", true);
-
- $this->assertEquals($s->isMale(), true);
- $this->assertEquals($s->getName(), 'Joe');
- }
-
- public function testSimpleArraySet() {
- $arr['xxxname'] = 'Joe';
- $arr['xxxmale'] = true;
-
- $s = new Simple();
- $ps = new LoggerReflectionUtils($s);
- $ps->setProperties($arr, "xxx");
-
- $this->assertEquals($s->getName(), 'Joe');
- $this->assertEquals($s->isMale(), true);
- }
-
- public function testStaticArraySet() {
- $arr['xxxname'] = 'Joe';
- $arr['xxxmale'] = true;
-
- $s = new Simple();
- LoggerReflectionUtils::setPropertiesByObject($s,$arr,"xxx");
-
- $this->assertEquals($s->getName(), 'Joe');
- $this->assertEquals($s->isMale(), true);
- }
- public function testCreateObject() {
- $object = LoggerReflectionUtils::createObject('LoggerLayoutSimple');
- $name = get_class($object);
- self::assertEquals($name, 'LoggerLayoutSimple');
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerRootTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerRootTest.php b/src/test/php/LoggerRootTest.php
deleted file mode 100644
index 056a50d..0000000
--- a/src/test/php/LoggerRootTest.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerRootTest extends PHPUnit_Framework_TestCase {
-
- public function testInitialSetup() {
- $root = new LoggerRoot();
- self::assertSame(LoggerLevel::getLevelAll(), $root->getLevel());
- self::assertSame(LoggerLevel::getLevelAll(), $root->getEffectiveLevel());
- self::assertSame('root', $root->getName());
- self::assertNull($root->getParent());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage log4php: LoggerRoot cannot have a parent.
- */
- public function testSetParentWarning() {
- $root = new LoggerRoot();
- $logger = new Logger('test');
- $root->setParent($logger);
- }
-
- public function testSetParentResult() {
- $root = new LoggerRoot();
- $logger = new Logger('test');
- @$root->setParent($logger);
- self::assertNull($root->getParent());
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage log4php: Cannot set LoggerRoot level to null.
- */
- public function testNullLevelWarning() {
- $root = new LoggerRoot();
- $root->setLevel(null);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerTest.php b/src/test/php/LoggerTest.php
deleted file mode 100644
index 145ac20..0000000
--- a/src/test/php/LoggerTest.php
+++ /dev/null
@@ -1,223 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerTest extends PHPUnit_Framework_TestCase {
-
- private $testConfig1 = array (
- 'rootLogger' => array (
- 'level' => 'ERROR',
- 'appenders' => array (
- 'default',
- ),
- ),
- 'appenders' => array (
- 'default' => array (
- 'class' => 'LoggerAppenderEcho',
- ),
- ),
- 'loggers' => array (
- 'mylogger' => array (
- 'additivity' => 'false',
- 'level' => 'DEBUG',
- 'appenders' => array (
- 'default',
- ),
- ),
- ),
- );
-
- // For testing additivity
- private $testConfig2 = array (
- 'appenders' => array (
- 'default' => array (
- 'class' => 'LoggerAppenderEcho',
- ),
- ),
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'loggers' => array (
- 'foo' => array (
- 'appenders' => array (
- 'default',
- ),
- ),
- 'foo.bar' => array (
- 'appenders' => array (
- 'default',
- ),
- ),
- 'foo.bar.baz' => array (
- 'appenders' => array (
- 'default',
- ),
- ),
- ),
- );
-
- // For testing additivity
- private $testConfig3 = array (
- 'appenders' => array (
- 'default' => array (
- 'class' => 'LoggerAppenderEcho',
- ),
- ),
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'loggers' => array (
- 'foo' => array (
- 'appenders' => array (
- 'default',
- ),
- ),
- 'foo.bar' => array (
- 'appenders' => array (
- 'default',
- ),
- ),
- 'foo.bar.baz' => array (
- 'level' => 'ERROR',
- 'appenders' => array (
- 'default',
- ),
- ),
- ),
- );
-
- protected function setUp() {
- Logger::clear();
- Logger::resetConfiguration();
- }
-
- protected function tearDown() {
- Logger::clear();
- Logger::resetConfiguration();
- }
-
- public function testLoggerExist() {
- $l = Logger::getLogger('test');
- self::assertEquals($l->getName(), 'test');
- self::assertTrue(Logger::exists('test'));
- }
-
- public function testCanGetRootLogger() {
- $l = Logger::getRootLogger();
- self::assertEquals($l->getName(), 'root');
- }
-
- public function testCanGetASpecificLogger() {
- $l = Logger::getLogger('test');
- self::assertEquals($l->getName(), 'test');
- }
-
- public function testCanLogToAllLevels() {
- Logger::configure($this->testConfig1);
-
- $logger = Logger::getLogger('mylogger');
- ob_start();
- $logger->info('this is an info');
- $logger->warn('this is a warning');
- $logger->error('this is an error');
- $logger->debug('this is a debug message');
- $logger->fatal('this is a fatal message');
- $v = ob_get_contents();
- ob_end_clean();
-
- $e = 'INFO - this is an info'.PHP_EOL;
- $e .= 'WARN - this is a warning'.PHP_EOL;
- $e .= 'ERROR - this is an error'.PHP_EOL;
- $e .= 'DEBUG - this is a debug message'.PHP_EOL;
- $e .= 'FATAL - this is a fatal message'.PHP_EOL;
-
- self::assertEquals($v, $e);
- }
-
- public function testIsEnabledFor() {
- Logger::configure($this->testConfig1);
-
- $logger = Logger::getLogger('mylogger');
-
- self::assertFalse($logger->isTraceEnabled());
- self::assertTrue($logger->isDebugEnabled());
- self::assertTrue($logger->isInfoEnabled());
- self::assertTrue($logger->isWarnEnabled());
- self::assertTrue($logger->isErrorEnabled());
- self::assertTrue($logger->isFatalEnabled());
-
- $logger = Logger::getRootLogger();
-
- self::assertFalse($logger->isTraceEnabled());
- self::assertFalse($logger->isDebugEnabled());
- self::assertFalse($logger->isInfoEnabled());
- self::assertFalse($logger->isWarnEnabled());
- self::assertTrue($logger->isErrorEnabled());
- self::assertTrue($logger->isFatalEnabled());
- }
-
- public function testGetCurrentLoggers() {
- Logger::clear();
- Logger::resetConfiguration();
-
- self::assertEquals(0, count(Logger::getCurrentLoggers()));
-
- Logger::configure($this->testConfig1);
- self::assertEquals(1, count(Logger::getCurrentLoggers()));
- $list = Logger::getCurrentLoggers();
- self::assertEquals('mylogger', $list[0]->getName());
- }
-
- public function testAdditivity() {
- Logger::configure($this->testConfig2);
-
- $logger = Logger::getLogger('foo.bar.baz');
- ob_start();
- $logger->info('test');
- $actual = ob_get_contents();
- ob_end_clean();
-
- // The message should get logged 4 times: once by every logger in the
- // hierarchy (including root)
- $expected = str_repeat('INFO - test' . PHP_EOL, 4);
- self::assertSame($expected, $actual);
- }
-
- public function testAdditivity2() {
- Logger::configure($this->testConfig3);
-
- $logger = Logger::getLogger('foo.bar.baz');
- ob_start();
- $logger->info('test');
- $actual = ob_get_contents();
- ob_end_clean();
-
- // The message should get logged 3 times: once by every logger in the
- // hierarchy, except foo.bar.baz which is set to level ERROR
- $expected = str_repeat('INFO - test' . PHP_EOL, 3);
- self::assertSame($expected, $actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerTestHelper.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerTestHelper.php b/src/test/php/LoggerTestHelper.php
deleted file mode 100644
index c4ea0ff..0000000
--- a/src/test/php/LoggerTestHelper.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/** A set of helper functions for running tests. */
-class LoggerTestHelper {
-
- /**
- * Returns a test logging event with level set to TRACE.
- * @return LoggerLoggingEvent
- */
- public static function getTraceEvent($message = 'test', $logger = "test") {
- return new LoggerLoggingEvent(__CLASS__, new Logger($logger), LoggerLevel::getLevelTrace(), $message);
- }
-
- /**
- * Returns a test logging event with level set to DEBUG.
- * @return LoggerLoggingEvent
- */
- public static function getDebugEvent($message = 'test', $logger = "test") {
- return new LoggerLoggingEvent(__CLASS__, new Logger($logger), LoggerLevel::getLevelDebug(), $message);
- }
-
- /**
- * Returns a test logging event with level set to INFO.
- * @return LoggerLoggingEvent
- */
- public static function getInfoEvent($message = 'test', $logger = "test") {
- return new LoggerLoggingEvent(__CLASS__, new Logger($logger), LoggerLevel::getLevelInfo(), $message);
- }
-
- /**
- * Returns a test logging event with level set to WARN.
- * @return LoggerLoggingEvent
- */
- public static function getWarnEvent($message = 'test', $logger = "test") {
- return new LoggerLoggingEvent(__CLASS__, new Logger($logger), LoggerLevel::getLevelWarn(), $message);
- }
-
- /**
- * Returns a test logging event with level set to ERROR.
- * @return LoggerLoggingEvent
- */
- public static function getErrorEvent($message = 'test', $logger = "test") {
- return new LoggerLoggingEvent(__CLASS__, new Logger($logger), LoggerLevel::getLevelError(), $message);
- }
-
- /**
- * Returns a test logging event with level set to FATAL.
- * @return LoggerLoggingEvent
- */
- public static function getFatalEvent($message = 'test', $logger = "test") {
- return new LoggerLoggingEvent(__CLASS__, new Logger($logger), LoggerLevel::getLevelFatal(), $message);
- }
-
- /**
- * Returns an array of logging events, one for each level, sorted ascending
- * by severitiy.
- */
- public static function getAllEvents($message = 'test') {
- return array(
- self::getTraceEvent($message),
- self::getDebugEvent($message),
- self::getInfoEvent($message),
- self::getWarnEvent($message),
- self::getErrorEvent($message),
- self::getFatalEvent($message),
- );
- }
-
- /** Returns an array of all existing levels, sorted ascending by severity. */
- public static function getAllLevels() {
- return array(
- LoggerLevel::getLevelTrace(),
- LoggerLevel::getLevelDebug(),
- LoggerLevel::getLevelInfo(),
- LoggerLevel::getLevelWarn(),
- LoggerLevel::getLevelError(),
- LoggerLevel::getLevelFatal(),
- );
- }
-
- /** Returns a string representation of a filter decision. */
- public static function decisionToString($decision) {
- switch($decision) {
- case LoggerFilter::ACCEPT: return 'ACCEPT';
- case LoggerFilter::NEUTRAL: return 'NEUTRAL';
- case LoggerFilter::DENY: return 'DENY';
- }
- }
-
- /** Returns a simple configuration with one echo appender tied to root logger. */
- public static function getEchoConfig() {
- return array(
- 'threshold' => 'ALL',
- 'rootLogger' => array(
- 'level' => 'trace',
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutSimple',
- ),
- ),
- ),
- );
- }
-
- /** Returns a simple configuration with one echo appender using the pattern layout. */
- public static function getEchoPatternConfig($pattern) {
- return array(
- 'threshold' => 'ALL',
- 'rootLogger' => array(
- 'level' => 'trace',
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutPattern',
- 'params' => array(
- 'conversionPattern' => $pattern
- )
- ),
- ),
- ),
- );
- }
-}
-
-?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/LoggerThrowableInformationTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/LoggerThrowableInformationTest.php b/src/test/php/LoggerThrowableInformationTest.php
deleted file mode 100644
index bc0a296..0000000
--- a/src/test/php/LoggerThrowableInformationTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group main
- */
-class LoggerThrowableInformationTest extends PHPUnit_Framework_TestCase {
-
- public function testConstructor() {
- $ex = new Exception();
- $tInfo = new LoggerThrowableInformation($ex);
-
- $result = $tInfo->getStringRepresentation();
- $this->assertInternalType('array', $result);
- }
-
- public function testExceptionChain() {
- $ex1 = new LoggerThrowableInformationTestException('Message1');
- $ex2 = new LoggerThrowableInformationTestException('Message2', 0, $ex1);
- $ex3 = new LoggerThrowableInformationTestException('Message3', 0, $ex2);
-
- $tInfo = new LoggerThrowableInformation($ex3);
- $result = $tInfo->getStringRepresentation();
- $this->assertInternalType('array', $result);
- }
-
- public function testGetThrowable() {
- $ex = new LoggerThrowableInformationTestException('Message1');
- $tInfo = new LoggerThrowableInformation($ex);
- $result = $tInfo->getThrowable();
- $this->assertEquals($ex, $result);
- }
-}
-
-
-if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
- class LoggerThrowableInformationTestException extends Exception { }
-} else {
- class LoggerThrowableInformationTestException extends Exception {
-
- protected $previous;
-
- public function __construct($message = '', $code = 0, Exception $previous = null) {
- parent::__construct($message, $code);
- $this->previous = $previous;
- }
-
- public function getPrevious() {
- return $this->previous;
- }
- }
-}
-?>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/README
----------------------------------------------------------------------
diff --git a/src/test/php/README b/src/test/php/README
deleted file mode 100644
index 693e23e..0000000
--- a/src/test/php/README
+++ /dev/null
@@ -1,19 +0,0 @@
-All tests can be run from the root of the package by running:
-$ phpunit
-
-Tests classes are divided into groups which can be run individually:
-$ phpunit --group main
-$ phpunit --group appenders
-$ phpunit --group configurators
-$ phpunit --group filters
-$ phpunit --group helpers
-$ phpunit --group layouts
-$ phpunit --group renderers
-
-Individual test classes can be run using e.g.:
-$ phpunit src/test/php/appenders/LoggerAppenderSocketTest.php
-
-Do not use relative file paths in the tests. Absoulte paths may be constructed
-using snippets like:
-* dirname(__FILE__) . '/../path/to/file'
-* PHPUNIT_TEMP_DIR . '/../path/to/file'
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/appenders/LoggerAppenderConsoleTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/appenders/LoggerAppenderConsoleTest.php b/src/test/php/appenders/LoggerAppenderConsoleTest.php
deleted file mode 100644
index 24b72e0..0000000
--- a/src/test/php/appenders/LoggerAppenderConsoleTest.php
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group appenders
- */
-class LoggerAppenderConsoleTest extends PHPUnit_Framework_TestCase {
-
- private $config = array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderConsole',
- 'layout' => array(
- 'class' => 'LoggerLayoutPattern',
- 'params' => array(
- // Intentionally blank so output doesn't clutter phpunit output
- 'conversionPattern' => ''
- )
- ),
- )
- )
- );
-
- public function testRequiresLayout() {
- $appender = new LoggerAppenderConsole();
- self::assertTrue($appender->requiresLayout());
- }
-
- public function testAppendDefault() {
- Logger::configure($this->config);
- $log = Logger::getRootLogger();
-
- $expected = LoggerAppenderConsole::STDOUT;
- $actual = $log->getAppender('default')->getTarget();
- $this->assertSame($expected, $actual);
-
- $log->info("hello");
- }
-
- public function testAppendStdout() {
- $this->config['appenders']['default']['params']['target'] = 'stdout';
-
- Logger::configure($this->config);
- $log = Logger::getRootLogger();
-
- $expected = LoggerAppenderConsole::STDOUT;
- $actual = $log->getAppender('default')->getTarget();
- $this->assertSame($expected, $actual);
-
- $log->info("hello");
- }
-
- public function testAppendStderr() {
- $this->config['appenders']['default']['params']['target'] = 'stderr';
- Logger::configure($this->config);
- $log = Logger::getRootLogger();
- $expected = LoggerAppenderConsole::STDERR;
-
- $actual = $log->getAppender('default')->getTarget();
- $this->assertSame($expected, $actual);
-
- $log->info("hello");
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/appenders/LoggerAppenderDailyFileTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/appenders/LoggerAppenderDailyFileTest.php b/src/test/php/appenders/LoggerAppenderDailyFileTest.php
deleted file mode 100644
index 332ebf2..0000000
--- a/src/test/php/appenders/LoggerAppenderDailyFileTest.php
+++ /dev/null
@@ -1,190 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group appenders
- */
-class LoggerAppenderDailyFileTest extends PHPUnit_Framework_TestCase {
-
- protected function setUp() {
- @unlink(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date('Ymd'));
- @unlink(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date('Y'));
- }
-
- public function testRequiresLayout() {
- $appender = new LoggerAppenderDailyFile();
- self::assertTrue($appender->requiresLayout());
- }
-
- public function testDefaultLayout() {
- $appender = new LoggerAppenderDailyFile();
- $actual = $appender->getLayout();
- self::assertInstanceOf('LoggerLayoutSimple', $actual);
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Required parameter 'file' not set.
- */
- public function testRequiredParamWarning1() {
- $appender = new LoggerAppenderDailyFile();
- $appender->activateOptions();
- }
-
- /**
- * @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage Required parameter 'datePattern' not set.
- */
- public function testRequiredParamWarning2() {
- $appender = new LoggerAppenderDailyFile();
- $appender->setFile('file.log');
- $appender->setDatePattern('');
- $appender->activateOptions();
- }
-
- public function testGetDatePattern() {
- $appender = new LoggerAppenderDailyFile();
-
- // Default pattern
- $actual = $appender->getDatePattern();
- self::assertEquals('Ymd', $actual);
-
- // Custom pattern
- $appender->setDatePattern('xyz');
- $actual = $appender->getDatePattern();
- self::assertEquals('xyz', $actual);
- }
-
- /**
- * For greater code coverage!
- * Override the warning so remaining code is reached.
- */
- public function testRequiredParamWarning3() {
- $appender = new LoggerAppenderDailyFile();
- $appender->setFile('file.log');
- $appender->setDatePattern('');
- @$appender->activateOptions();
- }
-
- public function testLazyFileOpen() {
- $event = LoggerTestHelper::getWarnEvent("my message");
- $file = PHPUNIT_TEMP_DIR . '/lazy-file.%s.log';
- $pattern = 'Y-m-d';
-
- $date = date($pattern, $event->getTimeStamp());
- $path = PHPUNIT_TEMP_DIR . "/lazy-file.$date.log";
-
- if (file_exists($path)) {
- unlink($path);
- }
-
- $appender = new LoggerAppenderDailyFile();
- $appender->setFile($file);
- $appender->setDatePattern('Y-m-d');
- $appender->activateOptions();
-
- // File should not exist before first append
- self::assertFileNotExists($path);
- $appender->append($event);
- self::assertFileExists($path);
- }
-
- public function testRollover()
- {
- $message = uniqid();
- $level = LoggerLevel::getLevelDebug();
-
- $file = PHPUNIT_TEMP_DIR . '/lazy-file.%s.log';
- $pattern = 'Y-m-d';
-
- // Get some timestamps for events - different date for each
- $ts1 = mktime(10, 0, 0, 7, 3, 1980);
- $ts2 = mktime(10, 0, 0, 7, 4, 1980);
- $ts3 = mktime(10, 0, 0, 7, 5, 1980);
-
- $e1 = new LoggerLoggingEvent(__CLASS__, 'test', $level, $message, $ts1);
- $e2 = new LoggerLoggingEvent(__CLASS__, 'test', $level, $message, $ts2);
- $e3 = new LoggerLoggingEvent(__CLASS__, 'test', $level, $message, $ts3);
-
- // Expected paths
- $path1 = PHPUNIT_TEMP_DIR . '/lazy-file.1980-07-03.log';
- $path2 = PHPUNIT_TEMP_DIR . '/lazy-file.1980-07-04.log';
- $path3 = PHPUNIT_TEMP_DIR . '/lazy-file.1980-07-05.log';
-
- @unlink($path1);
- @unlink($path2);
- @unlink($path3);
-
- $appender = new LoggerAppenderDailyFile();
- $appender->setFile($file);
- $appender->setDatePattern('Y-m-d');
- $appender->activateOptions();
-
- $appender->append($e1);
- $appender->append($e2);
- $appender->append($e3);
-
- $actual1 = file_get_contents($path1);
- $actual2 = file_get_contents($path2);
- $actual3 = file_get_contents($path3);
-
- $expected1 = "DEBUG - $message" . PHP_EOL;
- $expected2 = "DEBUG - $message" . PHP_EOL;
- $expected3 = "DEBUG - $message" . PHP_EOL;
-
- self::assertSame($expected1, $actual1);
- self::assertSame($expected2, $actual2);
- self::assertSame($expected3, $actual3);
- }
-
- public function testSimpleLogging() {
- $event = LoggerTestHelper::getWarnEvent("my message");
-
- $appender = new LoggerAppenderDailyFile();
- $appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.%s');
- $appender->activateOptions();
- $appender->append($event);
- $appender->close();
-
- $actual = file_get_contents(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date("Ymd"));
- $expected = "WARN - my message".PHP_EOL;
- self::assertEquals($expected, $actual);
- }
-
- public function testChangedDateFormat() {
- $event = LoggerTestHelper::getWarnEvent("my message");
-
- $appender = new LoggerAppenderDailyFile();
- $appender->setDatePattern('Y');
- $appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.%s');
- $appender->activateOptions();
- $appender->append($event);
- $appender->close();
-
- $actual = file_get_contents(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date("Y"));
- $expected = "WARN - my message".PHP_EOL;
- self::assertEquals($expected, $actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/appenders/LoggerAppenderEchoTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/appenders/LoggerAppenderEchoTest.php b/src/test/php/appenders/LoggerAppenderEchoTest.php
deleted file mode 100644
index b70e282..0000000
--- a/src/test/php/appenders/LoggerAppenderEchoTest.php
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group appenders
- */
-class LoggerAppenderEchoTest extends PHPUnit_Framework_TestCase {
-
- private $config1 = array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutSimple'
- ),
- )
- )
- );
-
- private $config2 = array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutSimple'
- ),
- 'params' => array(
- 'htmlLineBreaks' => true
- )
- )
- )
- );
-
- private $config3 = array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderEcho',
- 'layout' => array(
- 'class' => 'LoggerLayoutSimple'
- ),
- 'params' => array(
- 'htmlLineBreaks' => 'foo'
- )
- )
- )
- );
-
- public function testAppend() {
- Logger::configure($this->config1);
- $log = Logger::getRootLogger();
-
- $hlb = $log->getAppender('default')->getHtmlLineBreaks();
- $this->assertSame(false, $hlb);
-
- ob_start();
- $log->info("This is a test");
- $log->debug("And this too");
- $actual = ob_get_clean();
- $expected = "INFO - This is a test" . PHP_EOL . "DEBUG - And this too". PHP_EOL;
-
- $this->assertSame($expected, $actual);
- }
-
- public function testHtmlLineBreaks() {
- Logger::configure($this->config2);
- $log = Logger::getRootLogger();
-
- $hlb = $log->getAppender('default')->getHtmlLineBreaks();
- $this->assertSame(true, $hlb);
-
- ob_start();
- $log->info("This is a test" . PHP_EOL . "With more than one line");
- $log->debug("And this too");
- $actual = ob_get_clean();
- $expected = "INFO - This is a test<br />" . PHP_EOL . "With more than one line<br />" . PHP_EOL . "DEBUG - And this too<br />" . PHP_EOL;
-
- $this->assertSame($expected, $actual);
- }
-
-// public function testHtmlLineBreaksInvalidOption() {
-// Logger::configure($this->config3);
-// }
-
-
- public function testEcho() {
- $appender = new LoggerAppenderEcho("myname ");
-
- $layout = new LoggerLayoutSimple();
- $appender->setLayout($layout);
- $appender->activateOptions();
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
-
- $expected = "ERROR - testmessage" . PHP_EOL;
- ob_start();
- $appender->append($event);
- $actual = ob_get_clean();
-
- self::assertEquals($expected, $actual);
- }
-
- public function testRequiresLayout() {
- $appender = new LoggerAppenderEcho();
- self::assertTrue($appender->requiresLayout());
- }
-
- public function testEchoHtml() {
- $appender = new LoggerAppenderEcho("myname ");
- $appender->setHtmlLineBreaks(true);
-
- $layout = new LoggerLayoutSimple();
- $appender->setLayout($layout);
- $appender->activateOptions();
-
- // Single line message
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
-
- $expected = "ERROR - testmessage<br />" . PHP_EOL;
- ob_start();
- $appender->append($event);
- $actual = ob_get_clean();
- self::assertEquals($expected, $actual);
-
- // Multi-line message
- $msg = "This message\nis in several lines\r\nto test various line breaks.";
- $expected = "ERROR - This message<br />\nis in several lines<br />\r\nto test various line breaks.<br />" . PHP_EOL;
-
- $event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(), $msg);
- ob_start();
- $appender->append($event);
- $actual = ob_get_clean();
- self::assertEquals($expected, $actual);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/test/php/appenders/LoggerAppenderFileTest.php
----------------------------------------------------------------------
diff --git a/src/test/php/appenders/LoggerAppenderFileTest.php b/src/test/php/appenders/LoggerAppenderFileTest.php
deleted file mode 100644
index 5ed3eef..0000000
--- a/src/test/php/appenders/LoggerAppenderFileTest.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 appenders
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- * @version $Revision$
- * @link http://logging.apache.org/log4php
- */
-
-/**
- * @group appenders
- */
-class LoggerAppenderFileTest extends PHPUnit_Framework_TestCase {
-
- private $config1 = array(
- 'rootLogger' => array(
- 'appenders' => array('default'),
- ),
- 'appenders' => array(
- 'default' => array(
- 'class' => 'LoggerAppenderFile',
- 'layout' => array(
- 'class' => 'LoggerLayoutSimple'
- ),
- 'params' => array()
- )
- )
- );
-
- private $testPath;
-
- public function __construct() {
- $this->testPath = PHPUNIT_TEMP_DIR . '/TEST.txt';
- }
-
- public function setUp() {
- Logger::resetConfiguration();
- if(file_exists($this->testPath)) {
- unlink($this->testPath);
- }
- }
-
- public function tearDown() {
- Logger::resetConfiguration();
- if(file_exists($this->testPath)) {
- unlink($this->testPath);
- }
- }
-
- public function testRequiresLayout() {
- $appender = new LoggerAppenderFile();
- self::assertTrue($appender->requiresLayout());
- }
-
- public function testActivationDoesNotCreateTheFile() {
- $path = PHPUNIT_TEMP_DIR . "/doesnotexisthopefully.log";
- @unlink($path);
- $appender = new LoggerAppenderFile();
- $appender->setFile($path);
- $appender->activateOptions();
-
- self::assertFalse(file_exists($path));
-
- $event = LoggerTestHelper::getInfoEvent('bla');
- $appender->append($event);
-
- self::assertTrue(file_exists($path));
- }
-
- public function testSimpleLogging() {
- $config = $this->config1;
- $config['appenders']['default']['params']['file'] = $this->testPath;
-
- Logger::configure($config);
-
- $logger = Logger::getRootLogger();
- $logger->info('This is a test');
-
- $expected = "INFO - This is a test" . PHP_EOL;
- $actual = file_get_contents($this->testPath);
- $this->assertSame($expected, $actual);
- }
-
- public function testAppendFlagTrue() {
- $config = $this->config1;
- $config['appenders']['default']['params']['file'] = $this->testPath;
- $config['appenders']['default']['params']['append'] = true;
-
- Logger::configure($config);
- $logger = Logger::getRootLogger();
- $logger->info('This is a test');
-
- Logger::configure($config);
- $logger = Logger::getRootLogger();
- $logger->info('This is a test');
-
- $expected = "INFO - This is a test" . PHP_EOL . "INFO - This is a test" . PHP_EOL;
- $actual = file_get_contents($this->testPath);
- $this->assertSame($expected, $actual);
- }
-
- public function testAppendFlagFalse() {
- $config = $this->config1;
- $config['appenders']['default']['params']['file'] = $this->testPath;
- $config['appenders']['default']['params']['append'] = false;
-
- Logger::configure($config);
- $logger = Logger::getRootLogger();
- $logger->info('This is a test');
-
- Logger::configure($config);
- $logger = Logger::getRootLogger();
- $logger->info('This is a test');
-
- $expected = "INFO - This is a test" . PHP_EOL;
- $actual = file_get_contents($this->testPath);
- $this->assertSame($expected, $actual);
- }
-}