2
0
Эх сурвалжийг харах

Do away with this horrible mock class

Jordi Boggiano 12 жил өмнө
parent
commit
e92cb54c24

+ 0 - 38
tests/Monolog/Handler/AmqpExchangeMock.php

@@ -1,38 +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 AmqpExchangeMock extends \AMQPExchange
-{
-    protected $messages = array();
-
-    public function __construct()
-    {
-    }
-
-    public function publish($message, $routing_key, $flags = AMQP_NOPARAM, array $attributes = array())
-    {
-        $this->messages[] = array($message, $routing_key, $flags, $attributes);
-
-        return true;
-    }
-
-    public function getMessages()
-    {
-        return $this->messages;
-    }
-
-    public function setName($name)
-    {
-        return true;
-    }
-}

+ 13 - 7
tests/Monolog/Handler/AmqpHandlerTest.php

@@ -32,7 +32,19 @@ class AmqpHandlerTest extends TestCase
 
     public function testHandle()
     {
-        $exchange = $this->getExchange();
+        $messages = array();
+
+        $exchange = $this->getMock('AMQPExchange', array('publish', 'setName'), array(), '', false);
+        $exchange->expects($this->once())
+            ->method('setName')
+            ->with('log')
+        ;
+        $exchange->expects($this->any())
+            ->method('publish')
+            ->will($this->returnCallback(function ($message, $routing_key, $flags = 0, $attributes = array()) use (&$messages) {
+                $messages[] = array($message, $routing_key, $flags, $attributes);
+            }))
+        ;
 
         $handler = new AmqpHandler($exchange, 'log');
 
@@ -60,15 +72,9 @@ class AmqpHandlerTest extends TestCase
 
         $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()
-    {
-        return new AmqpExchangeMock();
-    }
 }