Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions
web/vendor/phpunit/phpunit-mock-objects
.gitattributes.gitignore.travis.ymlCONTRIBUTING.mdLICENSEREADME.mdbuild.xml
build
composer.jsonphpunit.xml.dist
src/Framework/MockObject
tests

View file

@ -0,0 +1 @@
*.php diff=php

View file

@ -0,0 +1,8 @@
build/coverage
build/logs
cache.properties
phpunit.xml
/vendor
/composer.lock
/composer.phar
/.idea

View file

@ -0,0 +1,26 @@
language: php
before_script:
- composer self-update
- composer install --no-interaction --prefer-source --dev
script: ./vendor/bin/phpunit --configuration ./build/travis-ci.xml
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
notifications:
email: false
webhooks:
urls:
- https://webhooks.gitter.im/e/6668f52f3dd4e3f81960
on_success: always
on_failure: always
on_start: false

View file

@ -0,0 +1,5 @@
Pull Requests for bug fixes should be made against the current release branch (1.2).
Pull Requests for new features should be made against master.
For further notes please refer to [https://github.com/sebastianbergmann/phpunit/blob/master/CONTRIBUTING.md](https://github.com/sebastianbergmann/phpunit/blob/master/CONTRIBUTING.md)

View file

@ -0,0 +1,33 @@
PHPUnit_MockObject
Copyright (c) 2002-2015, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Sebastian Bergmann nor the names of his
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View file

@ -0,0 +1,21 @@
[![Build Status](https://img.shields.io/travis/sebastianbergmann/phpunit-mock-objects/2.3.svg?style=flat-square)](https://travis-ci.org/sebastianbergmann/phpunit-mock-objects)
[![Latest Stable Version](https://img.shields.io/packagist/v/phpunit/phpunit-mock-objects.svg?style=flat-square)](https://packagist.org/packages/phpunit/phpunit-mock-objects)
# PHPUnit_MockObject
**PHPUnit_MockObject** is the default mock object library for PHPUnit.
## Requirements
* PHP 5.3.3 is required but using the latest version of PHP is highly recommended
## Installation
To add PHPUnit_MockObject as a local, per-project dependency to your project, simply add a dependency on `phpunit/phpunit-mock-objects` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on PHPUnit_MockObject 2.3:
{
"require": {
"phpunit/phpunit-mock-objects": "2.3.*"
}
}

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="PHPUnit_MockObjects">
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>
<delete>
<fileset dir="${basedir}/build">
<include name="**/*.phar" />
</fileset>
</delete>
</target>
<target name="composer" depends="clean" description="Install dependencies with Composer">
<tstamp>
<format property="thirty.days.ago" pattern="MM/dd/yyyy hh:mm aa" offset="-30" unit="day"/>
</tstamp>
<delete>
<fileset dir="${basedir}">
<include name="composer.phar" />
<date datetime="${thirty.days.ago}" when="before"/>
</fileset>
</delete>
<get src="https://getcomposer.org/composer.phar" dest="${basedir}/composer.phar" skipexisting="true"/>
<exec executable="php">
<arg value="composer.phar"/>
<arg value="install"/>
</exec>
</target>
<target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer">
<exec executable="phpcs">
<arg value="--standard=PSR2" />
<arg value="--extensions=php" />
<arg path="${basedir}/src" />
<arg path="${basedir}/tests" />
</exec>
</target>
</project>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.2/phpunit.xsd"
bootstrap="../tests/bootstrap.php"
backupGlobals="false"
verbose="true">
<testsuite name="PHPUnit Mock Objects">
<directory suffix="Test.php">../tests</directory>
<directory suffix=".phpt">../tests</directory>
</testsuite>
</phpunit>

View file

@ -0,0 +1,50 @@
{
"name": "phpunit/phpunit-mock-objects",
"description": "Mock Object library for PHPUnit",
"type": "library",
"keywords": [
"xunit",
"mock"
],
"homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit-mock-objects/issues",
"irc": "irc://irc.freenode.net/phpunit"
},
"require": {
"php": ">=5.3.3",
"phpunit/php-text-template": "~1.2",
"doctrine/instantiator": "^1.0.2",
"sebastian/exporter": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"suggest": {
"ext-soap": "*"
},
"autoload": {
"classmap": [
"src/"
]
},
"autoload-dev": {
"classmap": [
"tests/_fixture/"
]
},
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev"
}
}
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.2/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
verbose="true">
<testsuite name="PHPUnit Mock Objects">
<directory suffix="Test.php">tests</directory>
<directory suffix=".phpt">tests</directory>
</testsuite>
<logging>
<log type="coverage-html" target="build/coverage"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -0,0 +1,30 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Builder interface for unique identifiers.
*
* Defines the interface for recording unique identifiers. The identifiers
* can be used to define the invocation order of expectations. The expectation
* is recorded using id() and then defined in order using
* PHPUnit_Framework_MockObject_Builder_Match::after().
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Builder_Identity
{
/**
* Sets the identification of the expectation to $id.
*
* @note The identifier is unique per mock object.
* @param string $id Unique identifiation of expectation.
*/
public function id($id);
}

View file

@ -0,0 +1,255 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Builder for mocked or stubbed invocations.
*
* Provides methods for building expectations without having to resort to
* instantiating the various matchers manually. These methods also form a
* more natural way of reading the expectation. This class should be together
* with the test case PHPUnit_Framework_MockObject_TestCase.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Builder_InvocationMocker implements PHPUnit_Framework_MockObject_Builder_MethodNameMatch
{
/**
* @var PHPUnit_Framework_MockObject_Stub_MatcherCollection
*/
protected $collection;
/**
* @var PHPUnit_Framework_MockObject_Matcher
*/
protected $matcher;
/**
* @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher
*/
public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher)
{
$this->collection = $collection;
$this->matcher = new PHPUnit_Framework_MockObject_Matcher(
$invocationMatcher
);
$this->collection->addMatcher($this->matcher);
}
/**
* @return PHPUnit_Framework_MockObject_Matcher
*/
public function getMatcher()
{
return $this->matcher;
}
/**
* @param mixed $id
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function id($id)
{
$this->collection->registerId($id, $this);
return $this;
}
/**
* @param PHPUnit_Framework_MockObject_Stub $stub
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function will(PHPUnit_Framework_MockObject_Stub $stub)
{
$this->matcher->stub = $stub;
return $this;
}
/**
* @param mixed $value
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturn($value)
{
$stub = new PHPUnit_Framework_MockObject_Stub_Return(
$value
);
return $this->will($stub);
}
/**
* @param array $valueMap
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnMap(array $valueMap)
{
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap(
$valueMap
);
return $this->will($stub);
}
/**
* @param mixed $argumentIndex
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnArgument($argumentIndex)
{
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument(
$argumentIndex
);
return $this->will($stub);
}
/**
* @param callable $callback
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnCallback($callback)
{
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback(
$callback
);
return $this->will($stub);
}
/**
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnSelf()
{
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf();
return $this->will($stub);
}
/**
* @param mixed $value, ...
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnOnConsecutiveCalls()
{
$args = func_get_args();
$stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($args);
return $this->will($stub);
}
/**
* @param Exception $exception
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willThrowException(Exception $exception)
{
$stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception);
return $this->will($stub);
}
/**
* @param mixed $id
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function after($id)
{
$this->matcher->afterMatchBuilderId = $id;
return $this;
}
/**
* Validate that a parameters matcher can be defined, throw exceptions otherwise.
*
* @throws PHPUnit_Framework_Exception
*/
private function canDefineParameters()
{
if ($this->matcher->methodNameMatcher === null) {
throw new PHPUnit_Framework_Exception(
'Method name matcher is not defined, cannot define parameter ' .
' matcher without one'
);
}
if ($this->matcher->parametersMatcher !== null) {
throw new PHPUnit_Framework_Exception(
'Parameter matcher is already defined, cannot redefine'
);
}
}
/**
* @param mixed $argument, ...
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function with()
{
$args = func_get_args();
$this->canDefineParameters();
$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($args);
return $this;
}
/**
* @param mixed ...$argument
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function withConsecutive()
{
$args = func_get_args();
$this->canDefineParameters();
$this->matcher->parametersMatcher =
new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($args);
return $this;
}
/**
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function withAnyParameters()
{
$this->canDefineParameters();
$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters;
return $this;
}
/**
* @param PHPUnit_Framework_Constraint|string $constraint
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function method($constraint)
{
if ($this->matcher->methodNameMatcher !== null) {
throw new PHPUnit_Framework_Exception(
'Method name matcher is already defined, cannot redefine'
);
}
$this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint);
return $this;
}
}

View file

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Builder interface for invocation order matches.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Builder_Match extends PHPUnit_Framework_MockObject_Builder_Stub
{
/**
* Defines the expectation which must occur before the current is valid.
*
* @param string $id The identification of the expectation that should
* occur before this one.
* @return PHPUnit_Framework_MockObject_Builder_Stub
*/
public function after($id);
}

View file

@ -0,0 +1,28 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Builder interface for matcher of method names.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Builder_MethodNameMatch extends PHPUnit_Framework_MockObject_Builder_ParametersMatch
{
/**
* Adds a new method name match and returns the parameter match object for
* further matching possibilities.
*
* @param PHPUnit_Framework_Constraint $name
* Constraint for matching method, if a string is passed it will use
* the PHPUnit_Framework_Constraint_IsEqual.
* @return PHPUnit_Framework_MockObject_Builder_ParametersMatch
*/
public function method($name);
}

View file

@ -0,0 +1,39 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for builders which can register builders with a given identification.
*
* This interface relates to PHPUnit_Framework_MockObject_Builder_Identity.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Builder_Namespace
{
/**
* Looks up the match builder with identification $id and returns it.
*
* @param string $id The identifiction of the match builder.
* @return PHPUnit_Framework_MockObject_Builder_Match
*/
public function lookupId($id);
/**
* Registers the match builder $builder with the identification $id. The
* builder can later be looked up using lookupId() to figure out if it
* has been invoked.
*
* @param string $id
* The identification of the match builder.
* @param PHPUnit_Framework_MockObject_Builder_Match $builder
* The builder which is being registered.
*/
public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder);
}

View file

@ -0,0 +1,49 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Builder interface for parameter matchers.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Builder_ParametersMatch extends PHPUnit_Framework_MockObject_Builder_Match
{
/**
* Sets the parameters to match for, each parameter to this funtion will
* be part of match. To perform specific matches or constraints create a
* new PHPUnit_Framework_Constraint and use it for the parameter.
* If the parameter value is not a constraint it will use the
* PHPUnit_Framework_Constraint_IsEqual for the value.
*
* Some examples:
* <code>
* // match first parameter with value 2
* $b->with(2);
* // match first parameter with value 'smock' and second identical to 42
* $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42));
* </code>
*
* @return PHPUnit_Framework_MockObject_Builder_ParametersMatch
*/
public function with();
/**
* Sets a matcher which allows any kind of parameters.
*
* Some examples:
* <code>
* // match any number of parameters
* $b->withAnyParamers();
* </code>
*
* @return PHPUnit_Framework_MockObject_Matcher_AnyParameters
*/
public function withAnyParameters();
}

View file

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Builder interface for stubs which are actions replacing an invocation.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Builder_Stub extends PHPUnit_Framework_MockObject_Builder_Identity
{
/**
* Stubs the matching method with the stub object $stub. Any invocations of
* the matched method will now be handled by the stub instead.
*
* @param PHPUnit_Framework_MockObject_Stub $stub The stub object.
* @return PHPUnit_Framework_MockObject_Builder_Identity
*/
public function will(PHPUnit_Framework_MockObject_Stub $stub);
}

View file

@ -0,0 +1,16 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* @since Class available since Release 2.0.6
*/
class PHPUnit_Framework_MockObject_BadMethodCallException extends BadMethodCallException implements PHPUnit_Framework_MockObject_Exception
{
}

View file

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for exceptions used by PHPUnit_MockObject.
*
* @since Interface available since Release 2.0.6
*/
interface PHPUnit_Framework_MockObject_Exception
{
}

View file

@ -0,0 +1,16 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* @since Class available since Release 2.0.6
*/
class PHPUnit_Framework_MockObject_RuntimeException extends RuntimeException implements PHPUnit_Framework_MockObject_Exception
{
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,36 @@
{prologue}{class_declaration}
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
{clone}{mocked_methods}
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
{method}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}{epilogue}

View file

@ -0,0 +1,7 @@
public function method()
{
$any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array(array($expects, 'method'), func_get_args());
}

View file

@ -0,0 +1,4 @@
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}

View file

@ -0,0 +1,22 @@
{modifier} function {reference}{method_name}({arguments_decl})
{
$arguments = array({arguments_call});
$count = func_num_args();
if ($count > {arguments_count}) {
$_arguments = func_get_args();
for ($i = {arguments_count}; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new PHPUnit_Framework_MockObject_Invocation_Object(
'{class_name}', '{method_name}', $arguments, $this, {clone_arguments}
)
);
return $result;
}

View file

@ -0,0 +1,5 @@
{modifier} function {reference}{method_name}({arguments_decl})
{
throw new PHPUnit_Framework_MockObject_BadMethodCallException;
}

View file

@ -0,0 +1,22 @@
{modifier} function {reference}{method_name}({arguments_decl})
{
$arguments = array({arguments_call});
$count = func_num_args();
if ($count > {arguments_count}) {
$_arguments = func_get_args();
for ($i = {arguments_count}; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$this->__phpunit_getInvocationMocker()->invoke(
new PHPUnit_Framework_MockObject_Invocation_Object(
'{class_name}', '{method_name}', $arguments, $this, {clone_arguments}
)
);
return call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $arguments);
}

View file

@ -0,0 +1,4 @@
{prologue}class {class_name}
{
use {trait_name};
}

View file

@ -0,0 +1,5 @@
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
parent::__clone();
}

View file

@ -0,0 +1,7 @@
{namespace}class {class_name} extends \SoapClient
{
public function __construct($wsdl, array $options)
{
parent::__construct('{wsdl}', $options);
}
{methods}}

View file

@ -0,0 +1,4 @@
public function {method_name}({arguments})
{
}

View file

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for invocations.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Invocation
{
}

View file

@ -0,0 +1,35 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Represents a non-static invocation.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Invocation_Object extends PHPUnit_Framework_MockObject_Invocation_Static
{
/**
* @var object
*/
public $object;
/**
* @param string $className
* @param string $methodname
* @param array $parameters
* @param object $object
* @param object $cloneObjects
*/
public function __construct($className, $methodName, array $parameters, $object, $cloneObjects = false)
{
parent::__construct($className, $methodName, $parameters, $cloneObjects);
$this->object = $object;
}
}

View file

@ -0,0 +1,152 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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 SebastianBergmann\Exporter\Exporter;
/**
* Represents a static invocation.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Invocation_Static implements PHPUnit_Framework_MockObject_Invocation, PHPUnit_Framework_SelfDescribing
{
/**
* @var array
*/
protected static $uncloneableExtensions = array(
'mysqli' => true,
'SQLite' => true,
'sqlite3' => true,
'tidy' => true,
'xmlwriter' => true,
'xsl' => true
);
/**
* @var array
*/
protected static $uncloneableClasses = array(
'Closure',
'COMPersistHelper',
'IteratorIterator',
'RecursiveIteratorIterator',
'SplFileObject',
'PDORow',
'ZipArchive'
);
/**
* @var string
*/
public $className;
/**
* @var string
*/
public $methodName;
/**
* @var array
*/
public $parameters;
/**
* @param string $className
* @param string $methodname
* @param array $parameters
* @param bool $cloneObjects
*/
public function __construct($className, $methodName, array $parameters, $cloneObjects = false)
{
$this->className = $className;
$this->methodName = $methodName;
$this->parameters = $parameters;
if (!$cloneObjects) {
return;
}
foreach ($this->parameters as $key => $value) {
if (is_object($value)) {
$this->parameters[$key] = $this->cloneObject($value);
}
}
}
/**
* @return string
*/
public function toString()
{
$exporter = new Exporter;
return sprintf(
'%s::%s(%s)',
$this->className,
$this->methodName,
implode(
', ',
array_map(
array($exporter, 'shortenedExport'),
$this->parameters
)
)
);
}
/**
* @param object $original
* @return object
*/
protected function cloneObject($original)
{
$cloneable = null;
$object = new ReflectionObject($original);
// Check the blacklist before asking PHP reflection to work around
// https://bugs.php.net/bug.php?id=53967
if ($object->isInternal() &&
isset(self::$uncloneableExtensions[$object->getExtensionName()])) {
$cloneable = false;
}
if ($cloneable === null) {
foreach (self::$uncloneableClasses as $class) {
if ($original instanceof $class) {
$cloneable = false;
break;
}
}
}
if ($cloneable === null && method_exists($object, 'isCloneable')) {
$cloneable = $object->isCloneable();
}
if ($cloneable === null && $object->hasMethod('__clone')) {
$method = $object->getMethod('__clone');
$cloneable = $method->isPublic();
}
if ($cloneable === null) {
$cloneable = true;
}
if ($cloneable) {
try {
return clone $original;
} catch (Exception $e) {
return $original;
}
} else {
return $original;
}
}
}

View file

@ -0,0 +1,156 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Mocker for invocations which are sent from
* PHPUnit_Framework_MockObject_MockObject objects.
*
* Keeps track of all expectations and stubs as well as registering
* identifications for builders.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework_MockObject_Stub_MatcherCollection, PHPUnit_Framework_MockObject_Invokable, PHPUnit_Framework_MockObject_Builder_Namespace
{
/**
* @var PHPUnit_Framework_MockObject_Matcher_Invocation[]
*/
protected $matchers = array();
/**
* @var PHPUnit_Framework_MockObject_Builder_Match[]
*/
protected $builderMap = array();
/**
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
*/
public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
{
$this->matchers[] = $matcher;
}
/**
* @since Method available since Release 1.1.0
*/
public function hasMatchers()
{
foreach ($this->matchers as $matcher) {
if ($matcher->hasMatchers()) {
return true;
}
}
return false;
}
/**
* @param mixed $id
* @return bool|null
*/
public function lookupId($id)
{
if (isset($this->builderMap[$id])) {
return $this->builderMap[$id];
}
return;
}
/**
* @param mixed $id
* @param PHPUnit_Framework_MockObject_Builder_Match $builder
* @throws PHPUnit_Framework_Exception
*/
public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder)
{
if (isset($this->builderMap[$id])) {
throw new PHPUnit_Framework_Exception(
'Match builder with id <' . $id . '> is already registered.'
);
}
$this->builderMap[$id] = $builder;
}
/**
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
{
return new PHPUnit_Framework_MockObject_Builder_InvocationMocker(
$this,
$matcher
);
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return mixed
*/
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$exception = null;
$hasReturnValue = false;
if (strtolower($invocation->methodName) == '__tostring') {
$returnValue = '';
} else {
$returnValue = null;
}
foreach ($this->matchers as $match) {
try {
if ($match->matches($invocation)) {
$value = $match->invoked($invocation);
if (!$hasReturnValue) {
$returnValue = $value;
$hasReturnValue = true;
}
}
} catch (Exception $e) {
$exception = $e;
}
}
if ($exception !== null) {
throw $exception;
}
return $returnValue;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
foreach ($this->matchers as $matcher) {
if (!$matcher->matches($invocation)) {
return false;
}
}
return true;
}
/**
* @return bool
*/
public function verify()
{
foreach ($this->matchers as $matcher) {
$matcher->verify();
}
}
}

