Skip to content

Added tests for described Exoskeleton functionality#8

Open
anigeluk wants to merge 20 commits intoAutomattic:masterfrom
anigeluk:master
Open

Added tests for described Exoskeleton functionality#8
anigeluk wants to merge 20 commits intoAutomattic:masterfrom
anigeluk:master

Conversation

@anigeluk
Copy link
Copy Markdown

There are failing tests in place for functionality described in the readme which isn't currently supported by the existing code.

method can also be a comma-separated list of methods, eg: POST,GET,PUT

I have not been able to test the 429 header and the retry-after headers are successfully set in my testing environment.

Copy link
Copy Markdown

@mdbitz mdbitz left a comment

Choose a reason for hiding this comment

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

Hi Sarah:

I want through the tests with a fine tooth comb :) I really like the coverage these tests give but we could clean it up a little further for the merge.

Comment thread tests/test-exoskeleton-add-rule.php Outdated
/**
* Test adding a valid rule with multiple methods
*
* @dataProvider validRuleProvider
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test validates the case of having comma separated method provided. Using a dataProvider doesn't provide any additional benefit. I would suggest switching to getValidRuleHelper.

Comment thread tests/test-exoskeleton-add-rule.php Outdated
/**
* Pre test setup
*/
function setUp() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setup isn't providing setup of any data. We should be cleaning rule sets as part of TearDown vs setUp e.g. cleanup after vs before a test.

Comment thread tests/test-exoskeleton-add-rule.php Outdated
/**
* Check that exoskeleton will not overwrite an already existing rule
*
* @dataProvider validRuleProvider
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DataProvider usage here doesn't provide additional coverage we could remove this as additional executions on different rules don't provide benefit.

Comment thread tests/test-exoskeleton-add-rule.php Outdated
* Test adding a valid rule for a custom route
* Exoskeleton makes no check for existence of custom route.
*
* @dataProvider validRuleProvider
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

coverage is same if change this to a single test without a dataProvider

parent::setUp();

// Clear existing rules.
$instance = Exoskeleton::get_instance();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this is an instance, we should do clean up in tearDown vs the setUp

/**
* Check that exoskeleton validates rules with an invalid rule
*
* @dataProvider validRuleProvider
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Best Practices is to use datProviders for multiple test points. Using them for a single item is better suited for a helper/util function so that it is easier to understand the flow.

Comment thread tests/test-exoskeleton-add-rule.php Outdated
*
* @var array Three valid rule definitions
*/
protected static $three_valid_rules;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

per my review this is no longer utilized. If that is true we should clean it up/remove.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are correct :) I should have removed this when switching to data providers.

@mdbitz
Copy link
Copy Markdown

mdbitz commented Jun 12, 2017

Thanks for taking the time to implement my suggestions. These look good to merge I'm just going to leave it open for Josh to make the final call.

@header( "Retry-After: $retry_after" );

// Do not die if testing.
if ( defined( 'PHPUNIT_EXOSKELETON_TESTING' ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it make sense to calculate the retry after headers in a different function that would be easier to test? Then we could just output the headers and exit here without altering any logic for tests.

@joshbetz
Copy link
Copy Markdown
Contributor

I think it would be good to avoid changing the logic for tests, but otherwise looks good to me.

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