mockolate icon indicating copy to clipboard operation
mockolate copied to clipboard

Complain on mismatched argument count

Open drewbourne opened this issue 14 years ago • 0 comments

When specifying expected arguments using .args() Mockolate should verify the argument count where possible.

Example

public class ArgumentCountExample
{
    public function methodNoArgs():void {}
    public function methodRequiredArgs(req1:Object, req2:Object):void {}
    public function methodOptionalArgs(opt:Object = null):void {}
    public function methodRestArgs(...rest):void {}
    public function methodMixedArgs(req:Object, opt:Object = null, ..rest):void {}
}
// accepted
mock(example).method('methodNoArgs').noArgs(); 
mock(example).method('methodRequiredArgs').args(1, 2); 
mock(example).method('methodOptionalArgs').args(1); 
mock(example).method('methodRestArgs').args(1, 2, 3);
mock(example).method('methodRestArgs').args(1, 2, 3);
mock(example).method('methodMixedArgs').args(1, 2);
mock(example).method('methodMixedArgs').args(1, 2, 3);

// denied
mock(example).method('methodNoArgs').args(1); // should throw TooManyArgumentsError
mock(example).method('methodRequiredArgs').args(1); // should throw TooFewArgumentsError
mock(example).method('methodOptionalArgs').args(1, 2); // should throw TooManyArgumentsError

drewbourne avatar Mar 06 '12 23:03 drewbourne