View file

@ -0,0 +1,39 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for classes which can be invoked.
*
* The invocation will be taken from a mock object and passed to an object
* of this class.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Invokable extends PHPUnit_Framework_MockObject_Verifiable
{
/**
* Invokes the invocation object $invocation so that it can be checked for
* expectations or matched against stubs.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* The invocation object passed from mock object.
* @return object
*/
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation);
/**
* Checks if the invocation matches.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* The invocation object passed from mock object.
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation);
}

View file

@ -0,0 +1,271 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Main matcher which defines a full expectation using method, parameter and
* invocation matchers.
* This matcher encapsulates all the other matchers and allows the builder to
* set the specific matchers when the appropriate methods are called (once(),
* where() etc.).
*
* All properties are public so that they can easily be accessed by the builder.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher implements PHPUnit_Framework_MockObject_Matcher_Invocation
{
/**
* @var PHPUnit_Framework_MockObject_Matcher_Invocation
*/
public $invocationMatcher;
/**
* @var mixed
*/
public $afterMatchBuilderId = null;
/**
* @var bool
*/
public $afterMatchBuilderIsInvoked = false;
/**
* @var PHPUnit_Framework_MockObject_Matcher_MethodName
*/
public $methodNameMatcher = null;
/**
* @var PHPUnit_Framework_MockObject_Matcher_Parameters
*/
public $parametersMatcher = null;
/**
* @var PHPUnit_Framework_MockObject_Stub
*/
public $stub = null;
/**
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher
*/
public function __construct(PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher)
{
$this->invocationMatcher = $invocationMatcher;
}
/**
* @return string
*/
public function toString()
{
$list = array();
if ($this->invocationMatcher !== null) {
$list[] = $this->invocationMatcher->toString();
}
if ($this->methodNameMatcher !== null) {
$list[] = 'where ' . $this->methodNameMatcher->toString();
}
if ($this->parametersMatcher !== null) {
$list[] = 'and ' . $this->parametersMatcher->toString();
}
if ($this->afterMatchBuilderId !== null) {
$list[] = 'after ' . $this->afterMatchBuilderId;
}
if ($this->stub !== null) {
$list[] = 'will ' . $this->stub->toString();
}
return implode(' ', $list);
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return mixed
*/
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
{
if ($this->invocationMatcher === null) {
throw new PHPUnit_Framework_Exception(
'No invocation matcher is set'
);
}
if ($this->methodNameMatcher === null) {
throw new PHPUnit_Framework_Exception('No method matcher is set');
}
if ($this->afterMatchBuilderId !== null) {
$builder = $invocation->object
->__phpunit_getInvocationMocker()
->lookupId($this->afterMatchBuilderId);
if (!$builder) {
throw new PHPUnit_Framework_Exception(
sprintf(
'No builder found for match builder identification <%s>',
$this->afterMatchBuilderId
)
);
}
$matcher = $builder->getMatcher();
if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) {
$this->afterMatchBuilderIsInvoked = true;
}
}
$this->invocationMatcher->invoked($invocation);
try {
if ($this->parametersMatcher !== null &&
!$this->parametersMatcher->matches($invocation)) {
$this->parametersMatcher->verify();
}
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
"Expectation failed for %s when %s\n%s",
$this->methodNameMatcher->toString(),
$this->invocationMatcher->toString(),
$e->getMessage()
),
$e->getComparisonFailure()
);
}
if ($this->stub) {
return $this->stub->invoke($invocation);
}
return;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
if ($this->afterMatchBuilderId !== null) {
$builder = $invocation->object
->__phpunit_getInvocationMocker()
->lookupId($this->afterMatchBuilderId);
if (!$builder) {
throw new PHPUnit_Framework_Exception(
sprintf(
'No builder found for match builder identification <%s>',
$this->afterMatchBuilderId
)
);
}
$matcher = $builder->getMatcher();
if (!$matcher) {
return false;
}
if (!$matcher->invocationMatcher->hasBeenInvoked()) {
return false;
}
}
if ($this->invocationMatcher === null) {
throw new PHPUnit_Framework_Exception(
'No invocation matcher is set'
);
}
if ($this->methodNameMatcher === null) {
throw new PHPUnit_Framework_Exception('No method matcher is set');
}
if (!$this->invocationMatcher->matches($invocation)) {
return false;
}
try {
if (!$this->methodNameMatcher->matches($invocation)) {
return false;
}
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
"Expectation failed for %s when %s\n%s",
$this->methodNameMatcher->toString(),
$this->invocationMatcher->toString(),
$e->getMessage()
),
$e->getComparisonFailure()
);
}
return true;
}
/**
* @throws PHPUnit_Framework_Exception
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
if ($this->invocationMatcher === null) {
throw new PHPUnit_Framework_Exception(
'No invocation matcher is set'
);
}
if ($this->methodNameMatcher === null) {
throw new PHPUnit_Framework_Exception('No method matcher is set');
}
try {
$this->invocationMatcher->verify();
if ($this->parametersMatcher === null) {
$this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters;
}
$invocationIsAny = get_class($this->invocationMatcher) === 'PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount';
$invocationIsNever = get_class($this->invocationMatcher) === 'PHPUnit_Framework_MockObject_Matcher_InvokedCount' && $this->invocationMatcher->isNever();
if (!$invocationIsAny && !$invocationIsNever) {
$this->parametersMatcher->verify();
}
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
"Expectation failed for %s when %s.\n%s",
$this->methodNameMatcher->toString(),
$this->invocationMatcher->toString(),
PHPUnit_Framework_TestFailure::exceptionToString($e)
)
);
}
}
/**
* @since Method available since Release 1.2.4
*/
public function hasMatchers()
{
if ($this->invocationMatcher !== null &&
!$this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount) {
return true;
}
return false;
}
}

