Skip to content

Commit 8c81fb8

Browse files
committed
fixed issue of not properly clearing arg matcher stack which lead to errors in subsequent calls
1 parent c336b8d commit 8c81fb8

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Source/Core/Mocking/Spring.Mocking.Interceptor.pas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ procedure TMockInterceptor.InterceptArrange(const invocation: IInvocation);
305305
begin
306306
try
307307
if not Assigned(fMatch) then
308-
fMatch := TMatcherFactory.CreateMatchers(invocation.Arguments, invocation.Method.GetParameters);
308+
fMatch := TMatcherFactory.CreateMatchers(invocation.Arguments, invocation.Method.GetParameters)
309+
else
310+
TMatcherFactory.ClearConditionStack;
309311
if not Assigned(fMatch) then
310312
fMatch := CreateArgMatch(invocation.Arguments, invocation.Method.GetParameters);
311313
fExpectedCalls.AddRange(invocation.Method, CreateMethodCalls);
@@ -322,7 +324,9 @@ procedure TMockInterceptor.InterceptAssert(const invocation: IInvocation);
322324
begin
323325
try
324326
if not Assigned(fMatch) then
325-
fMatch := TMatcherFactory.CreateMatchers(invocation.Arguments, invocation.Method.GetParameters);
327+
fMatch := TMatcherFactory.CreateMatchers(invocation.Arguments, invocation.Method.GetParameters)
328+
else
329+
TMatcherFactory.ClearConditionStack;
326330
if fReceivedCalls.TryGetValues(invocation.Method, arguments) then
327331
begin
328332
if not Assigned(fMatch) then

Source/Core/Mocking/Spring.Mocking.Matching.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ TMatcherFactory = record
6565
/// </summary>
6666
class function CreateMatchers(const indizes: TArray<TValue>;
6767
const parameters: TArray<TRttiParameter>): Predicate<TArray<TValue>>; static;
68+
69+
class procedure ClearConditionStack; static;
6870
end;
6971

7072
RefArgs = record
@@ -349,6 +351,11 @@ class function TMatcherFactory.CreateMatcher<T>(
349351
Result := WrapIndex<T>(index);
350352
end;
351353

354+
class procedure TMatcherFactory.ClearConditionStack;
355+
begin
356+
conditionStack := nil;
357+
end;
358+
352359
class function TMatcherFactory.AddMatcher(
353360
const condition: Predicate<TValue>): Integer;
354361
begin

Tests/Source/Core/Spring.Tests.Mocking.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ procedure TParameterMatchingTests.ArgsStackProperlyCleaned;
221221
mock.Instance.Test2('', 0, False);
222222
mock.Received(Times.Once).Test2(Arg.IsAny<string>, Arg.IsAny<Integer>, Arg.IsAny<Boolean>);
223223

224+
mock.Setup.Executes.When(Args.Any).Test1(Arg.IsAny<Integer>, Arg.IsAny<string>);
225+
mock.Setup.Executes.When.Test1(Arg.IsAny<Integer>, Arg.IsAny<string>);
226+
224227
Pass;
225228
end;
226229

0 commit comments

Comments
 (0)