|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62640 Allow mocking with PHPUnit
Submitted: 2012-07-23 13:30 UTC Modified: 2013-04-17 15:29 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned: bkw (profile)
Status: Closed Package: amqp (PECL)
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2012-07-23 13:30 UTC]
To allow mocking with PHPUnit, PECL amqp needs to allow overriding the 
constructor without calling the parent constructor. Additionally, declare is a 
reserved word in PHP and therefore it is not possible to override that method in 

This is the missing part to make PECL amqp usable with PHPUnit.

Test script:
class AmqpTest extends PHPUnit_Framework_TestCase
    public function setUp()
        $this->exchange = $this->getMockBuilder('AMQPExchange')
        $this->queue = $this->getMockBuilder('AMQPQueue')
        $this->channel = $this->getMockBuilder('AMQPChannel')

    public function testCallExchangeDeclare()

    public function testCallQueueDeclare()

Expected result:
PHPUnit 3.6.11 by Sebastian Bergmann.


Time: 0 seconds, Memory: 6.00Mb

OK (2 tests, 2 assertions)

Actual result:
PHPUnit 3.6.11 by Sebastian Bergmann.

Segmentation fault


mocking.patch (last revision 2012-07-23 13:31 UTC by lars at strojny dot net)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-12 07:13 UTC] bkw at codingforce dot com
This one is almost merged:
 [2012-09-14 15:00 UTC] bkw at codingforce dot com
Hi Lars,

I wonder what you think about my new branch:

This renames AMQPExchange->declare() and AMQPQueue->declare() to
AMQQExchange->declareExchange() and AMQPQueue->declareQueue() to allow
overriding the methods.
It also adds aliases "declare()" for backwards compatibility.

Now mocking with expects()->method('declare') works for me.
What Do you think?
 [2012-09-14 15:05 UTC] bkw at codingforce dot com
> expects()->method('declare')

actually, I meant mocking with 'declareQueue' or 'declateExchange'...
 [2012-09-14 15:12 UTC]
Actually I think this is a pretty good idea to ease mocking.
 [2012-10-26 19:04 UTC] dagguh at gmail dot com
BTW. assertNull is a static method, so you shoudl call it as:
self::assertNull :)
 [2012-11-14 01:05 UTC] bkw at codingforce dot com
fixed in v1.0.9.
 [2013-04-17 15:29 UTC]
cleaning up.
 [2013-04-17 15:29 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: bkw
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 05:03:33 2021 UTC