瀏覽代碼

Fix tests

Jordi Boggiano 13 年之前
父節點
當前提交
ad9d31e0f4
共有 3 個文件被更改,包括 42 次插入20 次删除
  1. 11 2
      tests/Monolog/Handler/AmqpExchangeMock.php
  2. 29 16
      tests/Monolog/Handler/AmqpHandlerTest.php
  3. 2 2
      tests/bootstrap.php

+ 11 - 2
tests/Monolog/Handler/AmqpExchangeMock.php

@@ -11,19 +11,28 @@
 
 
 namespace Monolog\Handler;
 namespace Monolog\Handler;
 
 
-class MockAMQPExchange extends \AMQPExchange
+class AmqpExchangeMock extends \AMQPExchange
 {
 {
+    protected $messages = array();
+
     public function __construct()
     public function __construct()
     {
     {
     }
     }
 
 
     public function publish($message, $routing_key, $params = 0, $attributes = array())
     public function publish($message, $routing_key, $params = 0, $attributes = array())
     {
     {
+        $this->messages[] = array($message, $routing_key, $params, $attributes);
+
         return true;
         return true;
     }
     }
 
 
+    public function getMessages()
+    {
+        return $this->messages;
+    }
+
     public function setName($name)
     public function setName($name)
     {
     {
         return true;
         return true;
     }
     }
-}
+}

+ 29 - 16
tests/Monolog/Handler/AmqpHandlerTest.php

@@ -13,7 +13,6 @@ namespace Monolog\Handler;
 
 
 use Monolog\TestCase;
 use Monolog\TestCase;
 use Monolog\Logger;
 use Monolog\Logger;
-use Monolog\Handler\MockAMQPExchange;
 
 
 /**
 /**
  * @covers Monolog\Handler\RotatingFileHandler
  * @covers Monolog\Handler\RotatingFileHandler
@@ -27,7 +26,7 @@ class AmqpHandlerTest extends TestCase
         }
         }
 
 
         if (!class_exists('AMQPChannel')) {
         if (!class_exists('AMQPChannel')) {
-            $this->markTestSkipped("Please update AMQP to version >= 1");
+            $this->markTestSkipped("Please update AMQP to version >= 1.0");
         }
         }
     }
     }
 
 
@@ -39,23 +38,37 @@ class AmqpHandlerTest extends TestCase
 
 
         $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
         $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
 
 
+        $expected = array(
+            array(
+                'message' => 'test',
+                'context' => array(
+                    'data' => array(),
+                    'foo' => 34,
+                ),
+                'level' => 300,
+                'level_name' => 'WARNING',
+                'channel' => 'test',
+                'extra' => array(),
+            ),
+            'warn.test',
+            0,
+            array(
+                'delivery_mode' => 2,
+                'Content-type' => 'application/json'
+            )
+        );
+
         $handler->handle($record);
         $handler->handle($record);
+
+        $messages = $exchange->getMessages();
+        $this->assertCount(1, $messages);
+        $messages[0][0] = json_decode($messages[0][0], true);
+        unset($messages[0][0]['datetime']);
+        $this->assertEquals($expected, $messages[0]);
     }
     }
 
 
     protected function getExchange()
     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();
+        return new AmqpExchangeMock();
     }
     }
-}
+}

+ 2 - 2
tests/bootstrap.php

@@ -9,5 +9,5 @@
  * file that was distributed with this source code.
  * file that was distributed with this source code.
  */
  */
 
 
-require_once __DIR__ . "/../vendor/autoload.php";
-require_once __DIR__.'/Monolog/TestCase.php';
+$loader = require_once __DIR__ . "/../vendor/autoload.php";
+$loader->add('Monolog\\', __DIR__);