<commit_before><?php

namespace rockunit\filemanager;


use League\Flysystem\Adapter\Local;
use League\Flysystem\Cache\Adapter;
use League\Flysystem\Cache\Memcached;
use rock\cache\filemanager\FileManager;

class FileManagerTest extends \PHPUnit_Framework_TestCase
{
    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();
        static::clearRuntime();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testHasSuccess(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->write('test/bar.tmp', 'bar'));
        $this->assertTrue($fileManager->has('test/bar.tmp', FileManager::TYPE_FILE));
        $this->assertTrue($fileManager->has('test', FileManager::TYPE_DIR));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testHasFail(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->write('test/bar.tmp', 'bar'));
        $this->assertFalse($fileManager->has('test/bar.tmp', FileManager::TYPE_DIR));
        $this->assertFalse($fileManager->has('test', FileManager::TYPE_FILE));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testWriteSuccess(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->has('foo.tmp'));
        $this->assertTrue($fileManager->delete('foo.tmp'));
        $this->assertFalse($fileManager->has('foo.tmp'));
        $this->assertTrue($fileManager->write('0', 'hh'));
        $this->assertTrue($fileManager->has('0'));
        $this->assertTrue($fileManager->delete('0'));
        $this->assertFalse($fileManager->has('0'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testWriteFail(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertFalse($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->delete('foo.tmp'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testWriteStream(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->writeStream('bar.tmp', $fileManager->readStream('foo.tmp')));
        $this->assertTrue($fileManager->has('foo.tmp'));
        $this->assertTrue($fileManager->has('bar.tmp'));
        $this->assertTrue($fileManager->writeStream('0', $fileManager->readStream('foo.tmp')));
        $this->assertTrue($fileManager->has('foo.tmp'));
        $this->assertTrue($fileManager->has('0'));

        // repeat write fail
        $this->assertFalse($fileManager->writeStream('0', $fileManager->readStream('foo.tmp')));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testPut(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->put('foo.tmp', 'foo'));
        $this->assertSame($fileManager->read('foo.tmp'), 'foo');
        $this->assertTrue($fileManager->put('foo.tmp', 'test'));
        $this->assertSame($fileManager->read('foo.tmp'), 'test');
        $this->assertTrue($fileManager->delete('foo.tmp'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testUpdateStream(FileManager $fileManager)
    {
        $fileManager->deleteAll();
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->write('bar.tmp', ''));<commit_msg>fixed tests<commit_after><?php

namespace rockunit\filemanager;


use League\Flysystem\Adapter\Local;
use League\Flysystem\Cache\Adapter;
use League\Flysystem\Cache\Memcached;
use rock\cache\filemanager\FileManager;

class FileManagerTest extends \PHPUnit_Framework_TestCase
{
    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();
        static::clearRuntime();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testHasSuccess(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->write('test/bar.tmp', 'bar'));
        $this->assertTrue($fileManager->has('test/bar.tmp', FileManager::TYPE_FILE));
        $this->assertTrue($fileManager->has('test', FileManager::TYPE_DIR));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testHasFail(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->write('test/bar.tmp', 'bar'));
        $this->assertFalse($fileManager->has('test/bar.tmp', FileManager::TYPE_DIR));
        $this->assertFalse($fileManager->has('test', FileManager::TYPE_FILE));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testWriteSuccess(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->has('foo.tmp'));
        $this->assertTrue($fileManager->delete('foo.tmp'));
        $this->assertFalse($fileManager->has('foo.tmp'));
        $this->assertTrue($fileManager->write('0', 'hh'));
        $this->assertTrue($fileManager->has('0'));
        $this->assertTrue($fileManager->delete('0'));
        $this->assertFalse($fileManager->has('0'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testWriteFail(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertFalse($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->delete('foo.tmp'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testWriteStream(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->write('test.tmp', 'foo'));
        $this->assertTrue($fileManager->writeStream('baz.tmp', $fileManager->readStream('test.tmp')));
        $this->assertTrue($fileManager->has('test.tmp'));
        $this->assertTrue($fileManager->has('baz.tmp'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testPut(FileManager $fileManager)
    {
        $this->assertTrue($fileManager->put('foo.tmp', 'foo'));
        $this->assertSame($fileManager->read('foo.tmp'), 'foo');
        $this->assertTrue($fileManager->put('foo.tmp', 'test'));
        $this->assertSame($fileManager->read('foo.tmp'), 'test');
        $this->assertTrue($fileManager->delete('foo.tmp'));
        $fileManager->deleteAll();
    }

    /**
     * @dataProvider providerFileManager
     */
    public function testUpdateStream(FileManager $fileManager)
    {
        $fileManager->deleteAll();
        $this->assertTrue($fileManager->write('foo.tmp', 'foo'));
        $this->assertTrue($fileManager->write('bar.tmp', ''));
{'fraction_non_alphanumeric': 0.18485012152308938, 'fraction_numerical': 0.0014852822036186875, 'mean_word_length': 3.472826086956522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 149, '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': '2256089', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2113, 'n_words': 248}