php.net |  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
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: lstrojny@php.net Assigned: bkw (profile)
Status: Closed Package: amqp (PECL)
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lstrojny@php.net
New email:
PHP Version: OS:

 

 [2012-07-23 13:30 UTC] lstrojny@php.net
Description:
------------
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 
userland.

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

Test script:
---------------
<?php
class AmqpTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->exchange = $this->getMockBuilder('AMQPExchange')
            ->disableOriginalConstructor()
            ->getMock();
        $this->queue = $this->getMockBuilder('AMQPQueue')
            ->disableOriginalConstructor()
            ->getMock();
        $this->channel = $this->getMockBuilder('AMQPChannel')
            ->disableOriginalConstructor()
            ->getMock();
    }

    public function testCallExchangeDeclare()
    {
        $this->assertNull($this->exchange->declare());
    }

    public function testCallQueueDeclare()
    {
        $this->assertNull($this->queue->declare());
    }
}

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

Patches

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

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-12 07:13 UTC] bkw at codingforce dot com
This one is almost merged:
https://github.com/pdezwart/php-amqp/pull/1
 [2012-09-14 15:00 UTC] bkw at codingforce dot com
Hi Lars,

I wonder what you think about my new branch:

https://github.com/bkw/pecl-amqp-official/tree/mocking

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] lstrojny@php.net
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] bkw@php.net
cleaning up.
 [2013-04-17 15:29 UTC] bkw@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: bkw
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jun 15 20:01:23 2021 UTC