This commit is contained in:
jack
2018-04-20 14:03:37 +08:00
commit cd217f9db8
6494 changed files with 706313 additions and 0 deletions
@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
class InvocationMockerTest extends TestCase
{
public function testWillReturnWithOneValue()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->willReturn(1);
$this->assertEquals(1, $mock->foo());
}
public function testWillReturnWithMultipleValues()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->willReturn(1, 2, 3);
$this->assertEquals(1, $mock->foo());
$this->assertEquals(2, $mock->foo());
$this->assertEquals(3, $mock->foo());
}
public function testWillReturnOnConsecutiveCalls()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->willReturnOnConsecutiveCalls(1, 2, 3);
$this->assertEquals(1, $mock->foo());
$this->assertEquals(2, $mock->foo());
$this->assertEquals(3, $mock->foo());
}
public function testWillReturnByReference()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->willReturnReference($value);
$this->assertNull($mock->foo());
$value = 'foo';
$this->assertSame('foo', $mock->foo());
$value = 'bar';
$this->assertSame('bar', $mock->foo());
}
}
@@ -0,0 +1,135 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
trait BaseTrait
{
protected function hello()
{
return 'hello';
}
}
trait ChildTrait
{
use BaseTrait
{
hello as private hi;
}
protected function hello()
{
return 'hi';
}
protected function world()
{
return $this->hi();
}
}
class Foo
{
use ChildTrait;
public function speak()
{
return $this->world();
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['speak'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function speak()
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'speak', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,105 @@
--TEST--
https://github.com/sebastianbergmann/phpunit-mock-objects/issues/397
--FILE--
<?php
class C
{
public function m(?self $other): self
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
C::class,
[],
'MockC',
true,
true
);
print $mock['code'];
--EXPECT--
class MockC extends C implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['m'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function m(?C $other): C
{
$arguments = [$other];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'C', 'm', $arguments, 'C', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,154 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
abstract class Foo
{
public function one()
{
}
abstract public function two();
abstract protected function three();
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['one', 'two', 'three'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function one()
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'one', $arguments, '', $this, true
)
);
return $result;
}
public function two()
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'two', $arguments, '', $this, true
)
);
return $result;
}
protected function three()
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'three', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,132 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public function bar(Foo $foo)
{
}
public function baz(Foo $foo)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar', 'baz'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function baz(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'baz', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,84 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true)
--FILE--
<?php
class Foo
{
public function __clone()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
parent::__clone();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,83 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true)
--FILE--
<?php
class Foo
{
public function __construct()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,83 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', false)
--FILE--
<?php
class Foo
{
public function __clone()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
false
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,83 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true)
--FILE--
<?php
class Foo
{
public function __construct()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,88 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true)
--FILE--
<?php
interface IFoo
{
public function __construct($bar);
}
class Foo implements IFoo
{
public function __construct($bar)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,88 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true)
--FILE--
<?php
interface IFoo
{
public function __construct($bar);
}
class Foo implements IFoo
{
public function __construct($bar)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,110 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', array('bar'), 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public function bar(Foo $foo)
{
}
public function baz(Foo $foo)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
array('bar'),
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,112 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('ClassWithDeprecatedMethod', [], 'MockFoo', TRUE, TRUE)
--FILE--
<?php
class ClassWithDeprecatedMethod
{
/**
* @deprecated this method
* is deprecated
*/
public function deprecatedMethod()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'ClassWithDeprecatedMethod',
[],
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['deprecatedmethod'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function deprecatedMethod()
{
@trigger_error('The ClassWithDeprecatedMethod::deprecatedMethod method is deprecated (this method is deprecated).', E_USER_DEPRECATED);
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'ClassWithDeprecatedMethod', 'deprecatedMethod', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,98 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public function method()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['method'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function method()
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'method', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,106 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('ClassWithMethodWithVariadicArguments', [], 'MockFoo', true, true)
--FILE--
<?php
class ClassWithMethodWithNullableTypehintedVariadicArguments
{
public function methodWithNullableTypehintedVariadicArguments($a, ?string ...$parameters)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'ClassWithMethodWithNullableTypehintedVariadicArguments',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['methodwithnullabletypehintedvariadicarguments'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function methodWithNullableTypehintedVariadicArguments($a, ?string ...$parameters)
{
$arguments = [$a];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'ClassWithMethodWithNullableTypehintedVariadicArguments', 'methodWithNullableTypehintedVariadicArguments', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,106 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('ClassWithMethodWithVariadicArguments', [], 'MockFoo', true, true)
--FILE--
<?php
class ClassWithMethodWithTypehintedVariadicArguments
{
public function methodWithTypehintedVariadicArguments($a, string ...$parameters)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'ClassWithMethodWithTypehintedVariadicArguments',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['methodwithtypehintedvariadicarguments'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function methodWithTypehintedVariadicArguments($a, string ...$parameters)
{
$arguments = [$a];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'ClassWithMethodWithTypehintedVariadicArguments', 'methodWithTypehintedVariadicArguments', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,106 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('ClassWithMethodWithVariadicArguments', [], 'MockFoo', true, true)
--FILE--
<?php
class ClassWithMethodWithVariadicArguments
{
public function methodWithVariadicArguments($a, ...$parameters)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'ClassWithMethodWithVariadicArguments',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends ClassWithMethodWithVariadicArguments implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['methodwithvariadicarguments'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function methodWithVariadicArguments($a, ...$parameters)
{
$arguments = [$a];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'ClassWithMethodWithVariadicArguments', 'methodWithVariadicArguments', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,104 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
interface Foo
{
public function bar(Foo $foo);
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,133 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true, true)
--FILE--
<?php
class Foo
{
public function bar(Foo $foo)
{
}
public function baz(Foo $foo)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar', 'baz'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function baz(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'baz', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,134 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true, true)
--FILE--
<?php
namespace NS;
class Foo
{
public function bar(Foo $foo)
{
}
public function baz(Foo $foo)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar', 'baz'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(NS\Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'NS\Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function baz(NS\Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'NS\Foo', 'baz', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,86 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true)
--FILE--
<?php
namespace NS;
class Foo
{
public function __clone()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
parent::__clone();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,85 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true)
--FILE--
<?php
namespace NS;
class Foo
{
public function __construct()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,85 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', false)
--FILE--
<?php
namespace NS;
class Foo
{
public function __clone()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
false
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,85 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true)
--FILE--
<?php
namespace NS;
class Foo
{
public function __construct()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,90 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true)
--FILE--
<?php
namespace NS;
interface IFoo
{
public function __construct($bar);
}
class Foo implements IFoo
{
public function __construct($bar)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,90 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true)
--FILE--
<?php
namespace NS;
interface IFoo
{
public function __construct($bar);
}
class Foo implements IFoo
{
public function __construct($bar)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,112 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', array('bar'), 'MockFoo', true, true)
--FILE--
<?php
namespace NS;
class Foo
{
public function bar(Foo $foo)
{
}
public function baz(Foo $foo)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
array('bar'),
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(NS\Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'NS\Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,106 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NS\Foo', [], 'MockFoo', true, true)
--FILE--
<?php
namespace NS;
interface Foo
{
public function bar(Foo $foo);
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, NS\Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(NS\Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'NS\Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,81 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('NonExistentClass', [], 'MockFoo', true, true)
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NonExistentClass',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class NonExistentClass
{
}
class MockFoo extends NonExistentClass implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,89 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'NS\Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
namespace NS {
class Foo
{
}
}
namespace {
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
}
@@ -0,0 +1,89 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'\NS\Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
namespace NS {
class Foo
{
}
}
namespace {
class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = [];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
}
@@ -0,0 +1,106 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public function bar(?int $x)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(?int $x)
{
$arguments = [$x];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,128 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', null, 'ProxyFoo', true, true, true, true)
--FILE--
<?php
class Foo
{
public function bar(Foo $foo)
{
}
public function baz(Foo $foo)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo', [], 'ProxyFoo', true, true, true, true
);
print $mock['code'];
?>
--EXPECT--
class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar', 'baz'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $arguments);
}
public function baz(Foo $foo)
{
$arguments = [$foo];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'baz', $arguments, '', $this, true
)
);
return call_user_func_array(array($this->__phpunit_originalObject, "baz"), $arguments);
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,104 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
interface Foo
{
public function bar(): Closure;
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(): Closure
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, 'Closure', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,111 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
final class FinalClass
{
}
class Foo
{
public function bar(): FinalClass
{
return new FinalClass();
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(): FinalClass
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, 'FinalClass', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,104 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
interface Foo
{
public function bar(): Generator;
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(): Generator
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, 'Generator', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,104 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
interface Foo
{
public function bar(string $baz): ?string;
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(string $baz): ?string
{
$arguments = [$baz];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '?string', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,107 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public function bar(string $baz): Bar
{
return 'test';
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(string $baz): Bar
{
$arguments = [$baz];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, 'Bar', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,110 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Bar', [], 'MockBar', true, true)
--FILE--
<?php
abstract class Foo
{
abstract public function baz();
}
class Bar extends Foo
{
public function baz(): parent
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Bar',
[],
'MockBar',
true,
true
);
print $mock['code'];
--EXPECT--
class MockBar extends Bar implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['baz'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function baz(): Foo
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Bar', 'baz', $arguments, 'Foo', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,104 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
interface Foo
{
public function bar(string $baz): self;
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(string $baz): Foo
{
$arguments = [$baz];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, 'Foo', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,90 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public static function bar(string $baz): Bar
{
return 'test';
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public static function bar(string $baz): Bar
{
throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "bar" cannot be invoked on mock object');
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,102 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
interface Foo
{
public function bar(string $baz): void;
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(string $baz): void
{
$arguments = [$baz];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, 'void', $this, true
)
);
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,106 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--FILE--
<?php
class Foo
{
public function bar(string $baz)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);
print $mock['code'];
?>
--EXPECT--
class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['bar'];
private $__phpunit_returnValueGeneration = true;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(string $baz)
{
$arguments = [$baz];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Foo', 'bar', $arguments, '', $this, true
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration)
{
$this->__phpunit_returnValueGeneration = $returnValueGeneration;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
@@ -0,0 +1,37 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch')
--SKIPIF--
<?php
if (!extension_loaded('soap')) echo 'skip: SOAP extension is required';
?>
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
print $generator->generateClassFromWsdl(
__DIR__ . '/../_fixture/GoogleSearch.wsdl',
'GoogleSearch'
);
?>
--EXPECTF--
class GoogleSearch extends \SoapClient
{
public function __construct($wsdl, array $options)
{
parent::__construct('%s/GoogleSearch.wsdl', $options);
}
public function doGoogleSearch($key, $q, $start, $maxResults, $filter, $restrict, $safeSearch, $lr, $ie, $oe)
{
}
public function doGetCachedPage($key, $url)
{
}
public function doSpellingSuggestion($key, $phrase)
{
}
}
@@ -0,0 +1,38 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch')
--SKIPIF--
<?php
if (!extension_loaded('soap')) echo 'skip: SOAP extension is required';
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
print $generator->generateClassFromWsdl(
__DIR__ . '/../_fixture/GoogleSearch.wsdl',
'My\\Space\\GoogleSearch'
);
?>
--EXPECTF--
namespace My\Space;
class GoogleSearch extends \SoapClient
{
public function __construct($wsdl, array $options)
{
parent::__construct('%s/GoogleSearch.wsdl', $options);
}
public function doGoogleSearch($key, $q, $start, $maxResults, $filter, $restrict, $safeSearch, $lr, $ie, $oe)
{
}
public function doGetCachedPage($key, $url)
{
}
public function doSpellingSuggestion($key, $phrase)
{
}
}
@@ -0,0 +1,30 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch', array('doGoogleSearch'))
--SKIPIF--
<?php
if (!extension_loaded('soap')) echo 'skip: SOAP extension is required';
?>
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new \PHPUnit\Framework\MockObject\Generator;
print $generator->generateClassFromWsdl(
__DIR__ . '/../_fixture/GoogleSearch.wsdl',
'GoogleSearch',
array('doGoogleSearch')
);
?>
--EXPECTF--
class GoogleSearch extends \SoapClient
{
public function __construct($wsdl, array $options)
{
parent::__construct('%s/GoogleSearch.wsdl', $options);
}
public function doGoogleSearch($key, $q, $start, $maxResults, $filter, $restrict, $safeSearch, $lr, $ie, $oe)
{
}
}
@@ -0,0 +1,213 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\MockObject\Generator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
* @covers \PHPUnit\Framework\MockObject\Generator
*
* @uses \PHPUnit\Framework\MockObject\InvocationMocker
* @uses \PHPUnit\Framework\MockObject\Builder\InvocationMocker
* @uses \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation
* @uses \PHPUnit\Framework\MockObject\Invocation\StaticInvocation
* @uses \PHPUnit\Framework\MockObject\Matcher
* @uses \PHPUnit\Framework\MockObject\Matcher\InvokedRecorder
* @uses \PHPUnit\Framework\MockObject\Matcher\MethodName
* @uses \PHPUnit\Framework\MockObject\Stub\ReturnStub
* @uses \PHPUnit\Framework\MockObject\Matcher\InvokedCount
*/
class GeneratorTest extends TestCase
{
/**
* @var Generator
*/
private $generator;
protected function setUp()
{
$this->generator = new Generator;
}
public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock()
{
$this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class);
$this->generator->getMock(stdClass::class, [0]);
}
public function testGetMockCanCreateNonExistingFunctions()
{
$mock = $this->generator->getMock(stdClass::class, ['testFunction']);
$this->assertTrue(method_exists($mock, 'testFunction'));
}
public function testGetMockGeneratorFails()
{
$this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class);
$this->expectExceptionMessage('duplicates: "foo, bar, foo" (duplicate: "foo")');
$this->generator->getMock(stdClass::class, ['foo', 'bar', 'foo']);
}
public function testGetMockBlacklistedMethodNamesPhp7()
{
$mock = $this->generator->getMock(InterfaceWithSemiReservedMethodName::class);
$this->assertTrue(method_exists($mock, 'unset'));
$this->assertInstanceOf(InterfaceWithSemiReservedMethodName::class, $mock);
}
public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces()
{
$mock = $this->generator->getMockForAbstractClass(Countable::class);
$this->assertTrue(method_exists($mock, 'count'));
}
public function testGetMockForAbstractClassStubbingAbstractClass()
{
$mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class);
$this->assertTrue(method_exists($mock, 'doSomething'));
}
public function testGetMockForAbstractClassWithNonExistentMethods()
{
$mock = $this->generator->getMockForAbstractClass(
AbstractMockTestClass::class,
[],
'',
true,
true,
true,
['nonexistentMethod']
);
$this->assertTrue(method_exists($mock, 'nonexistentMethod'));
$this->assertTrue(method_exists($mock, 'doSomething'));
}
public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMethodWhenNoMethodsWereInformed()
{
$mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class);
$mock->expects($this->any())
->method('doSomething')
->willReturn('testing');
$this->assertEquals('testing', $mock->doSomething());
$this->assertEquals(1, $mock->returnAnything());
}
/**
* @dataProvider getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider
*/
public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName)
{
$this->expectException(PHPUnit\Framework\Exception::class);
$this->generator->getMockForAbstractClass($className, [], $mockClassName);
}
public function testGetMockForAbstractClassAbstractClassDoesNotExist()
{
$this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class);
$this->generator->getMockForAbstractClass('Tux');
}
public function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider()
{
return [
'className not a string' => [[], ''],
'mockClassName not a string' => [Countable::class, new stdClass],
];
}
public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods()
{
$mock = $this->generator->getMockForTrait(
AbstractTrait::class,
[],
'',
true,
true,
true,
['nonexistentMethod']
);
$this->assertTrue(method_exists($mock, 'nonexistentMethod'));
$this->assertTrue(method_exists($mock, 'doSomething'));
$this->assertTrue($mock->mockableMethod());
$this->assertTrue($mock->anotherMockableMethod());
}
public function testGetMockForTraitStubbingAbstractMethod()
{
$mock = $this->generator->getMockForTrait(AbstractTrait::class);
$this->assertTrue(method_exists($mock, 'doSomething'));
}
public function testGetMockForSingletonWithReflectionSuccess()
{
$mock = $this->generator->getMock(SingletonClass::class, ['doSomething'], [], '', false);
$this->assertInstanceOf('SingletonClass', $mock);
}
public function testExceptionIsRaisedForMutuallyExclusiveOptions()
{
$this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class);
$this->generator->getMock(stdClass::class, [], [], '', false, true, true, true, true);
}
public function testCanImplementInterfacesThatHaveMethodsWithReturnTypes()
{
$stub = $this->generator->getMock([AnInterfaceWithReturnType::class, AnInterface::class]);
$this->assertInstanceOf(AnInterfaceWithReturnType::class, $stub);
$this->assertInstanceOf(AnInterface::class, $stub);
$this->assertInstanceOf(MockObject::class, $stub);
}
public function testCanConfigureMethodsForDoubleOfNonExistentClass()
{
$className = 'X' . md5(microtime());
$mock = $this->generator->getMock($className, ['someMethod']);
$this->assertInstanceOf($className, $mock);
}
public function testCanInvokeMethodsOfNonExistentClass()
{
$className = 'X' . md5(microtime());
$mock = $this->generator->getMock($className, ['someMethod']);
$mock->expects($this->once())->method('someMethod');
$this->assertNull($mock->someMethod());
}
public function testMockingOfThrowable()
{
$stub = $this->generator->getMock(ExceptionWithThrowable::class);
$this->assertInstanceOf(ExceptionWithThrowable::class, $stub);
$this->assertInstanceOf(Exception::class, $stub);
$this->assertInstanceOf(MockObject::class, $stub);
}
}
@@ -0,0 +1,120 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\MockObject\Invocation\ObjectInvocation;
use PHPUnit\Framework\TestCase;
class ObjectInvocationTest extends TestCase
{
public function testConstructorRequiresClassAndMethodAndParametersAndObject()
{
$this->assertInstanceOf(
ObjectInvocation::class,
new ObjectInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType',
new stdClass
)
);
}
public function testAllowToGetClassNameSetInConstructor()
{
$invocation = new ObjectInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType',
new stdClass
);
$this->assertSame('FooClass', $invocation->getClassName());
}
public function testAllowToGetMethodNameSetInConstructor()
{
$invocation = new ObjectInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType',
new stdClass
);
$this->assertSame('FooMethod', $invocation->getMethodName());
}
public function testAllowToGetObjectSetInConstructor()
{
$expectedObject = new stdClass;
$invocation = new ObjectInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType',
$expectedObject
);
$this->assertSame($expectedObject, $invocation->getObject());
}
public function testAllowToGetMethodParametersSetInConstructor()
{
$expectedParameters = [
'foo', 5, ['a', 'b'], new stdClass, null, false
];
$invocation = new ObjectInvocation(
'FooClass',
'FooMethod',
$expectedParameters,
'ReturnType',
new stdClass
);
$this->assertSame($expectedParameters, $invocation->getParameters());
}
public function testConstructorAllowToSetFlagCloneObjectsInParameters()
{
$parameters = [new stdClass];
$cloneObjects = true;
$invocation = new ObjectInvocation(
'FooClass',
'FooMethod',
$parameters,
'ReturnType',
new stdClass,
$cloneObjects
);
$this->assertEquals($parameters, $invocation->getParameters());
$this->assertNotSame($parameters, $invocation->getParameters());
}
public function testAllowToGetReturnTypeSetInConstructor()
{
$expectedReturnType = 'string';
$invocation = new ObjectInvocation(
'FooClass',
'FooMethod',
['an_argument'],
$expectedReturnType,
new stdClass
);
$this->assertSame($expectedReturnType, $invocation->getReturnType());
}
}
@@ -0,0 +1,114 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\Invocation\StaticInvocation;
class StaticInvocationTest extends TestCase
{
public function testConstructorRequiresClassAndMethodAndParameters()
{
$this->assertInstanceOf(
StaticInvocation::class,
new StaticInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType'
)
);
}
public function testAllowToGetClassNameSetInConstructor()
{
$invocation = new StaticInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType'
);
$this->assertSame('FooClass', $invocation->getClassName());
}
public function testAllowToGetMethodNameSetInConstructor()
{
$invocation = new StaticInvocation(
'FooClass',
'FooMethod',
['an_argument'],
'ReturnType'
);
$this->assertSame('FooMethod', $invocation->getMethodName());
}
public function testAllowToGetMethodParametersSetInConstructor()
{
$expectedParameters = [
'foo', 5, ['a', 'b'], new stdClass, null, false
];
$invocation = new StaticInvocation(
'FooClass',
'FooMethod',
$expectedParameters,
'ReturnType'
);
$this->assertSame($expectedParameters, $invocation->getParameters());
}
public function testConstructorAllowToSetFlagCloneObjectsInParameters()
{
$parameters = [new stdClass];
$cloneObjects = true;
$invocation = new StaticInvocation(
'FooClass',
'FooMethod',
$parameters,
'ReturnType',
$cloneObjects
);
$this->assertEquals($parameters, $invocation->getParameters());
$this->assertNotSame($parameters, $invocation->getParameters());
}
public function testAllowToGetReturnTypeSetInConstructor()
{
$expectedReturnType = 'string';
$invocation = new StaticInvocation(
'FooClass',
'FooMethod',
['an_argument'],
$expectedReturnType
);
$this->assertSame($expectedReturnType, $invocation->getReturnType());
}
public function testToStringWillReturnEmptyString()
{
$expectedReturnType = 'string';
$invocation = new StaticInvocation(
'FooClass',
'__toString',
[],
''
);
$this->assertSame($expectedReturnType, $invocation->getReturnType());
$this->assertSame('', $invocation->generateReturnValue());
}
}
@@ -0,0 +1,68 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\ExpectationFailedException;
class ConsecutiveParametersTest extends TestCase
{
public function testIntegration()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->withConsecutive(
['bar'],
[21, 42]
);
$this->assertNull($mock->foo('bar'));
$this->assertNull($mock->foo(21, 42));
}
public function testIntegrationWithLessAssertionsThanMethodCalls()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->withConsecutive(
['bar']
);
$this->assertNull($mock->foo('bar'));
$this->assertNull($mock->foo(21, 42));
}
public function testIntegrationExpectingException()
{
$mock = $this->getMockBuilder(stdClass::class)
->setMethods(['foo'])
->getMock();
$mock->expects($this->any())
->method('foo')
->withConsecutive(
['bar'],
[21, 42]
);
$mock->foo('bar');
$this->expectException(ExpectationFailedException::class);
$mock->foo('invalid');
}
}
@@ -0,0 +1,129 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockBuilder;
class MockBuilderTest extends TestCase
{
public function testMockBuilderRequiresClassName()
{
$mock = $this->getMockBuilder(Mockable::class)->getMock();
$this->assertInstanceOf(Mockable::class, $mock);
}
public function testByDefaultMocksAllMethods()
{
$mock = $this->getMockBuilder(Mockable::class)->getMock();
$this->assertNull($mock->mockableMethod());
$this->assertNull($mock->anotherMockableMethod());
}
public function testMethodsToMockCanBeSpecified()
{
$mock = $this->getMockBuilder(Mockable::class)
->setMethods(['mockableMethod'])
->getMock();
$this->assertNull($mock->mockableMethod());
$this->assertTrue($mock->anotherMockableMethod());
}
public function testMethodExceptionsToMockCanBeSpecified()
{
$mock = $this->getMockBuilder(Mockable::class)
->setMethodsExcept(['mockableMethod'])
->getMock();
$this->assertTrue($mock->mockableMethod());
$this->assertNull($mock->anotherMockableMethod());
}
public function testEmptyMethodExceptionsToMockCanBeSpecified()
{
$mock = $this->getMockBuilder(Mockable::class)
->setMethodsExcept()
->getMock();
$this->assertNull($mock->mockableMethod());
$this->assertNull($mock->anotherMockableMethod());
}
public function testByDefaultDoesNotPassArgumentsToTheConstructor()
{
$mock = $this->getMockBuilder(Mockable::class)->getMock();
$this->assertEquals([null, null], $mock->constructorArgs);
}
public function testMockClassNameCanBeSpecified()
{
$mock = $this->getMockBuilder(Mockable::class)
->setMockClassName('ACustomClassName')
->getMock();
$this->assertInstanceOf(ACustomClassName::class, $mock);
}
public function testConstructorArgumentsCanBeSpecified()
{
$mock = $this->getMockBuilder(Mockable::class)
->setConstructorArgs([23, 42])
->getMock();
$this->assertEquals([23, 42], $mock->constructorArgs);
}
public function testOriginalConstructorCanBeDisabled()
{
$mock = $this->getMockBuilder(Mockable::class)
->disableOriginalConstructor()
->getMock();
$this->assertNull($mock->constructorArgs);
}
public function testByDefaultOriginalCloneIsPreserved()
{
$mock = $this->getMockBuilder(Mockable::class)
->getMock();
$cloned = clone $mock;
$this->assertTrue($cloned->cloned);
}
public function testOriginalCloneCanBeDisabled()
{
$mock = $this->getMockBuilder(Mockable::class)
->disableOriginalClone()
->getMock();
$mock->cloned = false;
$cloned = clone $mock;
$this->assertFalse($cloned->cloned);
}
public function testProvidesAFluentInterface()
{
$spec = $this->getMockBuilder(Mockable::class)
->setMethods(['mockableMethod'])
->setConstructorArgs([])
->setMockClassName('DummyClassName')
->disableOriginalConstructor()
->disableOriginalClone()
->disableAutoload();
$this->assertInstanceOf(MockBuilder::class, $spec);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the phpunit-mock-objects package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
class ProxyObjectTest extends TestCase
{
public function testMockedMethodIsProxiedToOriginalMethod()
{
$proxy = $this->getMockBuilder(Bar::class)
->enableProxyingToOriginalMethods()
->getMock();
$proxy->expects($this->once())
->method('doSomethingElse');
$foo = new Foo;
$this->assertEquals('result', $foo->doSomething($proxy));
}
public function testMockedMethodWithReferenceIsProxiedToOriginalMethod()
{
$proxy = $this->getMockBuilder(MethodCallbackByReference::class)
->enableProxyingToOriginalMethods()
->getMock();
$a = $b = $c = 0;
$proxy->callback($a, $b, $c);
$this->assertEquals(1, $b);
}
}
@@ -0,0 +1,10 @@
<?php
abstract class AbstractMockTestClass implements MockTestInterface
{
abstract public function doSomething();
public function returnAnything()
{
return 1;
}
}
@@ -0,0 +1,15 @@
<?php
trait AbstractTrait
{
abstract public function doSomething();
public function mockableMethod()
{
return true;
}
public function anotherMockableMethod()
{
return true;
}
}
@@ -0,0 +1,6 @@
<?php
interface AnInterface
{
public function doSomething();
}
@@ -0,0 +1,5 @@
<?php
interface AnInterfaceWithReturnType
{
public function returnAnArray(): array;
}
@@ -0,0 +1,5 @@
<?php
interface AnotherInterface
{
public function doSomethingElse();
}
@@ -0,0 +1,8 @@
<?php
class Bar
{
public function doSomethingElse()
{
return 'result';
}
}
@@ -0,0 +1,15 @@
<?php
class ClassThatImplementsSerializable implements Serializable
{
public function serialize()
{
return get_object_vars($this);
}
public function unserialize($serialized)
{
foreach (unserialize($serialized) as $key => $value) {
$this->{$key} = $value;
}
}
}
@@ -0,0 +1,56 @@
<?php
class ClassWithAllPossibleReturnTypes
{
public function methodWithNoReturnTypeDeclaration()
{
}
public function methodWithVoidReturnTypeDeclaration(): void
{
}
public function methodWithStringReturnTypeDeclaration(): string
{
return 'string';
}
public function methodWithFloatReturnTypeDeclaration(): float
{
return 1.0;
}
public function methodWithIntReturnTypeDeclaration(): int
{
return 1;
}
public function methodWithBoolReturnTypeDeclaration(): bool
{
return true;
}
public function methodWithArrayReturnTypeDeclaration(): array
{
return ['string'];
}
public function methodWithTraversableReturnTypeDeclaration(): Traversable
{
return new ArrayIterator(['string']);
}
public function methodWithGeneratorReturnTypeDeclaration(): Generator
{
yield 1;
}
public function methodWithObjectReturnTypeDeclaration(): object
{
return new Exception;
}
public function methodWithClassReturnTypeDeclaration(): stdClass
{
return new stdClass;
}
}
@@ -0,0 +1,7 @@
<?php
class ClassWithSelfTypeHint
{
public function foo(self $foo)
{
}
}
@@ -0,0 +1,7 @@
<?php
class ClassWithStaticMethod
{
public static function staticMethod()
{
}
}
@@ -0,0 +1,8 @@
<?php
trait ExampleTrait
{
public function ohHai()
{
return __FUNCTION__;
}
}
@@ -0,0 +1,5 @@
<?php
interface ExceptionWithThrowable extends \Throwable
{
}
@@ -0,0 +1,8 @@
<?php
class Foo
{
public function doSomething(Bar $bar)
{
return $bar->doSomethingElse();
}
}
@@ -0,0 +1,9 @@
<?php
function functionCallback()
{
$args = func_get_args();
if ($args == ['foo', 'bar']) {
return 'pass';
}
}
@@ -0,0 +1,198 @@
<?xml version="1.0"?>
<!-- WSDL description of the Google Web APIs.
The Google Web APIs are in beta release. All interfaces are subject to
change as we refine and extend our APIs. Please see the terms of use
for more information. -->
<!-- Revision 2002-08-16 -->
<definitions name="GoogleSearch"
targetNamespace="urn:GoogleSearch"
xmlns:typens="urn:GoogleSearch"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- Types for search - result elements, directory categories -->
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:GoogleSearch">
<xsd:complexType name="GoogleSearchResult">
<xsd:all>
<xsd:element name="documentFiltering" type="xsd:boolean"/>
<xsd:element name="searchComments" type="xsd:string"/>
<xsd:element name="estimatedTotalResultsCount" type="xsd:int"/>
<xsd:element name="estimateIsExact" type="xsd:boolean"/>
<xsd:element name="resultElements" type="typens:ResultElementArray"/>
<xsd:element name="searchQuery" type="xsd:string"/>
<xsd:element name="startIndex" type="xsd:int"/>
<xsd:element name="endIndex" type="xsd:int"/>
<xsd:element name="searchTips" type="xsd:string"/>
<xsd:element name="directoryCategories" type="typens:DirectoryCategoryArray"/>
<xsd:element name="searchTime" type="xsd:double"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ResultElement">
<xsd:all>
<xsd:element name="summary" type="xsd:string"/>
<xsd:element name="URL" type="xsd:string"/>
<xsd:element name="snippet" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="cachedSize" type="xsd:string"/>
<xsd:element name="relatedInformationPresent" type="xsd:boolean"/>
<xsd:element name="hostName" type="xsd:string"/>
<xsd:element name="directoryCategory" type="typens:DirectoryCategory"/>
<xsd:element name="directoryTitle" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ResultElementArray">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:ResultElement[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DirectoryCategoryArray">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:DirectoryCategory[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DirectoryCategory">
<xsd:all>
<xsd:element name="fullViewableName" type="xsd:string"/>
<xsd:element name="specialEncoding" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<!-- Messages for Google Web APIs - cached page, search, spelling. -->
<message name="doGetCachedPage">
<part name="key" type="xsd:string"/>
<part name="url" type="xsd:string"/>
</message>
<message name="doGetCachedPageResponse">
<part name="return" type="xsd:base64Binary"/>
</message>
<message name="doSpellingSuggestion">
<part name="key" type="xsd:string"/>
<part name="phrase" type="xsd:string"/>
</message>
<message name="doSpellingSuggestionResponse">
<part name="return" type="xsd:string"/>
</message>
<!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->
<message name="doGoogleSearch">
<part name="key" type="xsd:string"/>
<part name="q" type="xsd:string"/>
<part name="start" type="xsd:int"/>
<part name="maxResults" type="xsd:int"/>
<part name="filter" type="xsd:boolean"/>
<part name="restrict" type="xsd:string"/>
<part name="safeSearch" type="xsd:boolean"/>
<part name="lr" type="xsd:string"/>
<part name="ie" type="xsd:string"/>
<part name="oe" type="xsd:string"/>
</message>
<message name="doGoogleSearchResponse">
<part name="return" type="typens:GoogleSearchResult"/>
</message>
<!-- Port for Google Web APIs, "GoogleSearch" -->
<portType name="GoogleSearchPort">
<operation name="doGetCachedPage">
<input message="typens:doGetCachedPage"/>
<output message="typens:doGetCachedPageResponse"/>
</operation>
<operation name="doSpellingSuggestion">
<input message="typens:doSpellingSuggestion"/>
<output message="typens:doSpellingSuggestionResponse"/>
</operation>
<operation name="doGoogleSearch">
<input message="typens:doGoogleSearch"/>
<output message="typens:doGoogleSearchResponse"/>
</operation>
</portType>
<!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->
<binding name="GoogleSearchBinding" type="typens:GoogleSearchPort">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="doGetCachedPage">
<soap:operation soapAction="urn:GoogleSearchAction"/>
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="doSpellingSuggestion">
<soap:operation soapAction="urn:GoogleSearchAction"/>
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="doGoogleSearch">
<soap:operation soapAction="urn:GoogleSearchAction"/>
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<!-- Endpoint for Google Web APIs -->
<service name="GoogleSearchService">
<port name="GoogleSearchPort" binding="typens:GoogleSearchBinding">
<soap:address location="http://api.google.com/search/beta2"/>
</port>
</service>
</definitions>
@@ -0,0 +1,5 @@
<?php
interface InterfaceWithSemiReservedMethodName
{
public function unset();
}
@@ -0,0 +1,5 @@
<?php
interface InterfaceWithStaticMethod
{
public static function staticMethod();
}
@@ -0,0 +1,21 @@
<?php
class MethodCallback
{
public static function staticCallback()
{
$args = func_get_args();
if ($args == ['foo', 'bar']) {
return 'pass';
}
}
public function nonStaticCallback()
{
$args = func_get_args();
if ($args == ['foo', 'bar']) {
return 'pass';
}
}
}
@@ -0,0 +1,13 @@
<?php
class MethodCallbackByReference
{
public function bar(&$a, &$b, $c)
{
Legacy::bar($a, $b, $c);
}
public function callback(&$a, &$b, $c)
{
$b = 1;
}
}
@@ -0,0 +1,6 @@
<?php
interface MockTestInterface
{
public function returnAnything();
public function returnAnythingElse();
}
@@ -0,0 +1,28 @@
<?php
class Mockable
{
public $constructorArgs;
public $cloned;
public function __construct($arg1 = null, $arg2 = null)
{
$this->constructorArgs = [$arg1, $arg2];
}
public function mockableMethod()
{
// something different from NULL
return true;
}
public function anotherMockableMethod()
{
// something different from NULL
return true;
}
public function __clone()
{
$this->cloned = true;
}
}
@@ -0,0 +1,18 @@
<?php
class PartialMockTestClass
{
public $constructorCalled = false;
public function __construct()
{
$this->constructorCalled = true;
}
public function doSomething()
{
}
public function doAnotherThing()
{
}
}
@@ -0,0 +1,28 @@
<?php
class SingletonClass
{
public static function getInstance()
{
}
public function doSomething()
{
}
protected function __construct()
{
}
final private function __sleep()
{
}
final private function __wakeup()
{
}
final private function __clone()
{
}
}
@@ -0,0 +1,13 @@
<?php
class SomeClass
{
public function doSomething($a, $b)
{
return;
}
public function doSomethingElse($c)
{
return;
}
}
@@ -0,0 +1,12 @@
<?php
class StaticMockTestClass
{
public static function doSomething()
{
}
public static function doSomethingElse()
{
return static::doSomething();
}
}
@@ -0,0 +1,8 @@
<?php
class StringableClass
{
public function __toString()
{
return '12345';
}
}
@@ -0,0 +1,5 @@
<?php
interface TraversableMockTestInterface extends \Traversable
{
}
@@ -0,0 +1,3 @@
<?php
require __DIR__ . '/_fixture/FunctionCallback.php';
require __DIR__ . '/../vendor/autoload.php';