Skip to content

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Jul 5, 2018

No description provided.

@oakbani oakbani requested a review from mikeproeng37 July 5, 2018 12:23
@coveralls
Copy link

coveralls commented Jul 5, 2018

Coverage Status

Coverage increased (+0.9%) to 97.074% when pulling 2b0610d on oakbani/validate-feature-api-inputs into 9984ac5 on master.

}

$enabledFeatureKeys = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave this at line 561 (on left) and return this empty array on lines 569 and 574 on the left?

$optimizelyMock->expects($this->once())
->method('validateInputs')
->with($inputArray)
->willReturn(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This testcase is a little confusing, you are passing in what seems to be valid inputs test_feature and test_user but mocking the validateInputs methods to return false.

Let's instead assign $userId to null and then ensure that validateInputs is called with it and then the assertFalse you already have will validate the isFeatureEnabled returns correctly. Also, ensure that the logger logs the appropriate message for invalid inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I have made userId null for clarity.
TestDoubles in PHPUnit provide a dummy implementation that simply returns null without calling the original method. See it here: https://phpunit.de/manual/6.5/en/test-doubles.html
That's why I add willReturn part for clarity to sort of show that when validateInputs returns false, the method is asserted false. The actual asserting part is the expectation of validateInputs being called with same params.
The testcase doesn't guarantee that the method ended right after valdiateInputs returned false or later. A better way could be asserting that code after validateInputs has returned isn't executed.

As for logging, I am already comprehensively testing logging in unit tests for validateInputs method. This would be repetitive here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense. Will approve now

$optimizelyMock->expects($this->once())
->method('validateInputs')
->with($inputArray)
->willReturn(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

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

Looks mostly good, just need to make the test cases clearer

@mikeproeng37 mikeproeng37 merged commit b8ee905 into master Jul 5, 2018
@oakbani oakbani deleted the oakbani/validate-feature-api-inputs branch July 6, 2018 06:15
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

Successfully merging this pull request may close these issues.

3 participants