<commit_before><?php

namespace Rollerworks\Component\Cache\Tests;

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Rollerworks\Component\Cache\SessionCache;

class SessionCacheTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var Session
     */
    protected $session;

    public function testSetFetch()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar');
        $this->assertTrue($cache->contains('foo'));
        $this->assertEquals('bar', $cache->fetch('foo'));

        $cache->save('foo2', 'bar2');
        $this->assertTrue($cache->contains('foo2'));
        $this->assertEquals('bar2', $cache->fetch('foo2'));
    }

    public function testRemove()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar');

        $this->assertTrue($cache->contains('foo'));
        $this->assertTrue($cache->delete('bar'));
        $this->assertTrue($cache->contains('foo'));
        $this->assertTrue($cache->delete('foo'));
        $this->assertFalse($cache->contains('foo'));
    }

    public function testFlush()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar');
        $cache->save('foo2', 'bar2');

        $this->assertTrue($cache->contains('foo'));
        $this->assertTrue($cache->contains('foo2'));
        $this->assertTrue($cache->flushAll());

        $this->assertFalse($cache->contains('foo'));
        $this->assertFalse($cache->contains('foo2'));
    }

    public function testExpires()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar', 2);
        $this->assertTrue($cache->contains('foo'));

        sleep(2);

        // This should return false as the cache is expired
        $this->assertFalse($cache->contains('foo'));
    }

    protected function setUp()
    {
        $storage = new MockArraySessionStorage();
        $this->session = new Session($storage);
    }
}<commit_msg>increased testing coverage to make sure fetch() works as expected when its expired<commit_after><?php

namespace Rollerworks\Component\Cache\Tests;

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Rollerworks\Component\Cache\SessionCache;

class SessionCacheTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var Session
     */
    protected $session;

    public function testSetFetch()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar');
        $this->assertTrue($cache->contains('foo'));
        $this->assertEquals('bar', $cache->fetch('foo'));

        $cache->save('foo2', 'bar2');
        $this->assertTrue($cache->contains('foo2'));
        $this->assertEquals('bar2', $cache->fetch('foo2'));
    }

    public function testRemove()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar');

        $this->assertTrue($cache->contains('foo'));
        $this->assertTrue($cache->delete('bar'));
        $this->assertTrue($cache->contains('foo'));
        $this->assertTrue($cache->delete('foo'));
        $this->assertFalse($cache->contains('foo'));
    }

    public function testFlush()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar');
        $cache->save('foo2', 'bar2');

        $this->assertTrue($cache->contains('foo'));
        $this->assertTrue($cache->contains('foo2'));
        $this->assertTrue($cache->flushAll());

        $this->assertFalse($cache->contains('foo'));
        $this->assertFalse($cache->contains('foo2'));
    }

    public function testExpires()
    {
        $cache = new SessionCache($this->session);

        $cache->save('foo', 'bar', 2);
        $this->assertTrue($cache->contains('foo'));

        sleep(3);

        // This should return false as the cache is expired
        $this->assertFalse($cache->contains('foo'));
        $this->assertFalse($cache->fetch('foo'));
    }

    protected function setUp()
    {
        $storage = new MockArraySessionStorage();
        $this->session = new Session($storage);
    }
}
{'fraction_non_alphanumeric': 0.1844888366627497, 'fraction_numerical': 0.005170387779083431, 'mean_word_length': 3.068833652007648, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5664050', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1181, 'n_words': 195}