<commit_before><?php
namespace Metaphore\Tests;

use Metaphore\Cache;
use Metaphore\Store\MockStore;

class CacheTest extends \PHPUnit_Framework_TestCase
{
    /*** @var \Metaphore\Cacche */
    protected $cache;

    public function setUp()
    {
        $this->cache = new Cache(new MockStore());
    }

    public function testCachesValue()
    {
        $key = "gago5";
        $result = "<NAME> plays as a defensive midfielder for Boca Juniors and the Argentine national team.";

        $actual_result = $this->cache->cache($key, $this->createFunc($result), 30);

        $this->assertSame($actual_result, $result);
        $this->assertSame($this->cache->get($key), $result);
    }

    public function testServesStaleValueIfOtherProcessIsGeneratingContent()
    {
        $key = "masche14";
        $result_new = "<NAME> plays for FC Barcelona in La Liga and the Argentina national team, as a central defender or defensive midfielder.";
        $result_stale = "<NAME>";

        $ret_val = $this->cache->cache($key, $this->createFunc($result_stale), -1);

        $this->assertSame($ret_val, $result_stale);

        // simulate lock (other process generating content)
        $this->cache->getLockManager()->acquire($key, 30);

        // try to cache new (but stale value should be returned as lock is acquired earlier)
        $ret_val = $this->cache->cache($key, $this->createFunc($result_new), -1);

        $this->assertSame($ret_val, $result_stale);

        // release lock and try to cache new value again
        $this->cache->getLockManager()->release($key);

        $ret_val = $this->cache->cache($key, $this->createFunc($result_new), -1);

        $this->assertSame($ret_val, $result_new);
    }

    protected function createFunc($result)
    {
        return function() use ($result) { return $result; };
    }
}
<commit_msg>CacheTest: cosmetic formatting changes<commit_after><?php
namespace Metaphore\Tests;

use Metaphore\Cache;
use Metaphore\Store\MockStore;

class CacheTest extends \PHPUnit_Framework_TestCase
{
    /*** @var \Metaphore\Cacche */
    protected $cache;

    public function setUp()
    {
        $this->cache = new Cache(new MockStore());
    }

    public function testCachesValue()
    {
        $key = "gago5";
        $result = "<NAME> plays as a defensive midfielder for Boca Juniors and the Argentine team.";

        $actualResult = $this->cache->cache($key, $this->createFunc($result), 30);

        $this->assertSame($actualResult, $result);
        $this->assertSame($this->cache->get($key), $result);
    }

    public function testServesStaleValueIfOtherProcessIsGeneratingContent()
    {
        $key = "masche14";
        $resultNew = "<NAME> plays for FC Barcelona in La Liga and the Argentina national team.";
        $resultStale = "<NAME>";

        $retVal = $this->cache->cache($key, $this->createFunc($resultStale), -1);

        $this->assertSame($retVal, $resultStale);

        // simulate lock (other process generating content)
        $this->cache->getLockManager()->acquire($key, 30);

        // try to cache new (but stale value should be returned as lock is acquired earlier)
        $ret_val = $this->cache->cache($key, $this->createFunc($resultNew), -1);

        $this->assertSame($retVal, $resultStale);

        // release lock and try to cache new value again
        $this->cache->getLockManager()->release($key);

        $retVal = $this->cache->cache($key, $this->createFunc($resultNew), -1);

        $this->assertSame($retVal, $resultNew);
    }

    protected function createFunc($result)
    {
        return (function () use ($result) {
            return $result;
        });
    }
}

{'fraction_non_alphanumeric': 0.14413924394887137, 'fraction_numerical': 0.005439216752787599, 'mean_word_length': 3.002176278563656, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 61, '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': '6166028', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1060, 'n_words': 271}