PHP 클래스 SimpleMock, simpletest

@package SimpleTest
파일 보기 프로젝트 열기: simpletest/simpletest 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( ) Creates an empty action list and expectation list.
atTestEnd ( string $test_method, SimpleTestCase &$test ) Receives event from unit test that the current test method has finished.
disableExpectationNameChecks ( ) Disables a name check when setting expectations.
errorAt ( integer $timing, string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR ) Sets up a trigger to throw an error upon a specific method call.
errorOn ( string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR ) Sets up a trigger to throw an error upon the method call.
expect ( string $method, array $args, string $message = '%s' ) Sets up an expected call with a set of expected parameters in that call.
expectAt ( integer $timing, string $method, array $args, string $message = '%s' ) Sets up an expected call with a set of expected parameters in that call.
expectAtLeastOnce ( string $method, array $args = false, string $message = '%s' ) Convenience method for requiring a method call.
expectCallCount ( string $method, integer $count, string $message = '%s' ) Sets an expectation for the number of times a method will be called.
expectMaximumCallCount ( string $method, integer $count, string $message = '%s' ) Sets the number of times a method may be called before a test failure is triggered.
expectMinimumCallCount ( string $method, integer $count, string $message = '%s' ) Sets the number of times to call a method to prevent a failure on the tally.
expectNever ( string $method, string $message = '%s' ) Convenience method for barring a method call.
expectOnce ( string $method, array $args = false, string $message = '%s' ) Convenience method for a single method call.
getCallCount ( string $method ) : integer Fetches the call count of a method so far.
invoke ( string $method, array $args ) : mixed Returns the expected value for the method name and checks expectations.
replaceWildcards ( array $args ) : array Replaces wildcard matches with wildcard expectations in the argument list.
returns ( string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed on by all calls to this method that match.
returnsAt ( integer $timing, string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed only when the required call count is reached.
returnsByReference ( string $method, mixed &$reference, array $args = false ) Sets a return for a parameter list that will be passed by reference for all calls.
returnsByReferenceAt ( integer $timing, string $method, mixed &$reference, array $args = false ) Sets a return for a parameter list that will be passed by value only when the required call count is reached.
returnsByValue ( string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed by value for all calls to this method.
returnsByValueAt ( integer $timing, string $method, mixed $value, array $args = false ) Sets a return for a parameter list that will be passed by value only when the required call count is reached.
throwAt ( integer $timing, string $method, object $exception = false, array $args = false ) Sets up a trigger to throw an exception upon the method call.
throwOn ( string $method, object $exception = false, array $args = false ) Sets up a trigger to throw an exception upon the method call.

보호된 메소드들

메소드 설명
addCall ( string $method, array $args ) Adds one to the call count of a method.
checkArgumentsIsArray ( mixed $args, string $task ) : boolean Die if bad arguments array is passed.
checkExpectations ( string $method, array $args, integer $timing ) Tests the arguments against expectations.
dieOnNoMethod ( string $method, string $task ) Triggers a PHP error if the method is not part of this object.
emulateCall ( string $method, array $args, integer $step ) : mixed Finds the return value matching the incoming arguments.
getCurrentTestCase ( ) : SimpeTestCase Finds currently running test.

비공개 메소드들

메소드 설명
disableEStrict ( ) Our mock has to be able to return anything, including variable references.
restoreEStrict ( integer $was ) Restores the E_STRICT level if it was previously set.

메소드 상세

__construct() 공개 메소드

All call counts are set to zero.
public __construct ( )

addCall() 보호된 메소드

Adds one to the call count of a method.
protected addCall ( string $method, array $args )
$method string Method called.
$args array Arguments as an array.

atTestEnd() 공개 메소드

Totals up the call counts and triggers a test assertion if a test is present for expected call counts.
public atTestEnd ( string $test_method, SimpleTestCase &$test )
$test_method string Current method name.
$test SimpleTestCase Test to send message to.

checkArgumentsIsArray() 보호된 메소드

Die if bad arguments array is passed.
protected checkArgumentsIsArray ( mixed $args, string $task ) : boolean
$args mixed The arguments value to be checked.
$task string Description of task attempt.
리턴 boolean Valid arguments

checkExpectations() 보호된 메소드

Tests the arguments against expectations.
protected checkExpectations ( string $method, array $args, integer $timing )
$method string Method to check.
$args array Argument list to match.
$timing integer The position of this call in the call history.

dieOnNoMethod() 보호된 메소드

Triggers a PHP error if the method is not part of this object.
protected dieOnNoMethod ( string $method, string $task )
$method string Name of method.
$task string Description of task attempt.

disableExpectationNameChecks() 공개 메소드

This hack is needed for the partial mocks.

emulateCall() 보호된 메소드

If there is no matching value found, then an error is triggered.
protected emulateCall ( string $method, array $args, integer $step ) : mixed
$method string Method name.
$args array Calling arguments.
$step integer Current position in the call history.
리턴 mixed Stored return or other action.

errorAt() 공개 메소드

Sets up a trigger to throw an error upon a specific method call.
public errorAt ( integer $timing, string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR )
$timing integer When to throw the exception. A value of 0 throws immediately. A value of 1 actually allows one call to this method before throwing. 2 will allow two calls before throwing and so on.
$method string Method name to throw on.
$error object Error message to trigger.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
$severity integer The PHP severity level. Defaults to E_USER_ERROR.

errorOn() 공개 메소드

Sets up a trigger to throw an error upon the method call.
public errorOn ( string $method, object $error = 'A mock error', array $args = false, integer $severity = E_USER_ERROR )
$method string Method name to throw on.
$error object Error message to trigger.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.
$severity integer The PHP severity level. Defaults to E_USER_ERROR.

expect() 공개 메소드

All calls will be compared to these expectations regardless of when the call is made.
public expect ( string $method, array $args, string $message = '%s' )
$method string Method call to test.
$args array Expected parameters for the call including wildcards.
$message string Overridden message.

expectAt() 공개 메소드

The expected call count will be adjusted if it is set too low to reach this call.
public expectAt ( integer $timing, string $method, array $args, string $message = '%s' )
$timing integer Number of calls in the future at which to test. Next call is 0.
$method string Method call to test.
$args array Expected parameters for the call including wildcards.
$message string Overridden message.

expectAtLeastOnce() 공개 메소드

Convenience method for requiring a method call.
public expectAtLeastOnce ( string $method, array $args = false, string $message = '%s' )
$method string Method call to track.
$args array Expected argument list or false for any arguments.
$message string Overridden message.

expectCallCount() 공개 메소드

The tally method is used to check this.
public expectCallCount ( string $method, integer $count, string $message = '%s' )
$method string Method call to test.
$count integer Number of times it should have been called at tally.
$message string Overridden message.

expectMaximumCallCount() 공개 메소드

Sets the number of times a method may be called before a test failure is triggered.
public expectMaximumCallCount ( string $method, integer $count, string $message = '%s' )
$method string Method call to test.
$count integer Most number of times it should have been called.
$message string Overridden message.

expectMinimumCallCount() 공개 메소드

Sets the number of times to call a method to prevent a failure on the tally.
public expectMinimumCallCount ( string $method, integer $count, string $message = '%s' )
$method string Method call to test.
$count integer Least number of times it should have been called.
$message string Overridden message.

expectNever() 공개 메소드

Convenience method for barring a method call.
public expectNever ( string $method, string $message = '%s' )
$method string Method call to ban.
$message string Overridden message.

expectOnce() 공개 메소드

Convenience method for a single method call.
public expectOnce ( string $method, array $args = false, string $message = '%s' )
$method string Method call to track.
$args array Expected argument list or false for any arguments.
$message string Overridden message.

getCallCount() 공개 메소드

Fetches the call count of a method so far.
public getCallCount ( string $method ) : integer
$method string Method name called.
리턴 integer Number of calls so far.

getCurrentTestCase() 보호된 메소드

Finds currently running test.
protected getCurrentTestCase ( ) : SimpeTestCase
리턴 SimpeTestCase Current test case.

invoke() 공개 메소드

Will generate anytest assertions as a result of expectations if there is a test present.
public invoke ( string $method, array $args ) : mixed
$method string Name of method to simulate.
$args array Arguments as an array.
리턴 mixed Stored return.

replaceWildcards() 공개 메소드

Replaces wildcard matches with wildcard expectations in the argument list.
public replaceWildcards ( array $args ) : array
$args array Raw argument list.
리턴 array Argument list with expectations.

returns() 공개 메소드

Sets a return for a parameter list that will be passed on by all calls to this method that match.
public returns ( string $method, mixed $value, array $args = false )
$method string Method name.
$value mixed Result of call by value/handle.
$args array List of parameters to match including wildcards.

returnsAt() 공개 메소드

Sets a return for a parameter list that will be passed only when the required call count is reached.
public returnsAt ( integer $timing, string $method, mixed $value, array $args = false )
$timing integer Number of calls in the future to which the result applies. If not set then all calls will return the value.
$method string Method name.
$value mixed Result of call passed.
$args array List of parameters to match including wildcards.

returnsByReference() 공개 메소드

Sets a return for a parameter list that will be passed by reference for all calls.
public returnsByReference ( string $method, mixed &$reference, array $args = false )
$method string Method name.
$reference mixed Result of the call will be this object.
$args array List of parameters to match including wildcards.

returnsByReferenceAt() 공개 메소드

Sets a return for a parameter list that will be passed by value only when the required call count is reached.
public returnsByReferenceAt ( integer $timing, string $method, mixed &$reference, array $args = false )
$timing integer Number of calls in the future to which the result applies. If not set then all calls will return the value.
$method string Method name.
$reference mixed Result of the call will be this object.
$args array List of parameters to match including wildcards.

returnsByValue() 공개 메소드

Sets a return for a parameter list that will be passed by value for all calls to this method.
public returnsByValue ( string $method, mixed $value, array $args = false )
$method string Method name.
$value mixed Result of call passed by value.
$args array List of parameters to match including wildcards.

returnsByValueAt() 공개 메소드

Sets a return for a parameter list that will be passed by value only when the required call count is reached.
public returnsByValueAt ( integer $timing, string $method, mixed $value, array $args = false )
$timing integer Number of calls in the future to which the result applies. If not set then all calls will return the value.
$method string Method name.
$value mixed Result of call passed by value.
$args array List of parameters to match including wildcards.

throwAt() 공개 메소드

Sets up a trigger to throw an exception upon the method call.
public throwAt ( integer $timing, string $method, object $exception = false, array $args = false )
$timing integer When to throw the exception. A value of 0 throws immediately. A value of 1 actually allows one call to this method before throwing. 2 will allow two calls before throwing and so on.
$method string Method name to throw on.
$exception object Exception object to throw. If not given then a simple Exception object is thrown.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.

throwOn() 공개 메소드

Sets up a trigger to throw an exception upon the method call.
public throwOn ( string $method, object $exception = false, array $args = false )
$method string Method name to throw on.
$exception object Exception object to throw. If not given then a simple Exception object is thrown.
$args array Optional argument list filter. If given then the exception will only be thrown if the method call matches the arguments.