Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Fixes cache entry deletion directly after creation #184

Merged
merged 5 commits into from
Aug 28, 2019
Merged

Fixes cache entry deletion directly after creation #184

merged 5 commits into from
Aug 28, 2019

Conversation

alexz707
Copy link
Contributor

See
#183

Only set TTL if there is a value which is not null!

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

This change requires unit tests, please, to demonstrate that no TTL is present in the item if none was provided.

src/Psr/SimpleCache/SimpleCacheDecorator.php Outdated Show resolved Hide resolved
@michalbundyra michalbundyra added this to the 2.8.3 milestone Aug 14, 2019
We should use TTL from options when it is not provided on set/setMultiple
methods of SimpleCacheDecorator.
@michalbundyra
Copy link
Member

@weierophinney I've added tests to cover changes and prove the issue. Instead of mocking storage and options, I've implemented storage and logged TTL when setting the item in cache. Then in assertion I am checking what value of TTL was set for the item.

@michalbundyra
Copy link
Member

Actually using mocking it will be also quite simply:

    public function testUseTtlFromOptionsOnSetMocking()
    {
        $this->options->getTtl()->willReturn(40);
        $this->options->setTtl(40)->will([$this->options, 'reveal']);

        $this->options->setTtl(null)->shouldNotBeCalled();

        $this->storage->getOptions()->will([$this->options, 'reveal']);
        $this->storage->setItem('foo', 'bar')->willReturn(true);

        self::assertTrue($this->cache->set('foo', 'bar'));
    }

    public function testUseTtlFromOptionsOnSetMultipleMocking()
    {
        $this->options->getTtl()->willReturn(40);
        $this->options->setTtl(40)->will([$this->options, 'reveal']);

        $this->options->setTtl(null)->shouldNotBeCalled();

        $this->storage->getOptions()->will([$this->options, 'reveal']);
        $this->storage->setItems(['foo' => 'bar', 'boo' => 'baz'])->willReturn([]);

        self::assertTrue($this->cache->setMultiple(['foo' => 'bar', 'boo' => 'baz']));
    }

But not sure if it is clear enough?

Line

$this->options->setTtl(null)->shouldNotBeCalled();

in both tests is not really needed. It says explicitly that we do not allow that cal, but as we are mocking options anyway, we are saying what calls are allowed (and all others are not).

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

Tests are easily understandable, and the solution looks reasonable. 🚢

michalbundyra added a commit that referenced this pull request Aug 28, 2019
Fixes cache entry deletion directly after creation
michalbundyra added a commit that referenced this pull request Aug 28, 2019
@michalbundyra michalbundyra merged commit 96fa750 into zendframework:master Aug 28, 2019
michalbundyra added a commit that referenced this pull request Aug 28, 2019
@michalbundyra
Copy link
Member

Thanks, @alexz707!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants