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

Exception constraints consistency #254

Closed
pkruithof opened this issue Jun 11, 2018 · 1 comment
Closed

Exception constraints consistency #254

pkruithof opened this issue Jun 11, 2018 · 1 comment

Comments

@pkruithof
Copy link
Contributor

I've noticed that not all assertions pass their constraints to the exception, for instance:

eq has the expected value passed to the exception:

if ($value != $value2) {
$message = \sprintf(
static::generateMessage($message ?: 'Value "%s" does not equal expected value "%s".'),
static::stringify($value),
static::stringify($value2)
);
throw static::createException($value, $message, static::INVALID_EQ, $propertyPath, array('expected' => $value2));
}

greaterThan on the other hand, has not:

if ($value <= $limit) {
$message = \sprintf(
static::generateMessage($message ?: 'Provided "%s" is not greater than "%s".'),
static::stringify($value),
static::stringify($limit)
);
throw static::createException($value, $message, static::INVALID_GREATER, $propertyPath);
}

I would like to make this consistent across all assertions, in the following manner:
For every assertion, every argument between the asserted value and the message is part of the $constraints array, passed to the exception.

Please let me know if you'd consider this, then I'll make a PR for it.

@rquadling
Copy link
Contributor

Happy to accept a PR to make things consistent.

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

No branches or pull requests

2 participants