From a56543682d53801091c505ef2a49cb7f6d4718a8 Mon Sep 17 00:00:00 2001 From: pomaxa Date: Wed, 13 Jun 2012 12:07:17 +0300 Subject: [PATCH] AMQP --- src/Monolog/Handler/AmqpHandler.php | 10 ++-- tests/Monolog/Handler/AmqpHandlerTest.php | 50 +++++++++++++++++++ tests/Monolog/Handler/AmqpMocks.php | 61 +++++++++++++++++++++++ 3 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 tests/Monolog/Handler/AmqpHandlerTest.php create mode 100644 tests/Monolog/Handler/AmqpMocks.php diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index e802ed03..a3f95244 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -16,22 +16,24 @@ use Monolog\Formatter\JsonFormatter; class AmqpHandler extends AbstractProcessingHandler { + /** @var \AMQPExchange $exchange */ protected $exchange; + /** @var string $space */ protected $space; /** - * @param \AMQPConnection $amqp Amqp connection, ready for use - * @param string $exchange exchange name + * @param \AMQPConnection $amqp AMQP connection, ready for use + * @param string $exchangeName * @param string $space string to be able better manage routing keys * @param int $level * @param bool $bubble Whether the messages that are handled can bubble up the stack or not */ - function __construct(\AMQPConnection $amqp, $exchange = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) + function __construct(\AMQPConnection $amqp, $exchangeName = 'log', $space = '', $level = Logger::DEBUG, $bubble = true) { $this->space = $space; $channel = new \AMQPChannel($amqp); $this->exchange = new \AMQPExchange($channel); - $this->exchange->setName($exchange); + $this->exchange->setName($exchangeName); parent::__construct($level, $bubble); } diff --git a/tests/Monolog/Handler/AmqpHandlerTest.php b/tests/Monolog/Handler/AmqpHandlerTest.php new file mode 100644 index 00000000..efcbc5d8 --- /dev/null +++ b/tests/Monolog/Handler/AmqpHandlerTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\TestCase; +use Monolog\Logger; + +/** + * @covers Monolog\Handler\RotatingFileHandler + */ +class RotatingFileHandlerTest extends TestCase +{ + public function setUp() + { + if (!class_exists('AMQPConnection') || !class_exists('AMQPExchange')) { + $this->markTestSkipped("amqp-php not installed"); + } + + if (!class_exists('AMQPChannel')) { + throw new \Exception(' Please update AMQP to version >= 1'); + } + + require_once __DIR__ . '/AmqpMocks.php'; + } + + public function testWrite() + { +// $handler = new AmqpHandler($this->getMockAMQPConnection(), 'log', 'monolog'); + } + + public function getMockAMQPConnection() { + return new MockAMQPConnection(); + } + + public function tearDown() + { + foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { + unlink($file); + } + } +} \ No newline at end of file diff --git a/tests/Monolog/Handler/AmqpMocks.php b/tests/Monolog/Handler/AmqpMocks.php new file mode 100644 index 00000000..cdbb8a8a --- /dev/null +++ b/tests/Monolog/Handler/AmqpMocks.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +class MockAMQPConnection extends \AMQPConnection +{ + public function __construct(){ + + } + + public function pconnect() + { + return true; + } + + public function reconnect() + { + return false; + } + + public function connect() { + return true; + } + + public function isConnected() { + return true; + } +} + + +class MockAMQPChannel extends \AMQPChannel +{ + public function __construct(MockAMQPConnection $connection) { + + } +} + +class MockAMQPExchange extends \AMQPExchange +{ + + public function __construct(MockAMQPChannel $channel) { + + } + + public function publish($message, $routing_key, $flags, $headers){ + return; + } + + public function setName($exchangeName) { + return true; + } +} \ No newline at end of file