meilisearch-php icon indicating copy to clipboard operation
meilisearch-php copied to clipboard

Remove all keys before running tests

Open brunoocasali opened this issue 3 years ago • 2 comments

Currently, in the tests (especially KeysAndPermissionsTest.php) we manually remove the created keys using $this->client->deleteKey. This is good, but we can do better.

The idea of this issue is to create a way of doing that for every test. We can use setUp() hook for that.

This will probably break some tests where we rely on the default keys created by Meilisearch automatically, those tests now should set up their own keys before asserting on them.

brunoocasali avatar Aug 11 '22 22:08 brunoocasali

The expectation is to not use $this->client->deleteKey in every test cases?

As the deleteKey should be executed after completing running the tests, shouldn't we use tearDown hook?

arifszn avatar Oct 11 '22 07:10 arifszn

The expectation is to not use $this->client->deleteKey in every test cases?

Yes, we can use hooks for this kind of setup/teardown.

As the deleteKey should be executed after completing running the tests, shouldn't we use tearDown hook?

I agree with you! But we can have the same behavior by using the setUp, I really like this reference from cypress when it comes to why using after hooks is not that good, https://docs.cypress.io/guides/references/best-practices#Using-after-or-afterEach-hooks

brunoocasali avatar Oct 11 '22 08:10 brunoocasali