View file

@ -0,0 +1,32 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which checks if a method has been invoked zero or more
* times. This matcher will always match.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
{
/**
* @return string
*/
public function toString()
{
return 'invoked zero or more times';
}
/**
*/
public function verify()
{
}
}

View file

@ -0,0 +1,34 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which allows any parameters to a method.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_AnyParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
{
/**
* @return string
*/
public function toString()
{
return 'with any parameters';
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
return true;
}
}

View file

@ -0,0 +1,123 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which looks for sets of specific parameters in the invocations.
*
* Checks the parameters of the incoming invocations, the parameter list is
* checked against the defined constraints in $parameters. If the constraint
* is met it will return true in matches().
*
* It takes a list of match groups and and increases a call index after each invocation.
* So the first invocation uses the first group of constraints, the second the next and so on.
*/
class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
{
/**
* @var array
*/
private $_parameterGroups = array();
/**
* @var array
*/
private $_invocations = array();
/**
* @param array $parameterGroups
*/
public function __construct(array $parameterGroups)
{
foreach ($parameterGroups as $index => $parameters) {
foreach ($parameters as $parameter) {
if (!($parameter instanceof \PHPUnit_Framework_Constraint)) {
$parameter = new \PHPUnit_Framework_Constraint_IsEqual($parameter);
}
$this->_parameterGroups[$index][] = $parameter;
}
}
}
/**
* @return string
*/
public function toString()
{
$text = 'with consecutive parameters';
return $text;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$this->_invocations[] = $invocation;
$callIndex = count($this->_invocations) - 1;
$this->verifyInvocation($invocation, $callIndex);
return false;
}
public function verify()
{
foreach ($this->_invocations as $callIndex => $invocation) {
$this->verifyInvocation($invocation, $callIndex);
}
}
/**
* Verify a single invocation
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @param int $callIndex
* @throws PHPUnit_Framework_ExpectationFailedException
*/
private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex)
{
if (isset($this->_parameterGroups[$callIndex])) {
$parameters = $this->_parameterGroups[$callIndex];
} else {
// no parameter assertion for this call index
return;
}
if ($invocation === null) {
throw new PHPUnit_Framework_ExpectationFailedException(
'Mocked method does not exist.'
);
}
if (count($invocation->parameters) < count($parameters)) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
'Parameter count for invocation %s is too low.',
$invocation->toString()
)
);
}
foreach ($parameters as $i => $parameter) {
$parameter->evaluate(
$invocation->parameters[$i],
sprintf(
'Parameter %s for invocation #%d %s does not match expected ' .
'value.',
$i,
$callIndex,
$invocation->toString()
)
);
}
}
}

View file

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for classes which matches an invocation based on its
* method name, argument, order or call count.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Matcher_Invocation extends PHPUnit_Framework_SelfDescribing, PHPUnit_Framework_MockObject_Verifiable
{
/**
* Registers the invocation $invocation in the object as being invoked.
* This will only occur after matches() returns true which means the
* current invocation is the correct one.
*
* The matcher can store information from the invocation which can later
* be checked in verify(), or it can check the values directly and throw
* and exception if an expectation is not met.
*
* If the matcher is a stub it will also have a return value.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* Object containing information on a mocked or stubbed method which
* was invoked.
* @return mixed
*/
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation);
/**
* Checks if the invocation $invocation matches the current rules. If it does
* the matcher will get the invoked() method called which should check if an
* expectation is met.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* Object containing information on a mocked or stubbed method which
* was invoked.
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation);
}

View file

@ -0,0 +1,86 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which checks if a method was invoked at a certain index.
*
* If the expected index number does not match the current invocation index it
* will not match which means it skips all method and parameter matching. Only
* once the index is reached will the method and parameter start matching and
* verifying.
*
* If the index is never reached it will throw an exception in index.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation
{
/**
* @var int
*/
protected $sequenceIndex;
/**
* @var int
*/
protected $currentIndex = -1;
/**
* @param int $sequenceIndex
*/
public function __construct($sequenceIndex)
{
$this->sequenceIndex = $sequenceIndex;
}
/**
* @return string
*/
public function toString()
{
return 'invoked at sequence index ' . $this->sequenceIndex;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$this->currentIndex++;
return $this->currentIndex == $this->sequenceIndex;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
*/
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
{
}
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
if ($this->currentIndex < $this->sequenceIndex) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
'The expected invocation at index %s was never reached.',
$this->sequenceIndex
)
);
}
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which checks if a method has been invoked at least
* N times.
*
* @since Class available since Release 2.2.0
*/
class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
{
/**
* @var int
*/
private $requiredInvocations;
/**
* @param int $requiredInvocations
*/
public function __construct($requiredInvocations)
{
$this->requiredInvocations = $requiredInvocations;
}
/**
* @return string
*/
public function toString()
{
return 'invoked at least ' . $this->requiredInvocations . ' times';
}
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
$count = $this->getInvocationCount();
if ($count < $this->requiredInvocations) {
throw new PHPUnit_Framework_ExpectationFailedException(
'Expected invocation at least ' . $this->requiredInvocations .
' times but it occured ' . $count . ' time(s).'
);
}
}
}

View file

@ -0,0 +1,45 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which checks if a method has been invoked at least one
* time.
*
* If the number of invocations is 0 it will throw an exception in verify.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
{
/**
* @return string
*/
public function toString()
{
return 'invoked at least once';
}
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
$count = $this->getInvocationCount();
if ($count < 1) {
throw new PHPUnit_Framework_ExpectationFailedException(
'Expected invocation at least once but it never occured.'
);
}
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which checks if a method has been invoked at least
* N times.
*
* @since Class available since Release 2.2.0
*/
class PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
{
/**
* @var int
*/
private $allowedInvocations;
/**
* @param int $allowedInvocations
*/
public function __construct($allowedInvocations)
{
$this->allowedInvocations = $allowedInvocations;
}
/**
* @return string
*/
public function toString()
{
return 'invoked at most ' . $this->allowedInvocations . ' times';
}
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
$count = $this->getInvocationCount();
if ($count > $this->allowedInvocations) {
throw new PHPUnit_Framework_ExpectationFailedException(
'Expected invocation at most ' . $this->allowedInvocations .
' times but it occured ' . $count . ' time(s).'
);
}
}
}

View file

