Skip to content

Refactored test suite to make sure the tests are running isolated #19

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

Conversation

ppshobi
Copy link
Contributor

@ppshobi ppshobi commented Apr 21, 2020

Hi, This is obviously a big pull request. Please take time to review it especially because this is the test suite. But I have made changes in small chunks so that the review process will be easier. That is also the reason you can see a big commit list.

I will give you an idea about the changes I have done in this PR.

  • There is a base TestCase.php class which all the test classes should extend and its a place we can have the basic bootstrapping of our test suite
  • Then I have gone through each test classes and removed/replaced the static methods by making use of constructor() and setup() methods as necessary and isolated each test methods to be run independently of each other. Then made sure the entire test class passes and then the whole suite. Then move on to the next class.
  • One or two extra tests were added and removed as necessary. Some method extraction refactoring was done on a few tests as it would cut the duplication.

@curquiza
Copy link
Member

Related to #23

@curquiza curquiza linked an issue Apr 22, 2020 that may be closed by this pull request
@ppshobi ppshobi force-pushed the setup-base-test-cases-and-refactorings-to-test-suite branch from 974935a to 47e605c Compare April 22, 2020 22:23
@ppshobi
Copy link
Contributor Author

ppshobi commented Apr 22, 2020

I think the PR is ready to review. Please let me know what you think. I have some other refactorings in mind, but it would require changes in the src/ so I have refrained myself from doing it at least in this PR.

@curquiza curquiza requested review from curquiza and bidoubiwa April 23, 2020 08:42
@ppshobi ppshobi changed the title [WIP]Setup base test case and refactoring to test suite Refactoring Test suite to make sure the tests are running isolated Apr 23, 2020
@ppshobi ppshobi changed the title Refactoring Test suite to make sure the tests are running isolated Refactored test suite to make sure the tests are running isolated Apr 23, 2020
@ppshobi ppshobi force-pushed the setup-base-test-cases-and-refactorings-to-test-suite branch from a368133 to 67adb2f Compare April 24, 2020 15:52
Co-Authored-By: Clémentine Urquizar <clementine@meilisearch.com>
@ppshobi ppshobi force-pushed the setup-base-test-cases-and-refactorings-to-test-suite branch from 56a34f3 to 8e3de7e Compare April 25, 2020 08:55
@curquiza
Copy link
Member

Related to this issue.

@bidoubiwa
Copy link
Contributor

Is it possible to add two tests in search ?
Those tests are made to see if the SDK handles correctly the fact that some search parameters can either be an array of strings or a single string.

Test 1

{
        limit: 5,
        offset: 0,
        attributesToRetrieve: ['id', 'title'],
        attributesToCrop: ['id', 'title'],
        cropLength: 6,
        attributesToHighlight: ['id', 'title'],
        filters: 'title = "Le Petit Prince"',
        matches: true,
}

You should have these keys

$this->assertArrayHasKey('_matchesInfo', $response["hits"][0]);
$this->assertArrayHasKey('title', $response["hits"][0]['_matchesInfo']);
$this->assertArrayHasKey('_formatted', $response["hits"][0]);

But not these keys:

$this->assertArrayNotHasKey('comment', $response["hits"][0]);
$this->assertArrayNotHasKey('comment', $response["hits"][0]['_matchesInfo']);

Try those value

$this->assertSame('Petit <em>Prince</em>', $response["hits"][0]["_formatted"]["title"]);

test 2

{
        limit: 5,
        offset: 0,
        attributesToRetrieve: "*",
        attributesToCrop: "*",
        cropLength: 6,
        attributesToHighlight: "*",
        filters: 'title = "Le Petit Prince"',
        matches: true,
}

You should have these keys

$this->assertArrayHasKey('_matchesInfo', $response["hits"][0]);
$this->assertArrayHasKey('_formatted', $response["hits"][0]);
$this->assertArrayHasKey('comment', $response["hits"][0])
$this->assertArrayHasKey('comment', $response["hits"][0]["_formatted"])
$this->assertArrayHasKey('title', $response["hits"][0]['_formatted']);
$this->assertArrayHasKey('title', $response["hits"][0]['_matchesInfo']);
$this->assertArrayHasKey('comment', $response["hits"][0]['_matchesInfo'])

Try those value

$this->assertSame('Petit <em>Prince</em>', $response["hits"][0]["_formatted"]["title"]);

Tests could be improved but this assure us that the strings are handled correctly!

@ppshobi ppshobi force-pushed the setup-base-test-cases-and-refactorings-to-test-suite branch from 3bbbd00 to 96c6c2c Compare April 28, 2020 22:29
Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

Great added tests! Thanks a lot

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

🎉

@curquiza
Copy link
Member

Need rebasing, and we are finally done @ppshobi 🙂 🎉

@ppshobi
Copy link
Contributor Author

ppshobi commented Apr 29, 2020

Done 👍

@curquiza
Copy link
Member

Perfeeeeeeect 👌 Thanks again @ppshobi!

@curquiza curquiza merged commit ccaed64 into meilisearch:master Apr 29, 2020
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.

Refactoring tests
4 participants