<commit_before><?php

/*
* This file is part of the ACache library.
*
* (c) <NAME> <<EMAIL>>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ACache\Tests;

use ACache\Cache;
use ACache\ArrayCache;
use ACache\ApcCache;
use ACache\FilesystemCache;
use ACache\NamespaceCache;

/**
 * NamespaceCache tests
 *
 * @author <NAME> <<EMAIL>>
 */
class NamespaceCacheTest extends \PHPUnit_Framework_TestCase
{

    /**
     * Test namespace.
     */
    public function testNamespace()
    {
        // regular
        $this->doTestNamespace(new ArrayCache());
        $this->doTestNamespace(new ApcCache());
        $this->doTestNamespace(new FilesystemCache(__DIR__.'/cache/1'));

        // nested
        $this->doTestNamespace(new NamespaceCache(new ArrayCache(), 'super'));
        $this->doTestNamespace(new NamespaceCache(new ApcCache(), 'super'));
        $this->doTestNamespace(new NamespaceCache(new FilesystemCache(__DIR__.'/cache/2'), 'super'));
    }

    /**
     * Do namespace tests.
     */
    protected function doTestNamespace(Cache $decoratedCache)
    {
        $cache = new NamespaceCache($decoratedCache, 'foo');
        $this->assertFalse($cache->contains('yin'));
        $this->assertNull($cache->fetch('yin'));

        $this->assertTrue($cache->save('yin', 'yang'));
        $this->assertTrue($cache->contains('yin'));
        $this->assertEquals('yang', $cache->fetch('yin'));
        // check decorated cache to make sure there is a namespace in the name...
        $this->assertFalse($decoratedCache->contains('yin'));

        $this->assertTrue($cache->delete('yin'));
        $this->assertFalse($cache->contains('yin'));
        $this->assertNull($cache->fetch('yin'));

        $stats = $decoratedCache->getStats();
        $this->assertEquals(0, $stats[Cache::STATS_SIZE]);

        $this->assertTrue($cache->save('foo', 'bar'));
        $stats = $decoratedCache->getStats();
        $this->assertEquals(1, $stats[Cache::STATS_SIZE]);

        $cache->flush();
        $stats = $decoratedCache->getStats();
        $this->assertFalse($cache->contains('foo'));
        $this->assertEquals(0, $stats[Cache::STATS_SIZE]);
    }

    /**
     * Test empty namespace.
     */
    public function testEmptyNamespace()
    {
        // regular
        $this->doTestEmptyNamespace(new ArrayCache());
        $this->doTestEmptyNamespace(new ApcCache());
        $this->doTestEmptyNamespace(new FilesystemCache(__DIR__.'/cache/3'));

        // nested
        $this->doTestEmptyNamespace(new NamespaceCache(new ArrayCache(), 'super'));
        $this->doTestEmptyNamespace(new NamespaceCache(new ApcCache(), 'super'));
        $this->doTestEmptyNamespace(new NamespaceCache(new FilesystemCache(__DIR__.'/cache/4'), 'super'));
    }

    /**
     * Do empty namespace tests.
     */
    protected function doTestEmptyNamespace(Cache $decoratedCache)
    {
        $cache = new NamespaceCache($decoratedCache);
        $this->assertFalse($cache->contains('yin'));
        $this->assertNull($cache->fetch('yin'));

        $this->assertTrue($cache->save('yin', 'yang'));
        $this->assertTrue($cache->contains('yin'));
        $this->assertEquals('yang', $cache->fetch('yin'));
        // check decorated cache as that should be the same
        $this->assertTrue($decoratedCache->contains('yin'));

        $cache->flush();
        $stats = $decoratedCache->getStats();
        $this->assertFalse($cache->contains('foo'));<commit_msg>flush decorated cache before testing<commit_after><?php

/*
* This file is part of the ACache library.
*
* (c) <NAME> <<EMAIL>>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ACache\Tests;

use ACache\Cache;
use ACache\ArrayCache;
use ACache\ApcCache;
use ACache\FilesystemCache;
use ACache\NamespaceCache;

/**
 * NamespaceCache tests
 *
 * @author <NAME> <<EMAIL>>
 */
class NamespaceCacheTest extends \PHPUnit_Framework_TestCase
{

    /**
     * Test namespace.
     */
    public function testNamespace()
    {
        // regular
        $this->doTestNamespace(new ArrayCache());
        $this->doTestNamespace(new ApcCache());
        $this->doTestNamespace(new FilesystemCache(__DIR__.'/cache/1'));

        // nested
        $this->doTestNamespace(new NamespaceCache(new ArrayCache(), 'super'));
        $this->doTestNamespace(new NamespaceCache(new ApcCache(), 'super'));
        $this->doTestNamespace(new NamespaceCache(new FilesystemCache(__DIR__.'/cache/2'), 'super'));
    }

    /**
     * Do namespace tests.
     */
    protected function doTestNamespace(Cache $decoratedCache)
    {
        // ensure we are clean
        $decoratedCache->flush();
        $cache = new NamespaceCache($decoratedCache, 'foo');

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

        $this->assertTrue($cache->save('yin', 'yang'));
        $this->assertTrue($cache->contains('yin'));
        $this->assertEquals('yang', $cache->fetch('yin'));
        // check decorated cache to make sure there is a namespace in the name...
        $this->assertFalse($decoratedCache->contains('yin'));

        $this->assertTrue($cache->delete('yin'));
        $this->assertFalse($cache->contains('yin'));
        $this->assertNull($cache->fetch('yin'));

        $stats = $decoratedCache->getStats();
        $this->assertEquals(0, $stats[Cache::STATS_SIZE]);

        $this->assertTrue($cache->save('foo', 'bar'));
        $stats = $decoratedCache->getStats();
        $this->assertEquals(1, $stats[Cache::STATS_SIZE]);

        $cache->flush();
        $stats = $decoratedCache->getStats();
        $this->assertFalse($cache->contains('foo'));
        $this->assertEquals(0, $stats[Cache::STATS_SIZE]);
    }

    /**
     * Test empty namespace.
     */
    public function testEmptyNamespace()
    {
        // regular
        $this->doTestEmptyNamespace(new ArrayCache());
        $this->doTestEmptyNamespace(new ApcCache());
        $this->doTestEmptyNamespace(new FilesystemCache(__DIR__.'/cache/3'));

        // nested
        $this->doTestEmptyNamespace(new NamespaceCache(new ArrayCache(), 'super'));
        $this->doTestEmptyNamespace(new NamespaceCache(new ApcCache(), 'super'));
        $this->doTestEmptyNamespace(new NamespaceCache(new FilesystemCache(__DIR__.'/cache/4'), 'super'));
    }

    /**
     * Do empty namespace tests.
     */
    protected function doTestEmptyNamespace(Cache $decoratedCache)
    {
        // ensure we are clean
        $decoratedCache->flush();
        $cache = new NamespaceCache($decoratedCache);

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

        $this->assertTrue($cache->save('yin', 'yang'));
        $this->assertTrue($cache->contains('yin'));
        $this->assertEquals('yang', $cache->fetch('yin'));
        // check decorated cache as that should be the same
        $this->assertTrue($decoratedCache->contains('yin'));

        $cache->flush();
        $stats = $decoratedCache->getStats();
        $this->assertFalse($cache->contains('foo'));
{'fraction_non_alphanumeric': 0.16922015182884748, 'fraction_numerical': 0.001932367149758454, 'mean_word_length': 3.190861769809138, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 131, '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': '5819378', 'n_tokens_mistral': 2073, 'n_tokens_neox': 2052, 'n_words': 385}