views:

46

answers:

1

PHP is somewhat crippled since it doesn't have return types (yet). I need my code to throw an exception when X already exists. I can write this in a scenario, but I'm not able to go from the scenarios to the interface my class should implement.

Actually this problem is the same in TDD I guess. There seems more that I can tell through my 'tests' than through my interfaces. Yet my interfaces define what components can interact, what responsibilities they should take.

The problem is bigger in PHP because it doesn't have return types but it also exists in other languages because there is no contract that says an exception should be thrown when x is the case.

How can I best deal with this?

+1  A: 

In languages that throw exceptions, the interface is only part of the contract specification. Use the tests to describe the rest of the contract by asserting that the correct exceptions are thrown when expected.

Seb Rose