@ -0,0 +1,109 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which checks if a method has been invoked a certain amount
* of times.
* If the number of invocations exceeds the value it will immediately throw an
* exception,
* If the number is less it will later be checked in verify() and also throw an
* exception.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_InvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
{
/**
* @var int
*/
protected $expectedCount;
/**
* @param int $expectedCount
*/
public function __construct($expectedCount)
{
$this->expectedCount = $expectedCount;
}
/**
* @return bool
*/
public function isNever()
{
return $this->expectedCount == 0;
}
/**
* @return string
*/
public function toString()
{
return 'invoked ' . $this->expectedCount . ' time(s)';
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
{
parent::invoked($invocation);
$count = $this->getInvocationCount();
if ($count > $this->expectedCount) {
$message = $invocation->toString() . ' ';
switch ($this->expectedCount) {
case 0: {
$message .= 'was not expected to be called.';
}
break;
case 1: {
$message .= 'was not expected to be called more than once.';
}
break;
default: {
$message .= sprintf(
'was not expected to be called more than %d times.',
$this->expectedCount
);
}
}
throw new PHPUnit_Framework_ExpectationFailedException($message);
}
}
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
$count = $this->getInvocationCount();
if ($count !== $this->expectedCount) {
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf(
'Method was expected to be called %d times, ' .
'actually called %d times.',
$this->expectedCount,
$count
)
);
}
}
}

View file

@ -0,0 +1,67 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Records invocations and provides convenience methods for checking them later
* on.
* This abstract class can be implemented by matchers which needs to check the
* number of times an invocation has occured.
*
* @since Class available since Release 1.0.0
* @abstract
*/
abstract class PHPUnit_Framework_MockObject_Matcher_InvokedRecorder implements PHPUnit_Framework_MockObject_Matcher_Invocation
{
/**
* @var PHPUnit_Framework_MockObject_Invocation[]
*/
protected $invocations = array();
/**
* @return int
*/
public function getInvocationCount()
{
return count($this->invocations);
}
/**
* @return PHPUnit_Framework_MockObject_Invocation[]
*/
public function getInvocations()
{
return $this->invocations;
}
/**
* @return bool
*/
public function hasBeenInvoked()
{
return count($this->invocations) > 0;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
*/
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$this->invocations[] = $invocation;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
return true;
}
}

View file

@ -0,0 +1,66 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which looks for a specific method name in the invocations.
*
* Checks the method name all incoming invocations, the name is checked against
* the defined constraint $constraint. If the constraint is met it will return
* true in matches().
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_MethodName extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
{
/**
* @var PHPUnit_Framework_Constraint
*/
protected $constraint;
/**
* @param PHPUnit_Framework_Constraint|string
* @throws PHPUnit_Framework_Constraint
*/
public function __construct($constraint)
{
if (!$constraint instanceof PHPUnit_Framework_Constraint) {
if (!is_string($constraint)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
$constraint = new PHPUnit_Framework_Constraint_IsEqual(
$constraint,
0,
10,
false,
true
);
}
$this->constraint = $constraint;
}
/**
* @return string
*/
public function toString()
{
return 'method name ' . $this->constraint->toString();
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
return $this->constraint->evaluate($invocation->methodName, '', true);
}
}

View file

@ -0,0 +1,127 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which looks for specific parameters in the invocations.
*
* Checks the parameters of all incoming invocations, the parameter list is
* checked against the defined constraints in $parameters. If the constraint
* is met it will return true in matches().
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Matcher_Parameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
{
/**
* @var PHPUnit_Framework_Constraint[]
*/
protected $parameters = array();
/**
* @var PHPUnit_Framework_MockObject_Invocation
*/
protected $invocation;
/**
* @param array $parameters
*/
public function __construct(array $parameters)
{
foreach ($parameters as $parameter) {
if (!($parameter instanceof PHPUnit_Framework_Constraint)) {
$parameter = new PHPUnit_Framework_Constraint_IsEqual(
$parameter
);
}
$this->parameters[] = $parameter;
}
}
/**
* @return string
*/
public function toString()
{
$text = 'with parameter';
foreach ($this->parameters as $index => $parameter) {
if ($index > 0) {
$text .= ' and';
}
$text .= ' ' . $index . ' ' . $parameter->toString();
}
return $text;
}
/**
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* @return bool
*/
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$this->invocation = $invocation;
return $this->verify();
}
/**
* Checks if the invocation $invocation matches the current rules. If it
* does the matcher will get the invoked() method called which should check
* if an expectation is met.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* Object containing information on a mocked or stubbed method which
* was invoked.
* @return bool
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify()
{
if ($this->invocation === null) {
throw new PHPUnit_Framework_ExpectationFailedException(
'Mocked method does not exist.'
);
}
if (count($this->invocation->parameters) < count($this->parameters)) {
$message = 'Parameter count for invocation %s is too low.';
// The user called `->with($this->anything())`, but may have meant
// `->withAnyParameters()`.
//
// @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199
if (count($this->parameters) === 1 &&
get_class($this->parameters[0]) === 'PHPUnit_Framework_Constraint_IsAnything') {
$message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.";
}
throw new PHPUnit_Framework_ExpectationFailedException(
sprintf($message, $this->invocation->toString())
);
}
foreach ($this->parameters as $i => $parameter) {
$parameter->evaluate(
$this->invocation->parameters[$i],
sprintf(
'Parameter %s for invocation %s does not match expected ' .
'value.',
$i,
$this->invocation->toString()
)
);
}
return true;
}
}

View file

@ -0,0 +1,56 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Invocation matcher which does not care about previous state from earlier
* invocations.
*
* This abstract class can be implemented by matchers which does not care about
* state but only the current run-time value of the invocation itself.
*
* @since Class available since Release 1.0.0
* @abstract
*/
abstract class PHPUnit_Framework_MockObject_Matcher_StatelessInvocation implements PHPUnit_Framework_MockObject_Matcher_Invocation
{
/**
* Registers the invocation $invocation in the object as being invoked.
* This will only occur after matches() returns true which means the
* current invocation is the correct one.
*
* The matcher can store information from the invocation which can later
* be checked in verify(), or it can check the values directly and throw
* and exception if an expectation is not met.
*
* If the matcher is a stub it will also have a return value.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* Object containing information on a mocked or stubbed method which
* was invoked.
* @return mixed
*/
public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
{
}
/**
* Checks if the invocation $invocation matches the current rules. If it does
* the matcher will get the invoked() method called which should check if an
* expectation is met.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* Object containing information on a mocked or stubbed method which
* was invoked.
* @return bool
*/
public function verify()
{
}
}

View file

@ -0,0 +1,322 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Implementation of the Builder pattern for Mock objects.
*
* @since File available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_MockBuilder
{
/**
* @var PHPUnit_Framework_TestCase
*/
private $testCase;
/**
* @var string
*/
private $type;
/**
* @var array
*/
private $methods = array();
/**
* @var string
*/
private $mockClassName = '';
/**
* @var array
*/
private $constructorArgs = array();
/**
* @var bool
*/
private $originalConstructor = true;
/**
* @var bool
*/
private $originalClone = true;
/**
* @var bool
*/
private $autoload = true;
/**
* @var bool
*/
private $cloneArguments = false;
/**
* @var bool
*/
private $callOriginalMethods = false;
/**
* @var object
*/
private $proxyTarget = null;
/**
* @param PHPUnit_Framework_TestCase $testCase
* @param array|string $type
*/
public function __construct(PHPUnit_Framework_TestCase $testCase, $type)
{
$this->testCase = $testCase;
$this->type = $type;
}
/**
* Creates a mock object using a fluent interface.
*
* @return PHPUnit_Framework_MockObject_MockObject
*/
public function getMock()
{
return $this->testCase->getMock(
$this->type,
$this->methods,
$this->constructorArgs,
$this->mockClassName,
$this->originalConstructor,
$this->originalClone,
$this->autoload,
$this->cloneArguments,
$this->callOriginalMethods,
$this->proxyTarget
);
}
/**
* Creates a mock object for an abstract class using a fluent interface.
*
* @return PHPUnit_Framework_MockObject_MockObject
*/
public function getMockForAbstractClass()
{
return $this->testCase->getMockForAbstractClass(
$this->type,
$this->constructorArgs,
$this->mockClassName,
$this->originalConstructor,
$this->originalClone,
$this->autoload,
$this->methods,
$this->cloneArguments
);
}
/**
* Creates a mock object for a trait using a fluent interface.
*
* @return PHPUnit_Framework_MockObject_MockObject
*/
public function getMockForTrait()
{
return $this->testCase->getMockForTrait(
$this->type,
$this->constructorArgs,
$this->mockClassName,
$this->originalConstructor,
$this->originalClone,
$this->autoload,
$this->methods,
$this->cloneArguments
);
}
/**
* Specifies the subset of methods to mock. Default is to mock all of them.
*
* @param array|null $methods
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function setMethods($methods)
{
$this->methods = $methods;
return $this;
}
/**
* Specifies the arguments for the constructor.
*
* @param array $args
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function setConstructorArgs(array $args)
{
$this->constructorArgs = $args;
return $this;
}
/**
* Specifies the name for the mock class.
*
* @param string $name
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function setMockClassName($name)
{
$this->mockClassName = $name;
return $this;
}
/**
* Disables the invocation of the original constructor.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function disableOriginalConstructor()
{
$this->originalConstructor = false;
return $this;
}
/**
* Enables the invocation of the original constructor.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 1.2.0
*/
public function enableOriginalConstructor()
{
$this->originalConstructor = true;
return $this;
}
/**
* Disables the invocation of the original clone constructor.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function disableOriginalClone()
{
$this->originalClone = false;
return $this;
}
/**
* Enables the invocation of the original clone constructor.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 1.2.0
*/
public function enableOriginalClone()
{
$this->originalClone = true;
return $this;
}
/**
* Disables the use of class autoloading while creating the mock object.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function disableAutoload()
{
$this->autoload = false;
return $this;
}
/**
* Enables the use of class autoloading while creating the mock object.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 1.2.0
*/
public function enableAutoload()
{
$this->autoload = true;
return $this;
}
/**
* Disables the cloning of arguments passed to mocked methods.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 1.2.0
*/
public function disableArgumentCloning()
{
$this->cloneArguments = false;
return $this;
}
/**
* Enables the cloning of arguments passed to mocked methods.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 1.2.0
*/
public function enableArgumentCloning()
{
$this->cloneArguments = true;
return $this;
}
/**
* Enables the invocation of the original methods.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 2.0.0
*/
public function enableProxyingToOriginalMethods()
{
$this->callOriginalMethods = true;
return $this;
}
/**
* Disables the invocation of the original methods.
*
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 2.0.0
*/
public function disableProxyingToOriginalMethods()
{
$this->callOriginalMethods = false;
$this->proxyTarget = null;
return $this;
}
/**
* Sets the proxy target.
*
* @param object $object
* @return PHPUnit_Framework_MockObject_MockBuilder
* @since Method available since Release 2.0.0
*/
public function setProxyTarget($object)
{
$this->proxyTarget = $object;
return $this;
}
}

View file

@ -0,0 +1,47 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for all mock objects which are generated by
* PHPUnit_Framework_MockObject_MockBuilder.
*
* @method PHPUnit_Framework_MockObject_Builder_InvocationMocker method($constraint)
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_MockObject /*extends PHPUnit_Framework_MockObject_Verifiable*/
{
/**
* Registers a new expectation in the mock object and returns the match
* object which can be infused with further details.
*
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher);
/**
* @return PHPUnit_Framework_MockObject_InvocationMocker
* @since Method available since Release 2.0.0
*/
public function __phpunit_setOriginalObject($originalObject);
/**
* @return PHPUnit_Framework_MockObject_InvocationMocker
*/
public function __phpunit_getInvocationMocker();
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function __phpunit_verify();
}

View file

@ -0,0 +1,31 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* An object that stubs the process of a normal method for a mock object.
*
* The stub object will replace the code for the stubbed method and return a
* specific value instead of the original value.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Stub extends PHPUnit_Framework_SelfDescribing
{
/**
* Fakes the processing of the invocation $invocation by returning a
* specific value.
*
* @param PHPUnit_Framework_MockObject_Invocation $invocation
* The invocation which was mocked and matched by the current method
* and argument matchers.
* @return mixed
*/
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation);
}

