I’ve got a simple function like this:
function CreateFileLink() { global $Username; return date('d-m-y-g-i'); }
How do you write code to test a function like that where the return data is variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could test it if you could somehow get control over that date() function. For example, in this case, you only care that the date function is being called with ‘d-m-y-g-i’; you don’t really care about the output of it. Maybe something like:
Sorry, I don’t even know what language this is but hopefully you can see my point. In production code, you’d call this by doing:
But in your test, you can provide an alternate implementation that will throw an error if the input isn’t what you expect: