diff --git a/src/Fluent/Autoloader.php b/src/Fluent/Autoloader.php index 76d63be..7824fd5 100644 --- a/src/Fluent/Autoloader.php +++ b/src/Fluent/Autoloader.php @@ -3,13 +3,13 @@ * Fluent-Logger-PHP * * Copyright (C) 2011 - 2012 Fluent-Logger-PHP Contributors - * + * * 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. @@ -22,7 +22,7 @@ class Autoloader { const NAME_SPACE = 'Fluent'; protected static $base_dir; - + /** * register Fluent basic autoloader * @@ -34,7 +34,7 @@ public static function register($dirname = __DIR__) self::$base_dir = $dirname; spl_autoload_register(array(__CLASS__, "autoload")); } - + /** * unregister Fluent basic autoloader * @@ -44,7 +44,7 @@ public static function unregister() { spl_autoload_unregister(array(__CLASS__, "autoload")); } - + /** * autoload basic implementation * @@ -54,17 +54,17 @@ public static function unregister() public static function autoload($name) { $retval = false; - if (strpos($name,self::NAME_SPACE) === 0) { - $parts = explode("\\",$name); + if (strpos($name, self::NAME_SPACE) === 0) { + $parts = explode("\\", $name); array_shift($parts); - - $expected_path = join(DIRECTORY_SEPARATOR,array(self::$base_dir, join(DIRECTORY_SEPARATOR,$parts) . ".php")); + + $expected_path = join(DIRECTORY_SEPARATOR, array(self::$base_dir, join(DIRECTORY_SEPARATOR, $parts) . ".php")); if (is_file($expected_path) && is_readable($expected_path)) { require $expected_path; $retval = true; } } - + return $retval; } } \ No newline at end of file diff --git a/src/Fluent/Logger/BaseLogger.php b/src/Fluent/Logger/BaseLogger.php index 419a37c..46a80f0 100644 --- a/src/Fluent/Logger/BaseLogger.php +++ b/src/Fluent/Logger/BaseLogger.php @@ -28,7 +28,7 @@ abstract class BaseLogger implements \Fluent\Logger\LoggerInterface protected $error_handler = null; /** - * @param $entity + * @param $entity * @param void $error error message */ public function defaultErrorHandler(BaseLogger $logger, Entity $entity, $error) @@ -38,7 +38,7 @@ public function defaultErrorHandler(BaseLogger $logger, Entity $entity, $error) /** * @param Entity $entity - * @param void $error error message + * @param void $error error message */ protected function processError(Entity $entity, $error) { @@ -61,6 +61,7 @@ public function registerErrorHandler($callable) } else { throw new \InvalidArgumentException("Error handler must be callable."); } + return true; } } diff --git a/src/Fluent/Logger/ChainLogger.php b/src/Fluent/Logger/ChainLogger.php index be986be..ceec692 100644 --- a/src/Fluent/Logger/ChainLogger.php +++ b/src/Fluent/Logger/ChainLogger.php @@ -26,7 +26,7 @@ */ class ChainLogger extends BaseLogger { - protected $chain = array(); + protected $chain = array(); protected $errors = array(); public function __construct() @@ -35,7 +35,7 @@ public function __construct() public function addLogger(\Fluent\Logger\BaseLogger $logger) { - $logger->registerErrorHandler(array($this,"defaultErrorHandler")); + $logger->registerErrorHandler(array($this, "defaultErrorHandler")); $this->chain[] = $logger; } @@ -47,7 +47,7 @@ public function defaultErrorHandler(BaseLogger $logger, Entity $entity, $error) /** * @param string $tag - * @param array $data + * @param array $data * * @api */ diff --git a/src/Fluent/Logger/ConsoleLogger.php b/src/Fluent/Logger/ConsoleLogger.php index dcb18e6..30881ca 100644 --- a/src/Fluent/Logger/ConsoleLogger.php +++ b/src/Fluent/Logger/ConsoleLogger.php @@ -28,7 +28,7 @@ class ConsoleLogger extends BaseLogger { /* @var resource handle */ protected $handle; - + /** * create Console logger object. * @@ -37,7 +37,7 @@ class ConsoleLogger extends BaseLogger public function __construct($stream = null) { if (is_null($stream)) { - $stream = fopen("php://stderr","w");; + $stream = fopen("php://stderr", "w"); } $this->handle = $stream; } @@ -50,6 +50,7 @@ public function __construct($stream = null) public static function open() { $logger = new self(); + return $logger; } @@ -57,11 +58,12 @@ public static function open() * send a message to specified fluentd. * * @param string $tag - * @param array $data + * @param array $data */ - public function post($tag ,array $data) + public function post($tag, array $data) { - $entity = new Entity($tag,$data); + $entity = new Entity($tag, $data); + return $this->postImpl($entity); } @@ -85,8 +87,9 @@ protected function postImpl(Entity $entity) * 2012-02-26T01:26:20+0900 debug.test {"hello":"world"} */ $format = "%s\t%s\t%s\n"; + return $this->write(sprintf($format, - date(\DateTime::ISO8601,$entity->getTime()), + date(\DateTime::ISO8601, $entity->getTime()), $entity->getTag(), json_encode($entity->getData()) )); diff --git a/src/Fluent/Logger/Entity.php b/src/Fluent/Logger/Entity.php index 03d7927..6c99df0 100644 --- a/src/Fluent/Logger/Entity.php +++ b/src/Fluent/Logger/Entity.php @@ -32,8 +32,8 @@ class Entity /** * create a entity for sending to fluentd server * - * @param $tag - * @param $data + * @param $tag + * @param $data * @param int $time unixtime */ public function __construct($tag, $data, $time = null) @@ -48,7 +48,7 @@ public function __construct($tag, $data, $time = null) $this->time = time(); } - $this->tag = $tag; + $this->tag = $tag; $this->data = $data; } diff --git a/src/Fluent/Logger/Exception.php b/src/Fluent/Logger/Exception.php index 5449357..63603a6 100644 --- a/src/Fluent/Logger/Exception.php +++ b/src/Fluent/Logger/Exception.php @@ -23,10 +23,10 @@ class Exception extends \Exception protected $entity; /** - * @param $tag - * @param $data - * @param string $message - * @param int $code + * @param $tag + * @param $data + * @param string $message + * @param int $code * @param \Exception|null $previous */ public function __construct(Entity $entity, $message = "", $code = 0, \Exception $previous = null) diff --git a/src/Fluent/Logger/FileLogger.php b/src/Fluent/Logger/FileLogger.php index 93592fb..a262871 100644 --- a/src/Fluent/Logger/FileLogger.php +++ b/src/Fluent/Logger/FileLogger.php @@ -58,6 +58,7 @@ public function __construct($path) public static function open($path) { $logger = new self($path); + return $logger; } @@ -65,11 +66,12 @@ public static function open($path) * write a message to specified path. * * @param string $tag - * @param array $data + * @param array $data */ - public function post($tag,array $data) + public function post($tag, array $data) { $entity = new Entity($tag, $data); + return $this->postImpl($entity); } @@ -86,21 +88,20 @@ public function post2(Entity $entity) protected function postImpl(Entity $entity) { $packed = json_encode($entity->getData()); - $data = $wbuffer = sprintf("%s\t%s\t%s\n", - date(\DateTime::ISO8601, - $entity->getTime()), - $entity->getTag(), - $packed . PHP_EOL + $data = $wbuffer = sprintf("%s\t%s\t%s\n", + date(\DateTime::ISO8601, $entity->getTime()), + $entity->getTag(), + $packed . PHP_EOL ); - $length = strlen($data); + $length = strlen($data); $written = 0; try { if (!flock($this->fp, LOCK_EX)) { throw new \Exception('could not obtain LOCK_EX'); } - fseek($this->fp,-1, SEEK_END); + fseek($this->fp, -1, SEEK_END); while ($written < $length) { $nwrite = fwrite($this->fp, $wbuffer); @@ -115,14 +116,16 @@ protected function postImpl(Entity $entity) $retry++; } $written += $nwrite; - $wbuffer = substr($wbuffer,$written); + $wbuffer = substr($wbuffer, $written); } flock($this->fp, LOCK_UN); } catch (\Exception $e) { $this->processError($this, $entity, $e->getMessage()); + return false; } + return true; } diff --git a/src/Fluent/Logger/FluentLogger.php b/src/Fluent/Logger/FluentLogger.php index 874fa7c..6edf341 100644 --- a/src/Fluent/Logger/FluentLogger.php +++ b/src/Fluent/Logger/FluentLogger.php @@ -1,15 +1,15 @@ options = array(); $this->mergeOptions($options); } - + /** * fluent-logger compatible API. * * @param string $host - * @param int $port - * @param array $options + * @param int $port + * @param array $options * @return FluentLogger created logger object. */ - public static function open($host = FluentLogger::DEFAULT_ADDRESS, $port = FluentLogger::DEFAULT_LISTEN_PORT, array $options = array()) + public static function open($host = FluentLogger::DEFAULT_ADDRESS, $port = FluentLogger::DEFAULT_LISTEN_PORT, array $options = array()) { - $key = sprintf("%s:%s:%s", $host, $port, md5(join(",",$options))); + $key = sprintf("%s:%s:%s", $host, $port, md5(join(",", $options))); if (!isset(self::$instances[$key])) { - $logger = new self($host,$port, $options); + $logger = new self($host, $port, $options); self::$instances[$key] = $logger; } @@ -266,9 +266,9 @@ protected function connect() // could not suppress warning without ini setting. // for now, we use error control operators. - $socket = @stream_socket_client($this->transport,$errno,$errstr, - $this->getOption("connection_timeout",self::CONNECTION_TIMEOUT), - $connect_options + $socket = @stream_socket_client($this->transport, $errno, $errstr, + $this->getOption("connection_timeout", self::CONNECTION_TIMEOUT), + $connect_options ); if (!$socket) { @@ -277,10 +277,10 @@ protected function connect() } // set read / write timeout. - stream_set_timeout($socket,$this->getOption("socket_timeout",self::SOCKET_TIMEOUT)); + stream_set_timeout($socket, $this->getOption("socket_timeout", self::SOCKET_TIMEOUT)); $this->socket = $socket; } - + /** * create a connection if Fluent Logger hasn't a socket connection. * @@ -292,12 +292,12 @@ protected function reconnect() $this->connect(); } } - + /** * send a message to specified fluentd. * * @param string $tag - * @param array $data + * @param array $data * @return bool * * @api @@ -305,6 +305,7 @@ protected function reconnect() public function post($tag, array $data) { $entity = new Entity($tag, $data); + return $this->postImpl($entity); } @@ -337,6 +338,7 @@ protected function postImpl(Entity $entity) } catch (\Exception $e) { $this->close(); $this->processError($entity, $e->getMessage()); + return false; } @@ -356,6 +358,7 @@ protected function postImpl(Entity $entity) } else if ($nwrite === 0) { if (!$this->getOption("retry_socket", true)) { $this->processError($entity, "could not send entities"); + return false; } @@ -370,25 +373,26 @@ protected function postImpl(Entity $entity) $this->close(); $this->reconnect(); } else { - error_log("unhandled error detected. please report this issue to http://github.com/fluent/fluent-logger-php/issues: " . var_export($errors,true)); + error_log("unhandled error detected. please report this issue to http://github.com/fluent/fluent-logger-php/issues: " . var_export($errors, true)); } } - if ($this->getOption('backoff_mode',self::BACKOFF_TYPE_EXPONENTIAL) == self::BACKOFF_TYPE_EXPONENTIAL) { + if ($this->getOption('backoff_mode', self::BACKOFF_TYPE_EXPONENTIAL) == self::BACKOFF_TYPE_EXPONENTIAL) { $this->backoffExponential(3, $retry); } else { - usleep($this->getOption("usleep_wait",self::USLEEP_WAIT)); + usleep($this->getOption("usleep_wait", self::USLEEP_WAIT)); } $retry++; continue; } $written += $nwrite; - $buffer = substr($packed,$written); + $buffer = substr($packed, $written); } } catch (\Exception $e) { $this->close(); $this->processError($entity, $e->getMessage()); + return false; } @@ -403,7 +407,7 @@ protected function postImpl(Entity $entity) */ public function backoffExponential($base, $attempt) { - usleep(pow($base, $attempt)*1000); + usleep(pow($base, $attempt) * 1000); } @@ -445,7 +449,7 @@ public function __destruct() /** * get specified option's value * - * @param $key + * @param $key * @param null $default * @return mixed */ diff --git a/src/Fluent/Logger/HttpLogger.php b/src/Fluent/Logger/HttpLogger.php index 3dde7b0..8845df9 100644 --- a/src/Fluent/Logger/HttpLogger.php +++ b/src/Fluent/Logger/HttpLogger.php @@ -28,12 +28,12 @@ class HttpLogger extends BaseLogger protected $tag; protected $host; protected $port; - + /** * create fluent http logger object. * * @param string $host - * @param int $port + * @param int $port * @return HttpLogger */ public function __construct($host, $port = HttpLogger::DEFAULT_HTTP_PORT) @@ -41,17 +41,18 @@ public function __construct($host, $port = HttpLogger::DEFAULT_HTTP_PORT) $this->host = $host; $this->port = $port; } - + /** * fluent-logger compatible API. * * @param string $host - * @param int $port + * @param int $port * @return HttpLogger created http logger object. */ public static function open($host, $port = HttpLogger::DEFAULT_HTTP_PORT) { - $logger = new self($host,$port); + $logger = new self($host, $port); + return $logger; } @@ -60,14 +61,15 @@ public static function open($host, $port = HttpLogger::DEFAULT_HTTP_PORT) * * @todo use HTTP1.1 protocol and persistent socket. * @param string $tag - * @param array $data + * @param array $data */ public function post($tag, array $data) { - $packed = json_encode($data); + $packed = json_encode($data); $request = sprintf('http://%s:%d/%s?json=%s', $this->host, $this->port, $tag, urlencode($packed)); $ret = file_get_contents($request); + return ($ret !== false); } @@ -76,14 +78,15 @@ public function post($tag, array $data) * * @todo use HTTP1.1 protocol and persistent socket. * @param string $tag - * @param array $data + * @param array $data */ public function post2(Entity $entity) { - $packed = json_encode($entity->getData()); + $packed = json_encode($entity->getData()); $request = sprintf('http://%s:%d/%s?json=%s', $this->host, $this->port, $entity->getTag(), urlencode($packed)); $ret = file_get_contents($request); + return ($ret !== false); } diff --git a/src/Fluent/Logger/LoggerInterface.php b/src/Fluent/Logger/LoggerInterface.php index 30edc5a..1425a83 100644 --- a/src/Fluent/Logger/LoggerInterface.php +++ b/src/Fluent/Logger/LoggerInterface.php @@ -3,13 +3,13 @@ * Fluent-Logger-PHP * * Copyright (C) 2011 - 2012 Fluent-Logger-PHP Contributors - * + * * 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. @@ -23,7 +23,7 @@ interface LoggerInterface /** * @abstract * @param string $tag - * @param array $data + * @param array $data * * @api */ diff --git a/tests/Fluent/Logger/BaseLoggerTest.php b/tests/Fluent/Logger/BaseLoggerTest.php index 1bede37..b12f7c6 100644 --- a/tests/Fluent/Logger/BaseLoggerTest.php +++ b/tests/Fluent/Logger/BaseLoggerTest.php @@ -7,7 +7,8 @@ use Fluent\Logger; use Fluent\Logger\FluentLogger; -function fluentTests_FluentLogger_DummyFunction () { +function fluentTests_FluentLogger_DummyFunction() +{ } class BaseLoggerTest extends \PHPUnit_Framework_TestCase @@ -33,7 +34,8 @@ public function errorHandlerProvider() array($this, 'errorHandlerProvider') ), array( - function () {}, // closure + function () { + }, // closure ), ); } diff --git a/tests/Fluent/Logger/ChainLoggerTest.php b/tests/Fluent/Logger/ChainLoggerTest.php index 2a17c24..9bf8e20 100644 --- a/tests/Fluent/Logger/ChainLoggerTest.php +++ b/tests/Fluent/Logger/ChainLoggerTest.php @@ -8,18 +8,18 @@ class ChainLoggerTest extends \PHPUnit_Framework_TestCase { - const TAG = 'debug.test'; - const OBJECT_KEY = 'hello'; + const TAG = 'debug.test'; + const OBJECT_KEY = 'hello'; const OBJECT_VALUE = 'world'; public function testChains() { $logger = new ChainLogger(); - $a = new FluentLogger("localhost"); - $b = new FluentLogger("localhost"); + $a = new FluentLogger("localhost"); + $b = new FluentLogger("localhost"); - $r = fopen("php://memory","r"); - $w = fopen("php://memory","a+"); + $r = fopen("php://memory", "r"); + $w = fopen("php://memory", "a+"); $this->setSocket($a, $r); $this->setSocket($b, $w); @@ -28,12 +28,12 @@ public function testChains() $logger->addLogger($b); $retval = $logger->post(self::TAG, array(self::OBJECT_KEY => self::OBJECT_VALUE)); - fseek($w,0); - $data = fread($w,8192); + fseek($w, 0); + $data = fread($w, 8192); $this->assertTrue($retval, "post successfull"); $this->assertStringMatchesFormat('["debug.test",%d,{"hello":"world"}]', $data); - $this->assertEquals(1,count($logger->getAvailableLoggers()), "failed logger should be ignore"); + $this->assertEquals(1, count($logger->getAvailableLoggers()), "failed logger should be ignore"); } diff --git a/tests/Fluent/Logger/ConsoleLoggerTest.php b/tests/Fluent/Logger/ConsoleLoggerTest.php index 0e53936..3eaaad1 100644 --- a/tests/Fluent/Logger/ConsoleLoggerTest.php +++ b/tests/Fluent/Logger/ConsoleLoggerTest.php @@ -12,17 +12,17 @@ public function testOpenMethod() $logger = new ConsoleLogger(); $this->assertInstanceof('Fluent\\Logger\\LoggerInterface', $logger, 'Logger::open should returns LoggerInterface inherited instance '); } - + public function testPostMethod() { - $stream = fopen("php://memory","r+"); + $stream = fopen("php://memory", "r+"); $logger = new ConsoleLogger($stream); - $logger->post("debug.test",array("a"=>"b")); + $logger->post("debug.test", array("a" => "b")); fseek($stream, 0); $data = stream_get_contents($stream); - $this->assertTrue((bool)preg_match("/debug.test\t\{\"a\":\"b\"\}/",$data), + $this->assertTrue((bool)preg_match("/debug.test\t\{\"a\":\"b\"\}/", $data), "ConsoleLogger::post could not write correctly.\nresult: {$data}"); fclose($stream); diff --git a/tests/Fluent/Logger/EntityTest.php b/tests/Fluent/Logger/EntityTest.php index a83e062..725b10c 100644 --- a/tests/Fluent/Logger/EntityTest.php +++ b/tests/Fluent/Logger/EntityTest.php @@ -10,18 +10,18 @@ class EntityTest extends \PHPUnit_Framework_TestCase public function testWhole() { - $time = time(); - $expected_data = array("abc"=>"def"); + $time = time(); + $expected_data = array("abc" => "def"); - $entity = new Entity(self::TAG,$expected_data, $time); - $this->assertEquals(self::TAG, $entity->getTag(),"unexpected tag `{$entity->getTag()}` returns."); + $entity = new Entity(self::TAG, $expected_data, $time); + $this->assertEquals(self::TAG, $entity->getTag(), "unexpected tag `{$entity->getTag()}` returns."); $this->assertEquals($expected_data, $entity->getData(), "unexpected data returns"); $this->assertEquals($time, $entity->getTime(), "unexpected time returns"); - $entity = new Entity(self::TAG,$expected_data); + $entity = new Entity(self::TAG, $expected_data); $this->assertGreaterThanOrEqual($time, $entity->getTime(), "unexpected time returns"); - $entity = new Entity(self::TAG,$expected_data,"not int"); + $entity = new Entity(self::TAG, $expected_data, "not int"); $this->assertGreaterThanOrEqual($time, $entity->getTime(), "unexpected time returns"); } diff --git a/tests/Fluent/Logger/FileLoggerTest.php b/tests/Fluent/Logger/FileLoggerTest.php index 8d80a51..5ede56a 100644 --- a/tests/Fluent/Logger/FileLoggerTest.php +++ b/tests/Fluent/Logger/FileLoggerTest.php @@ -46,7 +46,7 @@ public function testPostMethod() $logger = new FileLogger(self::$FILE_PATH); $this->assertTrue($logger->post($tag, array("a" => "b"))); - $data = file_get_contents(self::$FILE_PATH); + $data = file_get_contents(self::$FILE_PATH); $expected = preg_quote("$tag\t" . '{"a":"b"}'); $this->assertRegExp("/$expected/", $data, "FileLogger::post could not write correctly.\nresult: {$data}"); @@ -57,11 +57,11 @@ public function testPostMultiLine() $this->cleanUpFile(); $logger = new FileLogger(self::$FILE_PATH); - $lines = array( + $lines = array( array('a' => 'b'), array('c' => 'd'), ); - $tag = 'test.filelogger_multiline'; + $tag = 'test.filelogger_multiline'; foreach ($lines as $k => $line) { $this->assertTrue($logger->post($tag, $line)); } @@ -85,7 +85,7 @@ public function testPost2() $entity = new Entity($tag, array("a" => "b")); $this->assertTrue($logger->post2($entity)); - $data = file_get_contents(self::$FILE_PATH); + $data = file_get_contents(self::$FILE_PATH); $expected = preg_quote("$tag\t" . '{"a":"b"}'); $this->assertRegExp("/$expected/", $data, "FileLogger::post2 could not write correctly."); diff --git a/tests/Fluent/Logger/FluentLoggerTest.php b/tests/Fluent/Logger/FluentLoggerTest.php index c8c4cd7..acfc7a1 100644 --- a/tests/Fluent/Logger/FluentLoggerTest.php +++ b/tests/Fluent/Logger/FluentLoggerTest.php @@ -7,8 +7,8 @@ class FluentLoggerTest extends \PHPUnit_Framework_TestCase { - const TAG = 'debug.test'; - const OBJECT_KEY = 'hello'; + const TAG = 'debug.test'; + const OBJECT_KEY = 'hello'; const OBJECT_VALUE = 'world'; public function tearDown() @@ -24,7 +24,7 @@ public function testPostWillReturnTrueInTheCaseOfPostingSuccessfully() $socket = fopen("php://memory", "a+"); /* localhost is dummy string. we set php://memory as a socket */ - $logger = FluentLogger::open("localhost"); + $logger = FluentLogger::open("localhost"); $reflection = new \ReflectionProperty("Fluent\Logger\FluentLogger", "socket"); $reflection->setAccessible(true); $reflection->setValue($logger, $socket); @@ -100,22 +100,22 @@ private function getMockOfLogger(array $method) */ public function testGetTransportUri($host, $port, $expected_uri, $error_msg) { - $actual_uri = FluentLogger::getTransportUri($host,$port); - $this->assertEquals($expected_uri,$actual_uri, $error_msg); + $actual_uri = FluentLogger::getTransportUri($host, $port); + $this->assertEquals($expected_uri, $actual_uri, $error_msg); } public function providesTransport() { return array( - array("localhost",8080,"tcp://localhost:8080","unexpected uri returns"), - array("127.0.0.1",8080,"tcp://127.0.0.1:8080","unexpected uri returns"), - array("tcp://localhost",8080,"tcp://localhost:8080","unexpected uri returns"), - array("tcp://127.0.0.1",8080,"tcp://127.0.0.1:8080","unexpected uri returns"), - array("unix:///var/fluentd",0,"unix:///var/fluentd","unexpected uri returns"), - array("unix:///var/fluentd",8080,"unix:///var/fluentd","unix domain uri have to ignores port number"), - array("fe80::1",8080,"tcp://[fe80::1]:8080","ipv6 support failed"), - array("tcp://fe80::1",8081,"tcp://[fe80::1]:8081","ipv6 support failed"), - array("tcp://[fe80::1]",8082,"tcp://[fe80::1]:8082","ipv6 support failed"), + array("localhost", 8080, "tcp://localhost:8080", "unexpected uri returns"), + array("127.0.0.1", 8080, "tcp://127.0.0.1:8080", "unexpected uri returns"), + array("tcp://localhost", 8080, "tcp://localhost:8080", "unexpected uri returns"), + array("tcp://127.0.0.1", 8080, "tcp://127.0.0.1:8080", "unexpected uri returns"), + array("unix:///var/fluentd", 0, "unix:///var/fluentd", "unexpected uri returns"), + array("unix:///var/fluentd", 8080, "unix:///var/fluentd", "unix domain uri have to ignores port number"), + array("fe80::1", 8080, "tcp://[fe80::1]:8080", "ipv6 support failed"), + array("tcp://fe80::1", 8081, "tcp://[fe80::1]:8081", "ipv6 support failed"), + array("tcp://[fe80::1]", 8082, "tcp://[fe80::1]:8082", "ipv6 support failed"), ); } @@ -125,7 +125,7 @@ public function testGetTransportUriCauseExcpetion() FluentLogger::getTransportUri("udp://localhost", 1192); $this->fail("getTransportUri does not thorow exception"); } catch (\Exception $e) { - $this->assertInstanceOf("\\Exception",$e); + $this->assertInstanceOf("\\Exception", $e); } } @@ -134,7 +134,7 @@ public function testSetPacker() $logger = new FluentLogger("localhost"); $packer = new \Fluent\Logger\JsonPacker(); - $prop = new \ReflectionProperty($logger,"packer"); + $prop = new \ReflectionProperty($logger, "packer"); $prop->setAccessible(true); $logger->setPacker($packer); $this->assertSame($packer, $prop->getValue($logger), "unexpected packer was set"); @@ -144,16 +144,16 @@ public function testGetPacker() { $logger = new FluentLogger("localhost"); - $this->assertInstanceOf("Fluent\\Logger\\PackerInterface",$logger->getPacker(), "testGetPacker returns unexpected packer"); + $this->assertInstanceOf("Fluent\\Logger\\PackerInterface", $logger->getPacker(), "testGetPacker returns unexpected packer"); } public function testClearInstances() { - $prop = new \ReflectionProperty("\Fluent\Logger\FluentLogger","instances"); + $prop = new \ReflectionProperty("\Fluent\Logger\FluentLogger", "instances"); $prop->setAccessible(true); - FluentLogger::open("localhost",1191); - FluentLogger::open("localhost",1192); + FluentLogger::open("localhost", 1191); + FluentLogger::open("localhost", 1192); $this->assertCount(2, $prop->getValue("FluentLogger")); FluentLogger::clearInstances(); @@ -163,25 +163,25 @@ public function testClearInstances() public function testMergeOptions() { $logger = new FluentLogger("localhost"); - $prop = new \ReflectionProperty($logger,"options"); + $prop = new \ReflectionProperty($logger, "options"); $prop->setAccessible(true); $default = $prop->getValue($logger); - $additional_options = array("socket_timeout"=>10); + $additional_options = array("socket_timeout" => 10); $logger->mergeOptions($additional_options); - $this->assertEquals(array_merge($default,$additional_options),$prop->getValue($logger),"mergeOptions looks wired"); + $this->assertEquals(array_merge($default, $additional_options), $prop->getValue($logger), "mergeOptions looks wired"); } public function testMergeOptionsThrowsException() { - $logger = new FluentLogger("localhost"); - $additional_options = array("unexpected_key"=>10); + $logger = new FluentLogger("localhost"); + $additional_options = array("unexpected_key" => 10); try { $logger->mergeOptions($additional_options); $this->fail("mergeOptions doesn't thorw Exception"); } catch (\Exception $e) { - $this->assertInstanceOf("\\Exception",$e); + $this->assertInstanceOf("\\Exception", $e); } } @@ -189,49 +189,49 @@ public function testMergeOptionsThrowsException() public function testSetOptions() { $logger = new FluentLogger("localhost"); - $prop = new \ReflectionProperty($logger,"options"); + $prop = new \ReflectionProperty($logger, "options"); $prop->setAccessible(true); - $additional_options = array("socket_timeout"=>10); + $additional_options = array("socket_timeout" => 10); $logger->setOptions($additional_options); - $this->assertEquals($additional_options,$prop->getValue($logger),"setOptions looks wired"); + $this->assertEquals($additional_options, $prop->getValue($logger), "setOptions looks wired"); } public function testConnect() { - $logger = new FluentLogger("localhost",119223); - $method = new \ReflectionMethod($logger,"connect"); + $logger = new FluentLogger("localhost", 119223); + $method = new \ReflectionMethod($logger, "connect"); $method->setAccessible(true); try { $method->invoke($logger); $this->fail("mergeOptions doesn't thorw Exception"); } catch (\Exception $e) { - $this->assertInstanceOf("\\Exception",$e); + $this->assertInstanceOf("\\Exception", $e); } } public function testGetOption() { - $logger = new FluentLogger("localhost",119223); - $this->assertEquals(FluentLogger::CONNECTION_TIMEOUT,$logger->getOption("socket_timeout"), + $logger = new FluentLogger("localhost", 119223); + $this->assertEquals(FluentLogger::CONNECTION_TIMEOUT, $logger->getOption("socket_timeout"), "getOptions retunrs unexpected value"); } public function testReconnect() { - $logger = new FluentLogger("localhost",119223); - $method = new \ReflectionMethod($logger,"reconnect"); + $logger = new FluentLogger("localhost", 119223); + $method = new \ReflectionMethod($logger, "reconnect"); $method->setAccessible(true); try { $method->invoke($logger); $this->fail("reconnect doesn't throw Exception"); } catch (\Exception $e) { - $this->assertInstanceOf("\\Exception",$e); + $this->assertInstanceOf("\\Exception", $e); } - $fp = fopen("php://memory","r"); - $prop = new \ReflectionProperty($logger,"socket"); + $fp = fopen("php://memory", "r"); + $prop = new \ReflectionProperty($logger, "socket"); $prop->setAccessible(true); - $prop->setValue($logger,$fp); + $prop->setValue($logger, $fp); $method->invoke($logger); } } diff --git a/tests/Fluent/Logger/JsonPackerTest.php b/tests/Fluent/Logger/JsonPackerTest.php index 0246d28..1d0e97e 100644 --- a/tests/Fluent/Logger/JsonPackerTest.php +++ b/tests/Fluent/Logger/JsonPackerTest.php @@ -6,7 +6,7 @@ class JsonPackerTest extends \PHPUnit_Framework_TestCase { - const TAG = "debug.test"; + const TAG = "debug.test"; const EXPECTED_TIME = 123456789; protected $time; @@ -14,12 +14,12 @@ class JsonPackerTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->expected_data = array("abc"=>"def"); + $this->expected_data = array("abc" => "def"); } public function testPack() { - $entity = new Entity(self::TAG,$this->expected_data, self::EXPECTED_TIME); + $entity = new Entity(self::TAG, $this->expected_data, self::EXPECTED_TIME); $packer = new JsonPacker(); $result = $packer->pack($entity); @@ -29,7 +29,8 @@ public function testPack() * ["", , {object}] */ $this->assertStringMatchesFormat('["%s",%d,{"%s":"%s"}]', $result, "unexpected format returns"); - return json_decode($result,true); + + return json_decode($result, true); } /** @@ -37,7 +38,7 @@ public function testPack() */ public function testPackReturnTag($result) { - $this->assertEquals($result['0'],self::TAG); + $this->assertEquals($result['0'], self::TAG); } /** @@ -53,6 +54,6 @@ public function testPackReturnTime($result) */ public function testPackReturnData($result) { - $this->assertEquals($result['2'],$this->expected_data); + $this->assertEquals($result['2'], $this->expected_data); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4d8a7e1..8bdae3b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,5 @@