Problem
When switching verifiers, we may want to use the resolved value as a (temporary) subject. For example, in our docs on switching verifiers we go from verifying the return value of a method to file contents. The “subject” for the file verifier should never be the object or method, it should always be the returned value.
Abstract
Add the concept of an “original” subject versus resolved subject. The withVerifier() method will provide both. There must then be some consistent logic for what the target verifier will consider the subject under test. Some examples:
- File verifier will always treat resolved value as the subject (aka, filename)
method()/__call()/attributeName()/)__get() will use the original subject if there has already been some assertions about the resolved value, otherwise it will resolve the subject and treat that as the SUT. This should allow verifying the result of method/attribute chains.
jsonContent() will always use the resolved subject. Using jsonContent() from the File verifier should use the file’s contents
arrayContent() is the inverse of method/attributes: it should use the resolved value if that has been triggered (via __get()). Otherwise revert back to the original subject. This should also allow for deeper array inspection
Solution
Add parameter to constructors for “previous verifier”, whenever we use withVerifier() pass along the previous verifier. Using any of the magic methods will target the current subject. If the method doesn’t work or make sense with the subject we will traverse up the stack until we find a subject where the method makes sense.
Add methods for previousSubject() and originalSubject() to allow user to explicitly traverse the stack
Problem
When switching verifiers, we may want to use the resolved value as a (temporary) subject. For example, in our docs on switching verifiers we go from verifying the return value of a method to file contents. The “subject” for the file verifier should never be the object or method, it should always be the returned value.
Abstract
Add the concept of an “original” subject versus resolved subject. The
withVerifier()method will provide both. There must then be some consistent logic for what the target verifier will consider the subject under test. Some examples:method()/__call()/attributeName()/)__get()will use the original subject if there has already been some assertions about the resolved value, otherwise it will resolve the subject and treat that as the SUT. This should allow verifying the result of method/attribute chains.jsonContent()will always use the resolved subject. UsingjsonContent()from the File verifier should use the file’s contentsarrayContent()is the inverse of method/attributes: it should use the resolved value if that has been triggered (via__get()). Otherwise revert back to the original subject. This should also allow for deeper array inspectionSolution
Add parameter to constructors for “previous verifier”, whenever we use
withVerifier()pass along the previous verifier. Using any of the magic methods will target the current subject. If the method doesn’t work or make sense with the subject we will traverse up the stack until we find a subject where the method makes sense.Add methods for
previousSubject()andoriginalSubject()to allow user to explicitly traverse the stack