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

Assert with optinal description #7 #8

Merged
merged 3 commits into from Sep 15, 2019
Merged

Conversation

integer
Copy link
Contributor

@integer integer commented Jul 11, 2019

  • new feature #7
  • BC break? no

With this PR you can add description to your asserts and this description will be printed in error messages.

$schema = Expect::string()
        ->assert('ctype_digit', 'Is number')
        ->assert(function ($s) { return strlen($s) >= 3; }, 'Minimal lenght');

@integer integer force-pushed the assert-with-description branch 3 times, most recently from 9e5851a to fb99032 Compare Jul 11, 2019
@dg
Copy link
Member

@dg dg commented Jul 12, 2019

It could be implemented in an alternative way, but I don't know what's better.

$schema = Expect::arrayOf('string')
	->assert(function ($v) { 
		if (count($v) % 2 !== 0) { // count must be even number
			throw new AssertException('Even items in array');
		}
	}); 

@mabar
Copy link
Contributor

@mabar mabar commented Jul 12, 2019

I would like exception, it allows non-statical error messages

@dg
Copy link
Member

@dg dg commented Jul 12, 2019

After experience with forms and addRule() I would prefer exceptions today.

@integer
Copy link
Contributor Author

@integer integer commented Jul 12, 2019

Exceptions requires more writing, but you can prepare better message. I will try exceptions in my project. Thank you for hint.

@dg dg merged commit 60ba751 into nette:master Sep 15, 2019
1 check was pending
dg pushed a commit that referenced this issue Sep 15, 2019
dg pushed a commit that referenced this issue Sep 15, 2019
dg pushed a commit that referenced this issue Sep 24, 2019
dg pushed a commit that referenced this issue Oct 31, 2019
dg pushed a commit that referenced this issue Oct 31, 2019
dg pushed a commit that referenced this issue Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants