Closed bbatsche closed 2 years ago
We could theoretically overload __call()
and add this functionality there as well. Would that make the fluent API too funky? Is it adding too much to that method?
verify($user)->getName()->will()->returnValue()->equalTo('John')
->setBirthday('Tomorrow')->throwException()->instanceOf(BadBirthday::class)
->setBirthday('1984-10-30')->returnValue()->null();
Is there anyway we could support verify($foo)->method('bar')->willNot()->throwException();
?
Should split out verifier classes (use withVerifier()
internally to swap them out).
Value
+- Attribute
+- Method
+- Exception
getActual()
in Value
becomes simple stud method, other verifiers override with their own logic.
Override getActual()
in File
as well. Create a getContents($filename)
method that will do assert readable, is file, open, read contents, if false
fail, return contents. getActual()
uses that to read subject contents and cache locally.
Add
method()
accessor toValue
class. Will allow you to write assertions about the return value & exception thrown by a method of an object or (static method of a) class.Method is invoked at
returnValue()
and value is stored locally in$resolvedValue
so additional assertions can be done against it without reinvoking the method.with(...$args)
allows passing arguments to method, and can be used to create a sort of data provider to the method.throwException()
will invoke method and capture the exception locally. Can drill down into properties of the exception withwithMessage()
andwithCode()
methods.If exception is not thrown in
throwException()
then test is failed.