2

Recently, I've started to working on Email2SMS feature in our product. When I joined the project this component had zero code coverage by unit-tests. Legacy code.

Since I started to working on it, I was using test-first approach. But code quality was very low. It was very hard to split it and tests small chunks by unit-tests, so I decided to write integration test.

There is php script, which accepts some message info, search for user in DB and save some info if everything is OK.

$last_line = system('php emailtosms.php -file=unicode_message.txt ', $retval);

$this->assertStringExistsInLogFile('Email to SMS message was not sent');

Is it bad or not? How would you solve this problem?

1 Answer 1

3

Not so good.

Test at a lower level, by having the emailtosms.php script as a simple wrapper that processes the command line args, and then pass off to more testable class. Depending on the final step, you could write unit tests to do almost every but the final send (maybe mock the final step that actually sends it, and just store it to a variable, then check you've got something valid there).

The final integration, runs the full class end-to-end, and check its output, looking at the final log - or a little higher-level, what would be put into to log.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.