<commit_before><?php

namespace Doctrine\Tests\Common\Cache;

use Doctrine\Common\Cache\Cache;
use ArrayObject;

abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase
{
    /**
     * @dataProvider provideDataToCache
     */
    public function testSetContainsFetchDelete($value)
    {
        $cache = $this->_getCacheDriver();

        // Test saving a value, checking if it exists, and fetching it back
        $this->assertTrue($cache->save('key', $value));
        $this->assertTrue($cache->contains('key'));
        if (is_object($value)) {
            $this->assertEquals($value, $cache->fetch('key'), 'Objects retrieved from the cache must be equal but not necessarily the same reference');
        } else {
            $this->assertSame($value, $cache->fetch('key'), 'Scalar and array data retrieved from the cache must be the same as the original, e.g. same type');
        }

        // Test deleting a value
        $this->assertTrue($cache->delete('key'));
        $this->assertFalse($cache->contains('key'));
        $this->assertFalse($cache->fetch('key'));
    }

    /**
     * @dataProvider provideDataToCache
     */
    public function testUpdateExistingEntry($value)
    {
        $cache = $this->_getCacheDriver();

        $this->assertTrue($cache->save('key', 'old-value'));
        $this->assertTrue($cache->contains('key'));

        $this->assertTrue($cache->save('key', $value));
        $this->assertTrue($cache->contains('key'));
        if (is_object($value)) {
            $this->assertEquals($value, $cache->fetch('key'), 'Objects retrieved from the cache must be equal but not necessarily the same reference');
        } else {
            $this->assertSame($value, $cache->fetch('key'), 'Scalar and array data retrieved from the cache must be the same as the original, e.g. same type');
        }
    }

    public function testCacheKeyIsCaseSensitive()
    {
        $cache = $this->_getCacheDriver();

        $this->assertTrue($cache->save('key', 'value'));
        $this->assertTrue($cache->contains('key'));
        $this->assertSame('value', $cache->fetch('key'));

        $this->assertFalse($cache->contains('KEY'));
        $this->assertFalse($cache->fetch('KEY'));

        $cache->delete('KEY');
        $this->assertTrue($cache->contains('key', 'Deleting cache item with different case must not affect other cache item'));
    }

    public function testFetchMultiple()
    {
        $cache  = $this->_getCacheDriver();
        $values = $this->provideDataToCache();
        $saved  = [];

        foreach ($values as $key => $value) {
            $cache->save($key, $value[0]);

            $saved[$key] = $value[0];
        }

        $keys = array_keys($saved);

        $this->assertEquals(
            $saved,<commit_msg>Correcting short array syntax (incompatible with 5.3.x<commit_after><?php

namespace Doctrine\Tests\Common\Cache;

use Doctrine\Common\Cache\Cache;
use ArrayObject;

abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase
{
    /**
     * @dataProvider provideDataToCache
     */
    public function testSetContainsFetchDelete($value)
    {
        $cache = $this->_getCacheDriver();

        // Test saving a value, checking if it exists, and fetching it back
        $this->assertTrue($cache->save('key', $value));
        $this->assertTrue($cache->contains('key'));
        if (is_object($value)) {
            $this->assertEquals($value, $cache->fetch('key'), 'Objects retrieved from the cache must be equal but not necessarily the same reference');
        } else {
            $this->assertSame($value, $cache->fetch('key'), 'Scalar and array data retrieved from the cache must be the same as the original, e.g. same type');
        }

        // Test deleting a value
        $this->assertTrue($cache->delete('key'));
        $this->assertFalse($cache->contains('key'));
        $this->assertFalse($cache->fetch('key'));
    }

    /**
     * @dataProvider provideDataToCache
     */
    public function testUpdateExistingEntry($value)
    {
        $cache = $this->_getCacheDriver();

        $this->assertTrue($cache->save('key', 'old-value'));
        $this->assertTrue($cache->contains('key'));

        $this->assertTrue($cache->save('key', $value));
        $this->assertTrue($cache->contains('key'));
        if (is_object($value)) {
            $this->assertEquals($value, $cache->fetch('key'), 'Objects retrieved from the cache must be equal but not necessarily the same reference');
        } else {
            $this->assertSame($value, $cache->fetch('key'), 'Scalar and array data retrieved from the cache must be the same as the original, e.g. same type');
        }
    }

    public function testCacheKeyIsCaseSensitive()
    {
        $cache = $this->_getCacheDriver();

        $this->assertTrue($cache->save('key', 'value'));
        $this->assertTrue($cache->contains('key'));
        $this->assertSame('value', $cache->fetch('key'));

        $this->assertFalse($cache->contains('KEY'));
        $this->assertFalse($cache->fetch('KEY'));

        $cache->delete('KEY');
        $this->assertTrue($cache->contains('key', 'Deleting cache item with different case must not affect other cache item'));
    }

    public function testFetchMultiple()
    {
        $cache  = $this->_getCacheDriver();
        $values = $this->provideDataToCache();
        $saved  = array();

        foreach ($values as $key => $value) {
            $cache->save($key, $value[0]);

            $saved[$key] = $value[0];
        }

        $keys = array_keys($saved);

        $this->assertEquals(
            $saved,
{'fraction_non_alphanumeric': 0.1632834757834758, 'fraction_numerical': 0.0010683760683760685, 'mean_word_length': 2.828902522154056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, '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': '127191', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1514, 'n_words': 364}