Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 59a9df3

Browse files
Merge pull request #115 from whatthejeff/issue_81
2 parents 447a514 + c0c0b2c commit 59a9df3

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Tests/MockObjectTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'AnInterface.php';
4949
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'FunctionCallback.php';
5050
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MethodCallback.php';
51+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'MethodCallbackByReference.php';
5152
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'PartialMockTestClass.php';
5253
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'SomeClass.php';
5354
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'StaticMockTestClass.php';
@@ -564,6 +565,45 @@ public function testVerificationOfNeverFailsWithAnyParameters()
564565
$this->resetMockObjects();
565566
}
566567

568+
public function testMockArgumentsPassedByReference() {
569+
$foo = $this->getMockBuilder('MethodCallbackByReference')
570+
->setMethods(array('bar'))
571+
->disableOriginalConstructor()
572+
->disableArgumentCloning()
573+
->getMock();
574+
575+
$foo->expects($this->any())
576+
->method('bar')
577+
->will($this->returnCallback(array($foo, 'callback')));
578+
579+
$a = $b = $c = 0;
580+
581+
$foo->bar($a, $b, $c);
582+
583+
$this->assertEquals(1, $b);
584+
}
585+
586+
public function testMockArgumentsPassedByReference2() {
587+
$foo = $this->getMockBuilder('MethodCallbackByReference')
588+
->disableOriginalConstructor()
589+
->disableArgumentCloning()
590+
->getMock();
591+
592+
$foo->expects($this->any())
593+
->method('bar')
594+
->will($this->returnCallback(
595+
function ($a, &$b, $c) {
596+
$b = 1;
597+
}
598+
));
599+
600+
$a = $b = $c = 0;
601+
602+
$foo->bar($a, $b, $c);
603+
604+
$this->assertEquals(1, $b);
605+
}
606+
567607
/**
568608
* @requires extension soap
569609
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
class MethodCallbackByReference
3+
{
4+
public function bar($a, &$b, $c) {
5+
Legacy::bar($a, $b, $c);
6+
}
7+
8+
public function callback($a, &$b, $c) {
9+
$b = 1;
10+
}
11+
}

0 commit comments

Comments
 (0)