commitall

This commit is contained in:
Sampanna Rimal
2024-07-10 18:28:19 +05:45
parent 140abda4e6
commit 9cd05ef3cb
15723 changed files with 4818733 additions and 0 deletions

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.
*/
/**
* 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 identification of expectation.
*/
public function id($id);
}

View File

@ -0,0 +1,291 @@
<?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;
/**
* @var string[]
*/
private $configurableMethods = [];
/**
* @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher
* @param array $configurableMethods
*/
public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher, array $configurableMethods)
{
$this->collection = $collection;
$this->matcher = new PHPUnit_Framework_MockObject_Matcher(
$invocationMatcher
);
$this->collection->addMatcher($this->matcher);
$this->configurableMethods = $configurableMethods;
}
/**
* @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
* @param mixed $nextValues, ...
*
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturn($value, ...$nextValues)
{
$stub = count($nextValues) === 0 ?
new PHPUnit_Framework_MockObject_Stub_Return($value) :
new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls(
array_merge([$value], $nextValues)
);
return $this->will($stub);
}
/**
* @param mixed $reference
*
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnReference(&$reference)
{
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnReference($reference);
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 $values, ...
*
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function willReturnOnConsecutiveCalls(...$values)
{
$stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($values);
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_MockObject_RuntimeException
*/
private function canDefineParameters()
{
if ($this->matcher->methodNameMatcher === null) {
throw new PHPUnit_Framework_MockObject_RuntimeException(
'Method name matcher is not defined, cannot define parameter ' .
'matcher without one'
);
}
if ($this->matcher->parametersMatcher !== null) {
throw new PHPUnit_Framework_MockObject_RuntimeException(
'Parameter matcher is already defined, cannot redefine'
);
}
}
/**
* @param array ...$arguments
*
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function with(...$arguments)
{
$this->canDefineParameters();
$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($arguments);
return $this;
}
/**
* @param array ...$arguments
*
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function withConsecutive(...$arguments)
{
$this->canDefineParameters();
$this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($arguments);
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_MockObject_RuntimeException(
'Method name matcher is already defined, cannot redefine'
);
}
if (is_string($constraint) && !in_array(strtolower($constraint), $this->configurableMethods)) {
throw new PHPUnit_Framework_MockObject_RuntimeException(
sprintf(
'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static',
$constraint
)
);
}
$this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint);
return $this;
}
}

View File

@ -0,0 +1,27 @@
<?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,27 @@
<?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,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.
*/
/**
* 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 identification 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(...$arguments);
/**
* Sets a matcher which allows any kind of parameters.
*
* Some examples:
* <code>
* // match any number of parameters
* $b->withAnyParameters();
* </code>
*
* @return PHPUnit_Framework_MockObject_Matcher_AnyParameters
*/
public function withAnyParameters();
}

View File

@ -0,0 +1,27 @@
<?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
*
* @return PHPUnit_Framework_MockObject_Builder_Identity
*/
public function will(PHPUnit_Framework_MockObject_Stub $stub);
}