View file

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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 SebastianBergmann\Exporter\Exporter;
/**
* Stubs a method by returning a user-defined stack of values.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls implements PHPUnit_Framework_MockObject_Stub
{
protected $stack;
protected $value;
public function __construct($stack)
{
$this->stack = $stack;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$this->value = array_shift($this->stack);
if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) {
$this->value = $this->value->invoke($invocation);
}
return $this->value;
}
public function toString()
{
$exporter = new Exporter;
return sprintf(
'return user-specified value %s',
$exporter->export($this->value)
);
}
}

View file

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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 SebastianBergmann\Exporter\Exporter;
/**
* Stubs a method by raising a user-defined exception.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Stub_Exception implements PHPUnit_Framework_MockObject_Stub
{
protected $exception;
public function __construct(Exception $exception)
{
$this->exception = $exception;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
throw $this->exception;
}
public function toString()
{
$exporter = new Exporter;
return sprintf(
'raise user-specified exception %s',
$exporter->export($this->exception)
);
}
}

View file

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Stubs a method by returning a user-defined value.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Stub_MatcherCollection
{
/**
* Adds a new matcher to the collection which can be used as an expectation
* or a stub.
*
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* Matcher for invocations to mock objects.
*/
public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher);
}

View file

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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 SebastianBergmann\Exporter\Exporter;
/**
* Stubs a method by returning a user-defined value.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Stub_Return implements PHPUnit_Framework_MockObject_Stub
{
protected $value;
public function __construct($value)
{
$this->value = $value;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
return $this->value;
}
public function toString()
{
$exporter = new Exporter;
return sprintf(
'return user-specified value %s',
$exporter->export($this->value)
);
}
}

View file

@ -0,0 +1,38 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Stubs a method by returning an argument that was passed to the mocked method.
*
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Stub_ReturnArgument extends PHPUnit_Framework_MockObject_Stub_Return
{
protected $argumentIndex;
public function __construct($argumentIndex)
{
$this->argumentIndex = $argumentIndex;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
if (isset($invocation->parameters[$this->argumentIndex])) {
return $invocation->parameters[$this->argumentIndex];
} else {
return;
}
}
public function toString()
{
return sprintf('return argument #%d', $this->argumentIndex);
}
}

View file

@ -0,0 +1,51 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Stub_ReturnCallback implements PHPUnit_Framework_MockObject_Stub
{
protected $callback;
public function __construct($callback)
{
$this->callback = $callback;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
return call_user_func_array($this->callback, $invocation->parameters);
}
public function toString()
{
if (is_array($this->callback)) {
if (is_object($this->callback[0])) {
$class = get_class($this->callback[0]);
$type = '->';
} else {
$class = $this->callback[0];
$type = '::';
}
return sprintf(
'return result of user defined callback %s%s%s() with the ' .
'passed arguments',
$class,
$type,
$this->callback[1]
);
} else {
return 'return result of user defined callback ' . $this->callback .
' with the passed arguments';
}
}
}

View file

@ -0,0 +1,34 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Stubs a method by returning the current object.
*
* @since Class available since Release 1.1.0
*/
class PHPUnit_Framework_MockObject_Stub_ReturnSelf implements PHPUnit_Framework_MockObject_Stub
{
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
if (!$invocation instanceof PHPUnit_Framework_MockObject_Invocation_Object) {
throw new PHPUnit_Framework_Exception(
'The current object can only be returned when mocking an ' .
'object, not a static class.'
);
}
return $invocation->object;
}
public function toString()
{
return 'return the current object';
}
}

View file

@ -0,0 +1,47 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Stubs a method by returning a value from a map.
*
* @since Class available since Release 1.1.0
*/
class PHPUnit_Framework_MockObject_Stub_ReturnValueMap implements PHPUnit_Framework_MockObject_Stub
{
protected $valueMap;
public function __construct(array $valueMap)
{
$this->valueMap = $valueMap;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
$parameterCount = count($invocation->parameters);
foreach ($this->valueMap as $map) {
if (!is_array($map) || $parameterCount != count($map) - 1) {
continue;
}
$return = array_pop($map);
if ($invocation->parameters === $map) {
return $return;
}
}
return;
}
public function toString()
{
return 'return value from a map';
}
}

View file

@ -0,0 +1,25 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* Interface for classes which must verify a given expectation.
*
* @since Interface available since Release 1.0.0
*/
interface PHPUnit_Framework_MockObject_Verifiable
{
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function verify();
}

View file

@ -0,0 +1,200 @@
<?php
class Framework_MockObject_GeneratorTest extends PHPUnit_Framework_TestCase
{
/**
* @var PHPUnit_Framework_MockObject_Generator
*/
protected $generator;
protected function setUp()
{
$this->generator = new PHPUnit_Framework_MockObject_Generator;
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMock
* @expectedException PHPUnit_Framework_Exception
*/
public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock()
{
$this->generator->getMock('StdClass', array(0));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMock
*/
public function testGetMockCanCreateNonExistingFunctions()
{
$mock = $this->generator->getMock('StdClass', array('testFunction'));
$this->assertTrue(method_exists($mock, 'testFunction'));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMock
* @expectedException PHPUnit_Framework_MockObject_RuntimeException
* @expectedExceptionMessage duplicates: "foo, foo"
*/
public function testGetMockGeneratorFails()
{
$mock = $this->generator->getMock('StdClass', array('foo', 'foo'));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
*/
public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces()
{
$mock = $this->generator->getMockForAbstractClass('Countable');
$this->assertTrue(method_exists($mock, 'count'));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
*/
public function testGetMockForAbstractClassStubbingAbstractClass()
{
$mock = $this->generator->getMockForAbstractClass('AbstractMockTestClass');
$this->assertTrue(method_exists($mock, 'doSomething'));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
*/
public function testGetMockForAbstractClassWithNonExistentMethods()
{
$mock = $this->generator->getMockForAbstractClass(
'AbstractMockTestClass',
array(),
'',
true,
true,
true,
array('nonexistentMethod')
);
$this->assertTrue(method_exists($mock, 'nonexistentMethod'));
$this->assertTrue(method_exists($mock, 'doSomething'));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
*/
public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMethodWhenNoMethodsWereInformed()
{
$mock = $this->generator->getMockForAbstractClass('AbstractMockTestClass');
$mock->expects($this->any())
->method('doSomething')
->willReturn('testing');
$this->assertEquals('testing', $mock->doSomething());
$this->assertEquals(1, $mock->returnAnything());
}
/**
* @dataProvider getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
* @expectedException PHPUnit_Framework_Exception
*/
public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName)
{
$mock = $this->generator->getMockForAbstractClass($className, array(), $mockClassName);
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass
* @expectedException PHPUnit_Framework_MockObject_RuntimeException
*/
public function testGetMockForAbstractClassAbstractClassDoesNotExist()
{
$mock = $this->generator->getMockForAbstractClass('Tux');
}
/**
* Dataprovider for test "testGetMockForAbstractClassExpectingInvalidArgumentException"
*/
public static function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider()
{
return array(
'className not a string' => array(array(), ''),
'mockClassName not a string' => array('Countable', new StdClass),
);
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForTrait
* @requires PHP 5.4.0
*/
public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods()
{
$mock = $this->generator->getMockForTrait(
'AbstractTrait',
array(),
'',
true,
true,
true,
array('nonexistentMethod')
);
$this->assertTrue(method_exists($mock, 'nonexistentMethod'));
$this->assertTrue(method_exists($mock, 'doSomething'));
$this->assertTrue($mock->mockableMethod());
$this->assertTrue($mock->anotherMockableMethod());
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMockForTrait
* @requires PHP 5.4.0
*/
public function testGetMockForTraitStubbingAbstractMethod()
{
$mock = $this->generator->getMockForTrait('AbstractTrait');
$this->assertTrue(method_exists($mock, 'doSomething'));
}
/**
* @requires PHP 5.4.0
*/
public function testGetMockForSingletonWithReflectionSuccess()
{
// Probably, this should be moved to tests/autoload.php
require_once __DIR__ . '/_fixture/SingletonClass.php';
$mock = $this->generator->getMock('SingletonClass', array('doSomething'), array(), '', false);
$this->assertInstanceOf('SingletonClass', $mock);
}
/**
* Same as "testGetMockForSingletonWithReflectionSuccess", but we expect
* warning for PHP < 5.4.0 since PHPUnit will try to execute private __wakeup
* on unserialize
*/
public function testGetMockForSingletonWithUnserializeFail()
{
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
$this->markTestSkipped('Only for PHP < 5.4.0');
}
$this->setExpectedException('PHPUnit_Framework_MockObject_RuntimeException');
// Probably, this should be moved to tests/autoload.php
require_once __DIR__ . '/_fixture/SingletonClass.php';
$mock = $this->generator->getMock('SingletonClass', array('doSomething'), array(), '', false);
}
/**
* ReflectionClass::getMethods for SoapClient on PHP 5.3 produces PHP Fatal Error
* @runInSeparateProcess
*/
public function testGetMockForSoapClientReflectionMethodsDuplication()
{
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
$this->markTestSkipped('Only for PHP < 5.4.0');
}
$mock = $this->generator->getMock('SoapClient', array(), array(), '', false);
$this->assertInstanceOf('SoapClient', $mock);
}
}

View file

@ -0,0 +1,107 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* @since File available since Release 1.0.0
*/
class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase
{
public function testMockBuilderRequiresClassName()
{
$spec = $this->getMockBuilder('Mockable');
$mock = $spec->getMock();
$this->assertTrue($mock instanceof Mockable);
}
public function testByDefaultMocksAllMethods()
{
$spec = $this->getMockBuilder('Mockable');
$mock = $spec->getMock();
$this->assertNull($mock->mockableMethod());
$this->assertNull($mock->anotherMockableMethod());
}
public function testMethodsToMockCanBeSpecified()
{
$spec = $this->getMockBuilder('Mockable');
$spec->setMethods(array('mockableMethod'));
$mock = $spec->getMock();
$this->assertNull($mock->mockableMethod());
$this->assertTrue($mock->anotherMockableMethod());
}
public function testByDefaultDoesNotPassArgumentsToTheConstructor()
{
$spec = $this->getMockBuilder('Mockable');
$mock = $spec->getMock();
$this->assertEquals(array(null, null), $mock->constructorArgs);
}
public function testMockClassNameCanBeSpecified()
{
$spec = $this->getMockBuilder('Mockable');
$spec->setMockClassName('ACustomClassName');
$mock = $spec->getMock();
$this->assertTrue($mock instanceof ACustomClassName);
}
public function testConstructorArgumentsCanBeSpecified()
{
$spec = $this->getMockBuilder('Mockable');
$spec->setConstructorArgs($expected = array(23, 42));
$mock = $spec->getMock();
$this->assertEquals($expected, $mock->constructorArgs);
}
public function testOriginalConstructorCanBeDisabled()
{
$spec = $this->getMockBuilder('Mockable');
$spec->disableOriginalConstructor();
$mock = $spec->getMock();
$this->assertNull($mock->constructorArgs);
}
public function testByDefaultOriginalCloneIsPreserved()
{
$spec = $this->getMockBuilder('Mockable');
$mock = $spec->getMock();
$cloned = clone $mock;
$this->assertTrue($cloned->cloned);
}
public function testOriginalCloneCanBeDisabled()
{
$spec = $this->getMockBuilder('Mockable');
$spec->disableOriginalClone();
$mock = $spec->getMock();
$mock->cloned = false;
$cloned = clone $mock;
$this->assertFalse($cloned->cloned);
}
public function testCallingAutoloadCanBeDisabled()
{
// it is not clear to me how to test this nor the difference
// between calling it or not
$this->markTestIncomplete();
}
public function testProvidesAFluentInterface()
{
$spec = $this->getMockBuilder('Mockable')
->setMethods(array('mockableMethod'))
->setConstructorArgs(array())
->setMockClassName('DummyClassName')
->disableOriginalConstructor()
->disableOriginalClone()
->disableAutoload();
$this->assertTrue($spec instanceof PHPUnit_Framework_MockObject_MockBuilder);
}
}

View file

@ -0,0 +1,129 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.4.0', '<')) print 'skip: PHP >= 5.4.0 required';
?>
--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',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function speak()
{
$arguments = array();
$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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,85 @@
<?php
class Framework_MockObject_Invocation_ObjectTest extends PHPUnit_Framework_TestCase
{
public function testConstructorRequiresClassAndMethodAndParametersAndObject()
{
new PHPUnit_Framework_MockObject_Invocation_Object(
'FooClass',
'FooMethod',
array('an_argument'),
new StdClass
);
}
public function testAllowToGetClassNameSetInConstructor()
{
$invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
'FooClass',
'FooMethod',
array('an_argument'),
new StdClass
);
$this->assertSame('FooClass', $invocation->className);
}
public function testAllowToGetMethodNameSetInConstructor()
{
$invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
'FooClass',
'FooMethod',
array('an_argument'),
new StdClass
);
$this->assertSame('FooMethod', $invocation->methodName);
}
public function testAllowToGetObjectSetInConstructor()
{
$expectedObject = new StdClass;
$invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
'FooClass',
'FooMethod',
array('an_argument'),
$expectedObject
);
$this->assertSame($expectedObject, $invocation->object);
}
public function testAllowToGetMethodParametersSetInConstructor()
{
$expectedParameters = array(
'foo', 5, array('a', 'b'), new StdClass, null, false
);
$invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
'FooClass',
'FooMethod',
$expectedParameters,
new StdClass
);
$this->assertSame($expectedParameters, $invocation->parameters);
}
public function testConstructorAllowToSetFlagCloneObjectsInParameters()
{
$parameters = array(new StdClass);
$cloneObjects = true;
$invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
'FooClass',
'FooMethod',
$parameters,
new StdClass,
$cloneObjects
);
$this->assertEquals($parameters, $invocation->parameters);
$this->assertNotSame($parameters, $invocation->parameters);
}
}

View file

@ -0,0 +1,54 @@
<?php
class Framework_MockObject_Invocation_StaticTest extends PHPUnit_Framework_TestCase
{
public function testConstructorRequiresClassAndMethodAndParameters()
{
new PHPUnit_Framework_MockObject_Invocation_Static('FooClass', 'FooMethod', array('an_argument'));
}
public function testAllowToGetClassNameSetInConstructor()
{
$invocation = new PHPUnit_Framework_MockObject_Invocation_Static('FooClass', 'FooMethod', array('an_argument'));
$this->assertSame('FooClass', $invocation->className);
}
public function testAllowToGetMethodNameSetInConstructor()
{
$invocation = new PHPUnit_Framework_MockObject_Invocation_Static('FooClass', 'FooMethod', array('an_argument'));
$this->assertSame('FooMethod', $invocation->methodName);
}
public function testAllowToGetMethodParametersSetInConstructor()
{
$expectedParameters = array(
'foo', 5, array('a', 'b'), new StdClass, null, false
);
$invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
'FooClass',
'FooMethod',
$expectedParameters
);
$this->assertSame($expectedParameters, $invocation->parameters);
}
public function testConstructorAllowToSetFlagCloneObjectsInParameters()
{
$parameters = array(new StdClass);
$cloneObjects = true;
$invocation = new PHPUnit_Framework_MockObject_Invocation_Static(
'FooClass',
'FooMethod',
$parameters,
$cloneObjects
);
$this->assertEquals($parameters, $invocation->parameters);
$this->assertNotSame($parameters, $invocation->parameters);
}
}

View file

@ -0,0 +1,45 @@
<?php
class Framework_MockObject_Matcher_ConsecutiveParametersTest extends PHPUnit_Framework_TestCase
{
public function testIntegration()
{
$mock = $this->getMock('stdClass', array('foo'));
$mock
->expects($this->any())
->method('foo')
->withConsecutive(
array('bar'),
array(21, 42)
);
$mock->foo('bar');
$mock->foo(21, 42);
}
public function testIntegrationWithLessAssertionsThenMethodCalls()
{
$mock = $this->getMock('stdClass', array('foo'));
$mock
->expects($this->any())
->method('foo')
->withConsecutive(
array('bar')
);
$mock->foo('bar');
$mock->foo(21, 42);
}
public function testIntegrationExpectingException()
{
$mock = $this->getMock('stdClass', array('foo'));
$mock
->expects($this->any())
->method('foo')
->withConsecutive(
array('bar'),
array(21, 42)
);
$mock->foo('bar');
$this->setExpectedException('PHPUnit_Framework_ExpectationFailedException');
$mock->foo('invalid');
}
}

View file

@ -0,0 +1,143 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function one()
{
$arguments = array();
$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_Object(
'Foo', 'one', $arguments, $this, TRUE
)
);
return $result;
}
public function two()
{
$arguments = array();
$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_Object(
'Foo', 'two', $arguments, $this, TRUE
)
);
return $result;
}
protected function three()
{
$arguments = array();
$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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,121 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = array($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_Object(
'Foo', 'bar', $arguments, $this, TRUE
)
);
return $result;
}
public function baz(Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,73 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE)
--FILE--
<?php
class Foo
{
public function __clone()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'Foo',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,72 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE)
--FILE--
<?php
class Foo
{
public function __construct()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'Foo',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,72 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', FALSE)
--FILE--
<?php
class Foo
{
public function __clone()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'Foo',
array(),
'MockFoo',
FALSE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,72 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE)
--FILE--
<?php
class Foo
{
public function __construct()
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'Foo',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,77 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,77 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,99 @@
--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'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,88 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function method()
{
$arguments = array();
$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_Object(
'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_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,99 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('ClassWithMethodWithVariadicArguments', array(), 'MockFoo', TRUE, TRUE)
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.6.0', '<')) print 'skip: PHP >= 5.6.0 required';
?>
--FILE--
<?php
class ClassWithMethodWithVariadicArguments
{
public function methodWithVariadicArguments($a, ...$parameters)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'ClassWithMethodWithVariadicArguments',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends ClassWithMethodWithVariadicArguments implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function methodWithVariadicArguments($a, ...$parameters)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,93 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo implements PHPUnit_Framework_MockObject_MockObject, Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,122 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), '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',
array(),
'MockFoo',
TRUE,
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = array($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_Object(
'Foo', 'bar', $arguments, $this, TRUE
)
);
return $result;
}
public function baz(Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,123 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(NS\Foo $foo)
{
$arguments = array($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_Object(
'NS\Foo', 'bar', $arguments, $this, TRUE
)
);
return $result;
}
public function baz(NS\Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,75 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,74 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,74 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
FALSE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,74 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,79 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,79 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,101 @@
--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'];
?>
--EXPECTF--
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(NS\Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,95 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), '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',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo implements PHPUnit_Framework_MockObject_MockObject, NS\Foo
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(NS\Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,70 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('NonExistentClass', array(), 'MockFoo', TRUE, TRUE)
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'NonExistentClass',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class NonExistentClass
{
}
class MockFoo extends NonExistentClass implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,78 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'NS\Foo',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
namespace NS {
class Foo
{
}
}
namespace {
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}
}

View file

@ -0,0 +1,78 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
--FILE--
<?php
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'\NS\Foo',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
namespace NS {
class Foo
{
}
}
namespace {
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}
}

View file

@ -0,0 +1,117 @@
--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', array(), 'ProxyFoo', TRUE, TRUE, TRUE, TRUE
);
print $mock['code'];
?>
--EXPECTF--
class ProxyFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(Foo $foo)
{
$arguments = array($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_Object(
'Foo', 'bar', $arguments, $this, TRUE
)
);
return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $arguments);
}
public function baz(Foo $foo)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -0,0 +1,99 @@
--TEST--
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
--SKIPIF--
<?php
if (!method_exists('ReflectionParameter', 'hasType')) print 'skip: PHP >= 7.0.0 required';
?>
--FILE--
<?php
class Foo
{
public function bar(string $baz)
{
}
}
require __DIR__ . '/../../vendor/autoload.php';
$generator = new PHPUnit_Framework_MockObject_Generator;
$mock = $generator->generate(
'Foo',
array(),
'MockFoo',
TRUE,
TRUE
);
print $mock['code'];
?>
--EXPECTF--
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public function bar(string $baz)
{
$arguments = array($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_Object(
'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(array($expects, 'method'), func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === NULL) {
$this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify()
{
$this->__phpunit_getInvocationMocker()->verify();
$this->__phpunit_invocationMocker = NULL;
}
}

View file

@ -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(
dirname(dirname(__FILE__)) . '/_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)
{
}
}

View file

@ -0,0 +1,39 @@
--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(
dirname(dirname(__FILE__)) . '/_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)
{
}
}

View file

@ -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(
dirname(dirname(__FILE__)) . '/_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)
{
}
}

View file

@ -0,0 +1,842 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
*
*
* @since Class available since Release 3.0.0
*/
class Framework_MockObjectTest extends PHPUnit_Framework_TestCase
{
public function testMockedMethodIsNeverCalled()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->never())
->method('doSomething');
}
public function testMockedMethodIsNeverCalledWithParameter()
{
$mock = $this->getMock('SomeClass');
$mock->expects($this->never())
->method('doSomething')
->with('someArg');
}
public function testMockedMethodIsNotCalledWhenExpectsAnyWithParameter()
{
$mock = $this->getMock('SomeClass');
$mock->expects($this->any())
->method('doSomethingElse')
->with('someArg');
}
public function testMockedMethodIsNotCalledWhenMethodSpecifiedDirectlyWithParameter()
{
$mock = $this->getMock('SomeClass');
$mock->method('doSomethingElse')
->with('someArg');
}
public function testMockedMethodIsCalledAtLeastOnce()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->atLeastOnce())
->method('doSomething');
$mock->doSomething();
}
public function testMockedMethodIsCalledAtLeastOnce2()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->atLeastOnce())
->method('doSomething');
$mock->doSomething();
$mock->doSomething();
}
public function testMockedMethodIsCalledAtLeastTwice()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->atLeast(2))
->method('doSomething');
$mock->doSomething();
$mock->doSomething();
}
public function testMockedMethodIsCalledAtLeastTwice2()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->atLeast(2))
->method('doSomething');
$mock->doSomething();
$mock->doSomething();
$mock->doSomething();
}
public function testMockedMethodIsCalledAtMostTwice()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->atMost(2))
->method('doSomething');
$mock->doSomething();
$mock->doSomething();
}
public function testMockedMethodIsCalledAtMosttTwice2()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->atMost(2))
->method('doSomething');
$mock->doSomething();
}
public function testMockedMethodIsCalledOnce()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->once())
->method('doSomething');
$mock->doSomething();
}
public function testMockedMethodIsCalledOnceWithParameter()
{
$mock = $this->getMock('SomeClass');
$mock->expects($this->once())
->method('doSomethingElse')
->with($this->equalTo('something'));
$mock->doSomethingElse('something');
}
public function testMockedMethodIsCalledExactly()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->exactly(2))
->method('doSomething');
$mock->doSomething();
$mock->doSomething();
}
public function testStubbedException()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->will($this->throwException(new Exception));
try {
$mock->doSomething();
} catch (Exception $e) {
return;
}
$this->fail();
}
public function testStubbedWillThrowException()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->willThrowException(new Exception);
try {
$mock->doSomething();
} catch (Exception $e) {
return;
}
$this->fail();
}
public function testStubbedReturnValue()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->will($this->returnValue('something'));
$this->assertEquals('something', $mock->doSomething());
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->willReturn('something');
$this->assertEquals('something', $mock->doSomething());
}
public function testStubbedReturnValueMap()
{
$map = array(
array('a', 'b', 'c', 'd'),
array('e', 'f', 'g', 'h')
);
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->will($this->returnValueMap($map));
$this->assertEquals('d', $mock->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $mock->doSomething('e', 'f', 'g'));
$this->assertEquals(null, $mock->doSomething('foo', 'bar'));
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->willReturnMap($map);
$this->assertEquals('d', $mock->doSomething('a', 'b', 'c'));
$this->assertEquals('h', $mock->doSomething('e', 'f', 'g'));
$this->assertEquals(null, $mock->doSomething('foo', 'bar'));
}
public function testStubbedReturnArgument()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->will($this->returnArgument(1));
$this->assertEquals('b', $mock->doSomething('a', 'b'));
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->willReturnArgument(1);
$this->assertEquals('b', $mock->doSomething('a', 'b'));
}
public function testFunctionCallback()
{
$mock = $this->getMock('SomeClass', array('doSomething'), array(), '', false);
$mock->expects($this->once())
->method('doSomething')
->will($this->returnCallback('functionCallback'));
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
$mock = $this->getMock('SomeClass', array('doSomething'), array(), '', false);
$mock->expects($this->once())
->method('doSomething')
->willReturnCallback('functionCallback');
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
}
public function testStubbedReturnSelf()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->will($this->returnSelf());
$this->assertEquals($mock, $mock->doSomething());
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->willReturnSelf();
$this->assertEquals($mock, $mock->doSomething());
}
public function testStubbedReturnOnConsecutiveCalls()
{
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->will($this->onConsecutiveCalls('a', 'b', 'c'));
$this->assertEquals('a', $mock->doSomething());
$this->assertEquals('b', $mock->doSomething());
$this->assertEquals('c', $mock->doSomething());
$mock = $this->getMock('AnInterface');
$mock->expects($this->any())
->method('doSomething')
->willReturnOnConsecutiveCalls('a', 'b', 'c');
$this->assertEquals('a', $mock->doSomething());
$this->assertEquals('b', $mock->doSomething());
$this->assertEquals('c', $mock->doSomething());
}
public function testStaticMethodCallback()
{
$mock = $this->getMock('SomeClass', array('doSomething'), array(), '', false);
$mock->expects($this->once())
->method('doSomething')
->will($this->returnCallback(array('MethodCallback', 'staticCallback')));
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
}
public function testPublicMethodCallback()
{
$mock = $this->getMock('SomeClass', array('doSomething'), array(), '', false);
$mock->expects($this->once())
->method('doSomething')
->will($this->returnCallback(array(new MethodCallback, 'nonStaticCallback')));
$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));
}
public function testMockClassOnlyGeneratedOnce()
{
$mock1 = $this->getMock('AnInterface');
$mock2 = $this->getMock('AnInterface');
$this->assertEquals(get_class($mock1), get_class($mock2));
}
public function testMockClassDifferentForPartialMocks()
{
$mock1 = $this->getMock('PartialMockTestClass');
$mock2 = $this->getMock('PartialMockTestClass', array('doSomething'));
$mock3 = $this->getMock('PartialMockTestClass', array('doSomething'));
$mock4 = $this->getMock('PartialMockTestClass', array('doAnotherThing'));
$mock5 = $this->getMock('PartialMockTestClass', array('doAnotherThing'));
$this->assertNotEquals(get_class($mock1), get_class($mock2));
$this->assertNotEquals(get_class($mock1), get_class($mock3));
$this->assertNotEquals(get_class($mock1), get_class($mock4));
$this->assertNotEquals(get_class($mock1), get_class($mock5));
$this->assertEquals(get_class($mock2), get_class($mock3));
$this->assertNotEquals(get_class($mock2), get_class($mock4));
$this->assertNotEquals(get_class($mock2), get_class($mock5));
$this->assertEquals(get_class($mock4), get_class($mock5));
}
public function testMockClassStoreOverrulable()
{
$mock1 = $this->getMock('PartialMockTestClass');
$mock2 = $this->getMock('PartialMockTestClass', array(), array(), 'MyMockClassNameForPartialMockTestClass1');
$mock3 = $this->getMock('PartialMockTestClass');
$mock4 = $this->getMock('PartialMockTestClass', array('doSomething'), array(), 'AnotherMockClassNameForPartialMockTestClass');
$mock5 = $this->getMock('PartialMockTestClass', array(), array(), 'MyMockClassNameForPartialMockTestClass2');
$this->assertNotEquals(get_class($mock1), get_class($mock2));
$this->assertEquals(get_class($mock1), get_class($mock3));
$this->assertNotEquals(get_class($mock1), get_class($mock4));
$this->assertNotEquals(get_class($mock2), get_class($mock3));
$this->assertNotEquals(get_class($mock2), get_class($mock4));
$this->assertNotEquals(get_class($mock2), get_class($mock5));
$this->assertNotEquals(get_class($mock3), get_class($mock4));
$this->assertNotEquals(get_class($mock3), get_class($mock5));
$this->assertNotEquals(get_class($mock4), get_class($mock5));
}
/**
* @covers PHPUnit_Framework_MockObject_Generator::getMock
*/
public function testGetMockWithFixedClassNameCanProduceTheSameMockTwice()
{
$mock = $this->getMockBuilder('StdClass')->setMockClassName('FixedName')->getMock();
$mock = $this->getMockBuilder('StdClass')->setMockClassName('FixedName')->getMock();
$this->assertInstanceOf('StdClass', $mock);
}
public function testOriginalConstructorSettingConsidered()
{
$mock1 = $this->getMock('PartialMockTestClass');
$mock2 = $this->getMock('PartialMockTestClass', array(), array(), '', false);
$this->assertTrue($mock1->constructorCalled);
$this->assertFalse($mock2->constructorCalled);
}
public function testOriginalCloneSettingConsidered()
{
$mock1 = $this->getMock('PartialMockTestClass');
$mock2 = $this->getMock('PartialMockTestClass', array(), array(), '', true, false);
$this->assertNotEquals(get_class($mock1), get_class($mock2));
}
public function testGetMockForAbstractClass()
{
$mock = $this->getMock('AbstractMockTestClass');
$mock->expects($this->never())
->method('doSomething');
}
public function traversableProvider()
{
return array(
array('Traversable'),
array('\Traversable'),
array('TraversableMockTestInterface'),
array(array('Traversable')),
array(array('Iterator','Traversable')),
array(array('\Iterator','\Traversable'))
);
}
/**
* @dataProvider traversableProvider
*/
public function testGetMockForTraversable($type)
{
$mock = $this->getMock($type);
$this->assertInstanceOf('Traversable', $mock);
}
public function testMultipleInterfacesCanBeMockedInSingleObject()
{
$mock = $this->getMock(array('AnInterface', 'AnotherInterface'));
$this->assertInstanceOf('AnInterface', $mock);
$this->assertInstanceOf('AnotherInterface', $mock);
}
/**
* @requires PHP 5.4.0
*/
public function testGetMockForTrait()
{
$mock = $this->getMockForTrait('AbstractTrait');
$mock->expects($this->never())->method('doSomething');
$parent = get_parent_class($mock);
$traits = class_uses($parent, false);
$this->assertContains('AbstractTrait', $traits);
}
public function testClonedMockObjectShouldStillEqualTheOriginal()
{
$a = $this->getMock('stdClass');
$b = clone $a;
$this->assertEquals($a, $b);
}
public function testMockObjectsConstructedIndepentantlyShouldBeEqual()
{
$a = $this->getMock('stdClass');
$b = $this->getMock('stdClass');
$this->assertEquals($a, $b);
}
public function testMockObjectsConstructedIndepentantlyShouldNotBeTheSame()
{
$a = $this->getMock('stdClass');
$b = $this->getMock('stdClass');
$this->assertNotSame($a, $b);
}
public function testClonedMockObjectCanBeUsedInPlaceOfOriginalOne()
{
$x = $this->getMock('stdClass');
$y = clone $x;
$mock = $this->getMock('stdClass', array('foo'));
$mock->expects($this->once())->method('foo')->with($this->equalTo($x));
$mock->foo($y);
}
public function testClonedMockObjectIsNotIdenticalToOriginalOne()
{
$x = $this->getMock('stdClass');
$y = clone $x;
$mock = $this->getMock('stdClass', array('foo'));
$mock->expects($this->once())->method('foo')->with($this->logicalNot($this->identicalTo($x)));
$mock->foo($y);
}
public function testObjectMethodCallWithArgumentCloningEnabled()
{
$expectedObject = new StdClass;
$mock = $this->getMockBuilder('SomeClass')
->setMethods(array('doSomethingElse'))
->enableArgumentCloning()
->getMock();
$actualArguments = array();
$mock->expects($this->any())
->method('doSomethingElse')
->will($this->returnCallback(function () use (&$actualArguments) {
$actualArguments = func_get_args();
}));
$mock->doSomethingElse($expectedObject);
$this->assertEquals(1, count($actualArguments));
$this->assertEquals($expectedObject, $actualArguments[0]);
$this->assertNotSame($expectedObject, $actualArguments[0]);
}
public function testObjectMethodCallWithArgumentCloningDisabled()
{
$expectedObject = new StdClass;
$mock = $this->getMockBuilder('SomeClass')
->setMethods(array('doSomethingElse'))
->disableArgumentCloning()
->getMock();
$actualArguments = array();
$mock->expects($this->any())
->method('doSomethingElse')
->will($this->returnCallback(function () use (&$actualArguments) {
$actualArguments = func_get_args();
}));
$mock->doSomethingElse($expectedObject);
$this->assertEquals(1, count($actualArguments));
$this->assertSame($expectedObject, $actualArguments[0]);
}
public function testArgumentCloningOptionGeneratesUniqueMock()
{
$mockWithCloning = $this->getMockBuilder('SomeClass')
->setMethods(array('doSomethingElse'))
->enableArgumentCloning()
->getMock();
$mockWithoutCloning = $this->getMockBuilder('SomeClass')
->setMethods(array('doSomethingElse'))
->disableArgumentCloning()
->getMock();
$this->assertNotEquals($mockWithCloning, $mockWithoutCloning);
}
public function testVerificationOfMethodNameFailsWithoutParameters()
{
$mock = $this->getMock('SomeClass', array('right', 'wrong'), array(), '', true, true, true);
$mock->expects($this->once())
->method('right');
$mock->wrong();
try {
$mock->__phpunit_verify();
$this->fail('Expected exception');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n"
. "Method was expected to be called 1 times, actually called 0 times.\n",
$e->getMessage()
);
}
$this->resetMockObjects();
}
public function testVerificationOfMethodNameFailsWithParameters()
{
$mock = $this->getMock('SomeClass', array('right', 'wrong'), array(), '', true, true, true);
$mock->expects($this->once())
->method('right');
$mock->wrong();
try {
$mock->__phpunit_verify();
$this->fail('Expected exception');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n"
. "Method was expected to be called 1 times, actually called 0 times.\n",
$e->getMessage()
);
}
$this->resetMockObjects();
}
public function testVerificationOfMethodNameFailsWithWrongParameters()
{
$mock = $this->getMock('SomeClass', array('right', 'wrong'), array(), '', true, true, true);
$mock->expects($this->once())
->method('right')
->with(array('first', 'second'));
try {
$mock->right(array('second'));
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n"
. "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n"
. "Failed asserting that two arrays are equal.",
$e->getMessage()
);
}
try {
$mock->__phpunit_verify();
$this->fail('Expected exception');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n"
. "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n"
. "Failed asserting that two arrays are equal.\n"
. "--- Expected\n"
. "+++ Actual\n"
. "@@ @@\n"
. " Array (\n"
. "- 0 => 'first'\n"
. "- 1 => 'second'\n"
. "+ 0 => 'second'\n"
. " )\n",
$e->getMessage()
);
}
$this->resetMockObjects();
}
public function testVerificationOfNeverFailsWithEmptyParameters()
{
$mock = $this->getMock('SomeClass', array('right', 'wrong'), array(), '', true, true, true);
$mock->expects($this->never())
->method('right')
->with();
try {
$mock->right();
$this->fail('Expected exception');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
'SomeClass::right() was not expected to be called.',
$e->getMessage()
);
}
$this->resetMockObjects();
}
public function testVerificationOfNeverFailsWithAnyParameters()
{
$mock = $this->getMock('SomeClass', array('right', 'wrong'), array(), '', true, true, true);
$mock->expects($this->never())
->method('right')
->withAnyParameters();
try {
$mock->right();
$this->fail('Expected exception');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
'SomeClass::right() was not expected to be called.',
$e->getMessage()
);
}
$this->resetMockObjects();
}
/**
* @ticket 199
*/
public function testWithAnythingInsteadOfWithAnyParameters()
{
$mock = $this->getMock('SomeClass', array('right'), array(), '', true, true, true);
$mock->expects($this->once())
->method('right')
->with($this->anything());
try {
$mock->right();
$this->fail('Expected exception');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->assertSame(
"Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n" .
"Parameter count for invocation SomeClass::right() is too low.\n" .
"To allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.",
$e->getMessage()
);
}
$this->resetMockObjects();
}
/**
* See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81
*/
public function testMockArgumentsPassedByReference()
{
$foo = $this->getMockBuilder('MethodCallbackByReference')
->setMethods(array('bar'))
->disableOriginalConstructor()
->disableArgumentCloning()
->getMock();
$foo->expects($this->any())
->method('bar')
->will($this->returnCallback(array($foo, 'callback')));
$a = $b = $c = 0;
$foo->bar($a, $b, $c);
$this->assertEquals(1, $b);
}
/**
* See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81
*/
public function testMockArgumentsPassedByReference2()
{
$foo = $this->getMockBuilder('MethodCallbackByReference')
->disableOriginalConstructor()
->disableArgumentCloning()
->getMock();
$foo->expects($this->any())
->method('bar')
->will($this->returnCallback(
function (&$a, &$b, $c) {
$b = 1;
}
));
$a = $b = $c = 0;
$foo->bar($a, $b, $c);
$this->assertEquals(1, $b);
}
/**
* https://github.com/sebastianbergmann/phpunit-mock-objects/issues/116
*/
public function testMockArgumentsPassedByReference3()
{
$foo = $this->getMockBuilder('MethodCallbackByReference')
->setMethods(array('bar'))
->disableOriginalConstructor()
->disableArgumentCloning()
->getMock();
$a = new stdClass();
$b = $c = 0;
$foo->expects($this->any())
->method('bar')
->with($a, $b, $c)
->will($this->returnCallback(array($foo, 'callback')));
$foo->bar($a, $b, $c);
}
/**
* https://github.com/sebastianbergmann/phpunit/issues/796
*/
public function testMockArgumentsPassedByReference4()
{
$foo = $this->getMockBuilder('MethodCallbackByReference')
->setMethods(array('bar'))
->disableOriginalConstructor()
->disableArgumentCloning()
->getMock();
$a = new stdClass();
$b = $c = 0;
$foo->expects($this->any())
->method('bar')
->with($this->isInstanceOf("stdClass"), $b, $c)
->will($this->returnCallback(array($foo, 'callback')));
$foo->bar($a, $b, $c);
}
/**
* @requires extension soap
*/
public function testCreateMockFromWsdl()
{
$mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'WsdlMock');
$this->assertStringStartsWith(
'Mock_WsdlMock_',
get_class($mock)
);
}
/**
* @requires extension soap
*/
public function testCreateNamespacedMockFromWsdl()
{
$mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'My\\Space\\WsdlMock');
$this->assertStringStartsWith(
'Mock_WsdlMock_',
get_class($mock)
);
}
/**
* @requires extension soap
*/
public function testCreateTwoMocksOfOneWsdlFile()
{
$mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl');
$mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl');
}
/**
* @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/156
* @ticket 156
*/
public function testInterfaceWithStaticMethodCanBeStubbed()
{
$this->assertInstanceOf(
'InterfaceWithStaticMethod',
$this->getMock('InterfaceWithStaticMethod')
);
}
/**
* @expectedException PHPUnit_Framework_MockObject_BadMethodCallException
*/
public function testInvokingStubbedStaticMethodRaisesException()
{
$mock = $this->getMock('ClassWithStaticMethod');
$mock->staticMethod();
}
/**
* @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/171
* @ticket 171
*/
public function testStubForClassThatImplementsSerializableCanBeCreatedWithoutInvokingTheConstructor()
{
$this->assertInstanceOf(
'ClassThatImplementsSerializable',
$this->getMockBuilder('ClassThatImplementsSerializable')
->disableOriginalConstructor()
->getMock()
);
}
private function resetMockObjects()
{
$refl = new ReflectionObject($this);
$refl = $refl->getParentClass();
$prop = $refl->getProperty('mockObjects');
$prop->setAccessible(true);
$prop->setValue($this, array());
}
}

View file

@ -0,0 +1,40 @@
<?php
/*
* This file is part of the PHPUnit_MockObject 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.
*/
/**
* @since Class available since Release 2.0.0
*/
class Framework_ProxyObjectTest extends PHPUnit_Framework_TestCase
{
public function testMockedMethodIsProxiedToOriginalMethod()
{
$proxy = $this->getMockBuilder('Bar')
->enableProxyingToOriginalMethods()
->getMock();
$proxy->expects($this->once())
->method('doSomethingElse');
$foo = new Foo;
$this->assertEquals('result', $foo->doSomething($proxy));
}
public function testMockedMethodWithReferenceIsProxiedToOriginalMethod()
{
$proxy = $this->getMockBuilder('MethodCallbackByReference')
->enableProxyingToOriginalMethods()
->getMock();
$a = $b = $c = 0;
$proxy->callback($a, $b, $c);
$this->assertEquals(1, $b);
}
}

Some files were not shown because too many files have changed in this diff Show more