Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Violating contracts should throw ContractViolation #30

Closed
icanhazstring opened this issue Jan 13, 2019 · 1 comment
Closed

Violating contracts should throw ContractViolation #30

icanhazstring opened this issue Jan 13, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@icanhazstring
Copy link
Member

icanhazstring commented Jan 13, 2019

Source branch: 1.x

A violation with a contract should not throw a DomainException with

Fatal error: Uncaught DomainException: Invalid return value received from the assertion body, only boolean or void can be returned in deal/demo/Account.php on line 51

To reproduce this, simply change the demo Account::getBalance to return any value instead 100.


It should instead raise an ContractViolation explaining what contract was violated with what value.
Somthing like this:

PHP Fatal error:  Uncaught PhpDeal\Exception\ContractViolation: Contract $amount>0 && is_numeric($amount) violated with -1 for Demo\Account->deposit in XXX

Since this will change exceptions raised, this is assumed a breaking change.
To change this, one has to change the AbstractContractAspect inside ensureContracts. If the $invocationResult equals false, a ContractViolation should be raised.

@icanhazstring icanhazstring added this to the 1.0.0 milestone Jan 13, 2019
icanhazstring added a commit that referenced this issue Jan 22, 2019
If contract validation result is bool but false, we will throw a
ContractViolation instead of a DomainException. This will make sure, the
topmost exception is clear and understandable.
@icanhazstring icanhazstring self-assigned this Jan 22, 2019
@icanhazstring
Copy link
Member Author

icanhazstring commented Jan 24, 2019

Solved with 20f0cef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant