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

For missing properties, the key for that error in set to "" #154

Conversation

samkeen
Copy link
Contributor

@samkeen samkeen commented Jun 5, 2015

Expected bahavior is that the key would be set to the poperty name.

This fix addressed the same issue PR'd by @primitive-type but is
rebased to current master

@bighappyface
Copy link
Collaborator

@samkeen good fix. Would you mind including a test for this?

@samkeen
Copy link
Contributor Author

samkeen commented Jun 15, 2015

added tests. Let me know if they are adequate. I can also rebase to a single commit if you prefer.

@bighappyface
Copy link
Collaborator

@samkeen thank you for the update! I think a squash would be great.

I have restarted the Travis runs to see if the failures clear up.

@samkeen samkeen force-pushed the fix_empty_property_keyname_when_property_is_missing branch from 745cd08 to c3ec089 Compare June 16, 2015 18:54
@samkeen
Copy link
Contributor Author

samkeen commented Jun 16, 2015

rebased to current upstream/master, + 2 commits squashed to 1

@bighappyface
Copy link
Collaborator

+1 looks good. @alecsammon @Maks3w would you mind to help review?


$validator->check($document, $schema);
$error = $validator->getErrors();
$this->assertEquals('foo', $error[0]['property']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $error is not well formatted, i.e. there is no index 0 or 'property` key does not exists test run will stop without an useful message.

Could you try to compare the whole $error variable or assert 0 and property exists?

@Maks3w
Copy link
Contributor

Maks3w commented Jun 16, 2015

@bighappyface, @samkeen has reveal invalid data provider is not enough without to check invalid data fails with the expected message.

i.e. invalid data providers should be refactored for to check the error message too.

@samkeen samkeen force-pushed the fix_empty_property_keyname_when_property_is_missing branch from c3ec089 to b1c2f65 Compare June 16, 2015 21:41

$validator->check($document, $schema);
$error = $validator->getErrors();
if(!isset($error[0]['property'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPUnit provides assertArrayHasKey and assertArraySubset try to use one of them.

Also this does not check if index 0 is set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry assertArraySubset requires phpunit ^4.4.0 /cc @bighappyface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry been away from PHP for a while. Let me know if latest push works, not the most elegant code but I think it covers any malformed input with a helpful fail message.

- Expected bahavior is that the key would be set to the poperty name.
- added tests to ensure the "property" is populated regardless
of required attribute is completely missing or has empty value.
@samkeen samkeen force-pushed the fix_empty_property_keyname_when_property_is_missing branch from b1c2f65 to a71086d Compare June 16, 2015 22:45
@samkeen
Copy link
Contributor Author

samkeen commented Jun 17, 2015

sorry @Maks3w , i realized i didn't use assertArrayHasKey as you suggested. I guess I thought it was better to have a single PHPUnit Assertion per test. If you like though, I can change it.

@bighappyface
Copy link
Collaborator

@Maks3w any last thoughts on this PR?

@nsitbon
Copy link

nsitbon commented Jul 3, 2015

Can you merge guys we are actively waiting for this PR making our tests failed.
Thx.

bighappyface added a commit that referenced this pull request Jul 13, 2015
…property_is_missing

For missing properties, the key for that error in set to ""
@bighappyface bighappyface merged commit 66c1330 into jsonrainbow:master Jul 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants