8000 [RateLimiter] Fix delete method of the cache storage by GregOriol · Pull Request #38661 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[RateLimiter] Fix delete method of the cache storage #38661

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

Merged
merged 3 commits into from
Oct 22, 2020
Merged

Conversation

GregOriol
Copy link
Contributor
Q A
Branch? 5.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets None
License MIT

This PR fixes a small issue with RateLimiter's cache storage and the delete method: all getItems are called with a sha1 of the id, but not the one for delete, which makes it miss the deletion.

Copy link
Member
@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you. This is correct.

Could you add a small unit test for this too?

@chalasr chalasr added this to the 5.2 milestone Oct 22, 2020
@GregOriol
Copy link
Contributor Author

I'm not sure how to write such a test, I'd rather not try to make something up here.

@Nyholm
Copy link
Member
Nyholm commented Oct 22, 2020

Do you mind if I push to your branch?

@GregOriol
Copy link
Contributor Author

Not at all, I'd be happy to take your suggestion on this :-)

Copy link
Member
@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

I added a test.

Im happy with this PR.


public function testDelete()
{
$this->pool->expects($this->once())->method('deleteItem')->with(sha1('test'))->willReturn(true);
Copy link
Member
@Nyholm Nyholm Oct 22, 2020

Choose a reason for hiding this comment

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

This line uses $this->pool which is a mock created in setUp().

We say that we "expect" that "once" the "method deleteItem" is called with sha1('test'). We also return true.

If what we expect does not happen, then the test will fail

{
$this->pool->expects($this->once())->method('deleteItem')->with(sha1('test'))->willReturn(true);

$this->storage->delete('test');
Copy link
Member

Choose a reason for hiding this comment

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

This is just calling the storage

@Nyholm
Copy link
Member
Nyholm commented Oct 22, 2020

Thank you @GregOriol.

@Nyholm Nyholm merged commit 76c22fa into symfony:5.x Oct 22, 2020
@fabpot fabpot mentioned this pull request Oct 28, 2020
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.

6 participants
0