mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-14 00:54:01 +02:00
mock implemenation, kind of
This commit is contained in:
@@ -28,31 +28,56 @@ class AmqpHandlerTest extends TestCase
|
||||
if (!class_exists('AMQPChannel')) {
|
||||
throw new \Exception(' Please update AMQP to version >= 1');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/AmqpMocks.php';
|
||||
}
|
||||
|
||||
|
||||
public function testConstruct()
|
||||
/**
|
||||
* @covers Monolog\Handler\AmqpHandler::__construct
|
||||
* @covers Monolog\Handler\AmqpHandler::handle
|
||||
* @covers Monolog\Handler\AmqpHandler::write
|
||||
* @covers Monolog\Handler\AmqpHandler::getDefaultFormatter
|
||||
*/
|
||||
public function testHandle()
|
||||
{
|
||||
// $handler = new AmqpHandler($this->getMockAMQPConnection(), 'log', 'monolog');
|
||||
// $this->assertInstanceOf('Monolog\Handler\AmqpHandler', $handler);
|
||||
$exchange = $this->getExchange();
|
||||
|
||||
$handler = new AmqpHandler($exchange, 'log', 'test');
|
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
|
||||
|
||||
$handler->handle($record);
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
protected function getExchange()
|
||||
{
|
||||
/* sorry, but PHP bug in zend_object_store_get_object segfaults
|
||||
php where using mocks on AMQP classes. should be fixed someday,
|
||||
but now it's time for some shitcode (see below)
|
||||
$exchange = $this->getMockBuilder('\AMQPExchange')
|
||||
->setConstructorArgs(array($this->getMock('\AMQPChannel')))
|
||||
->setMethods(array('setName'))
|
||||
->getMock();
|
||||
|
||||
$exchange->expects($this->any())
|
||||
->method('setName')
|
||||
->will($this->returnValue(true));
|
||||
*/
|
||||
return new MockAMQPExchange();
|
||||
}
|
||||
}
|
||||
|
||||
class MockAMQPExchange extends \AMQPExchange
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getMockAMQPConnection()
|
||||
public function publish($message, $routing_key, $params = 0, $attributes = array())
|
||||
{
|
||||
return new MockAMQPConnection();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function setName($name)
|
||||
{
|
||||
foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) {
|
||||
unlink($file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user