Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/mockatoo/Mockatoo.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mockatoo;

import haxe.macro.Expr;
import haxe.macro.Context;
import mockatoo.internal.MatcherClass;
import mockatoo.macro.InitMacro;
import mockatoo.macro.MockMaker;
import mockatoo.macro.VerifyMacro;
Expand Down Expand Up @@ -336,6 +337,7 @@ enum Matcher
isNotNull; // any non null value
any; // wildcard for any value
customMatcher(f:Dynamic -> Bool); //custom function to verify value
matcherClass(instance:MatcherClass); //custom function to verify value
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/mockatoo/internal/MatcherClass.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package mockatoo.internal;

/**
* Generic typedef for any matcher class that have a matches function.
* This way you can use any 3rdparty framework like hamcrest to match against complex conditions.
* @author grosmar
*/

typedef MatcherClass =
{
function matches(item:Dynamic):Bool;
}
4 changes: 3 additions & 1 deletion src/mockatoo/internal/MockMethod.hx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package mockatoo.internal;
import haxe.Constraints.IMap;
import mockatoo.exception.VerificationException;
import mockatoo.exception.StubbingException;
import mockatoo.Mockatoo;
Expand Down Expand Up @@ -297,6 +298,7 @@ class MockMethod
case Matcher.isNotNull: return actual != null;
case Matcher.any: return true;
case Matcher.customMatcher(f): return f(actual);
case Matcher.matcherClass(instance): return instance.matches(actual);
}
}
case TClass(_):
Expand Down Expand Up @@ -331,7 +333,7 @@ class MockMethod
if (value == null) return false;

// Please note, we cannot check HashMap because it is an abstract, and does not have an iterator function at runtime.
if (Std.is(value, Array) || Std.is(value, Map.IMap)) return true;
if (Std.is(value, Array) || Std.is(value, IMap)) return true;

//Iterable
var iterator = Reflect.field(value, "iterator");
Expand Down
3 changes: 0 additions & 3 deletions src/mockatoo/macro/MockTestMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class MockTestMacro

if (befores.length == 0 || afters.length == 0) return null;

if (!Context.defined("munit"))
Context.warning("Unable to generate mocks - @:mock and @:spy require munit", Context.currentPos());

if (beforeField == null)
{
beforeField = createField(FIELD_SETUP, META_BEFORE, befores);
Expand Down