<commit_before><?php

namespace PHPExiftool;

class ReaderTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var Reader
     */
    protected $object;
    protected static $tmpDir;

    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();

        $tmpDir = sys_get_temp_dir();

        self::$tmpDir = $tmpDir . '/exiftool_reader';

        if ( ! is_dir(self::$tmpDir)) {
            mkdir(self::$tmpDir);
        }

        file_put_contents(self::$tmpDir . '/hello.world', 'Hello');
        file_put_contents(self::$tmpDir . '/hello.exiftool', 'Hello');

        if ( ! is_dir(self::$tmpDir . '/dir')) {
            mkdir(self::$tmpDir . '/dir');
        }
        if ( ! is_dir(self::$tmpDir . '/usr')) {
            mkdir(self::$tmpDir . '/usr');
        }

        $tmpDir2 = $tmpDir . '/exiftool_reader2';

        if ( ! is_dir($tmpDir2)) {
            mkdir($tmpDir2);
        }

        file_put_contents($tmpDir2 . '/hello2.world', 'Hello');

        if ( ! is_link(self::$tmpDir . '/symlink')) {
            symlink($tmpDir2, self::$tmpDir . '/symlink');
        }

        file_put_contents(self::$tmpDir . '/dir/newfile.txt', 'Hello');

        $tmpDir3 = $tmpDir . '/exiftool_reader3';

        if ( ! is_dir($tmpDir3)) {
            mkdir($tmpDir3);
        }

        if ( ! is_dir($tmpDir3 . '/.svn')) {
            mkdir($tmpDir3 . '/.svn');
        }

        if ( ! is_dir($tmpDir3 . '/.roro')) {
            mkdir($tmpDir3 . '/.roro');
        }

        if ( ! is_dir($tmpDir3 . '/.git')) {
            mkdir($tmpDir3 . '/.git');
        }

        touch($tmpDir3 . '/.git/config');
        touch($tmpDir3 . '/.roro/.roro.tmp');
        touch($tmpDir3 . '/.phrasea.xml');
    }

    /**
     * @covers PHPExiftool\Reader::__construct
     */
    protected function setUp()
    {
        $this->object = new Reader();
    }

    /**
     * @covers PHPExiftool\Reader::getIterator
     */
    public function testGetIterator()
    {
        $file = self::$tmpDir . '/hello.exiftool';
        $this->assertInstanceOf('\\Iterator', $this->object->files($file)->getIterator());
    }

    /**
     * @covers PHPExiftool\Reader::getIterator
     */
    public function testAppend()
    {
        $file1 = self::$tmpDir . '/hello.exiftool';
        $file2 = self::$tmpDir . '/hello.world';
        $file3 = self::$tmpDir . '/dir/newfile.txt';
        $this->assertEquals(1, count($this->object->files($file1)->all()));

        $reader = new Reader();
        $reader->files(array($file2, $file3));
        $this->assertEquals(3, count($this->object->append($reader)->all()));
    }

    /**
     * @covers PHPExiftool\Reader::files
     * @covers PHPExiftool\Reader::buildQuery
     */
    public function testFiles()
    {
        $file = self::$tmpDir . '/hello.exiftool';
        $this->object->files($file);

        $splfile = $this->object->files(self::$tmpDir . '/hello.exiftool')->first()->getFile();

        $this->assertEquals(realpath($file), $splfile->getPathname());
    }

    public function testIgnoreVCS()
    {
        $this->object->in(self::$tmpDir . '3');
        $this->assertEquals(1, count($this->object->all()));
    }

    public function testIgnoreDotFiles()
    {
        $this->object->in(self::$tmpDir . '3');
        $this->assertEquals(1, count($this->object->all()));

        $this->object->ignoreDotFiles()->in(self::$tmpDir . '3');
        $this->assertEquals(0, count($this->object->all()));
    }

    /**
     * @covers PHPExiftool\Reader::in
     * @covers PHPExiftool\Reader::buildQuery
     */
    public function testIn()
    {
        $reader = new Reader();
        $reader->in(self::$tmpDir);
        $this->assertEquals(3, count($reader->all()));

        $reader = new Reader();
        $reader->in(self::$tmpDir . '/dir');
        $this->assertEquals(1, count($reader->all()));
    }

    /**
     * @covers PHPExiftool\Reader::exclude
     * @covers PHPExiftool\Reader::computeExcludeDirs
     * @covers PHPExiftool\Reader::buildQuery
     */
    public function testExclude()
    {
        $reader = new Reader();
        $reader
            ->in(self::$tmpDir)
            ->exclude(self::$tmpDir . '/dir');

        $this->assertEquals(2, count($reader->all()));
    }

    /**
     * @dataProvider getExclude
     * @covers PHPExiftool\Reader::computeExcludeDirs
     */
    public function testComputeExcludeDirs($dir)
    {
        $reader = new Reader();
        $reader
            ->in(self::$tmpDir)
            ->exclude($dir)
            ->all();
    }<commit_msg>Add tests<commit_after><?php

namespace PHPExiftool;

class ReaderTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var Reader
     */
    protected $object;
    protected static $tmpDir;

    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();

        $tmpDir = sys_get_temp_dir();

        self::$tmpDir = $tmpDir . '/exiftool_reader';

        if ( ! is_dir(self::$tmpDir)) {
            mkdir(self::$tmpDir);
        }

        file_put_contents(self::$tmpDir . '/hello.world', 'Hello');
        file_put_contents(self::$tmpDir . '/hello.exiftool', 'Hello');

        if ( ! is_dir(self::$tmpDir . '/dir')) {
            mkdir(self::$tmpDir . '/dir');
        }
        if ( ! is_dir(self::$tmpDir . '/usr')) {
            mkdir(self::$tmpDir . '/usr');
        }

        $tmpDir2 = $tmpDir . '/exiftool_reader2';

        if ( ! is_dir($tmpDir2)) {
            mkdir($tmpDir2);
        }

        file_put_contents($tmpDir2 . '/hello2.world', 'Hello');

        if ( ! is_link(self::$tmpDir . '/symlink')) {
            symlink($tmpDir2, self::$tmpDir . '/symlink');
        }

        file_put_contents(self::$tmpDir . '/dir/newfile.txt', 'Hello');

        $tmpDir3 = $tmpDir . '/exiftool_reader3';

        if ( ! is_dir($tmpDir3)) {
            mkdir($tmpDir3);
        }

        if ( ! is_dir($tmpDir3 . '/.svn')) {
            mkdir($tmpDir3 . '/.svn');
        }

        if ( ! is_dir($tmpDir3 . '/.roro')) {
            mkdir($tmpDir3 . '/.roro');
        }

        if ( ! is_dir($tmpDir3 . '/.git')) {
            mkdir($tmpDir3 . '/.git');
        }

        touch($tmpDir3 . '/.git/config');
        touch($tmpDir3 . '/.roro/.roro.tmp');
        touch($tmpDir3 . '/.phrasea.xml');
    }

    /**
     * @covers PHPExiftool\Reader::__construct
     */
    protected function setUp()
    {
        $this->object = new Reader();
    }

    /**
     * @covers PHPExiftool\Reader::__destruct
     */
    protected function tearDown()
    {
        $this->object = null;
    }

    /**
     * @covers PHPExiftool\Reader::getIterator
     */
    public function testGetIterator()
    {
        $file = self::$tmpDir . '/hello.exiftool';
        $this->assertInstanceOf('\\Iterator', $this->object->files($file)->getIterator());
    }

    /**
     * @covers PHPExiftool\Reader::append
     * @covers PHPExiftool\Reader::all
     */
    public function testAppend()
    {
        $file1 = self::$tmpDir . '/hello.exiftool';
        $file2 = self::$tmpDir . '/hello.world';
        $file3 = self::$tmpDir . '/dir/newfile.txt';
        $this->assertEquals(1, count($this->object->files($file1)->all()));

        $reader = new Reader();
        $reader->files(array($file2, $file3));
        $this->assertEquals(3, count($this->object->append($reader)->all()));
    }

    /**
     * @covers PHPExiftool\Reader::sort
     * @covers PHPExiftool\Reader::all
     */
    public function testSort()
    {
        $file1 = self::$tmpDir . '/hello.exiftool';
        $file2 = self::$tmpDir . '/hello.world';
        $file3 = self::$tmpDir . '/dir/newfile.txt';

        $reader = new Reader();
        $reader->files(array($file3, $file2, $file1));
        $reader->sort(array('directory', 'filename', 'cigarette'));

        $results = array();

        foreach($reader->all() as $entity)
        {
            $results[] = $entity->getFile()->getFilename();
        }

        $this->assertSame(array('hello.exiftool', 'hello.world', 'newfile.txt'), $results);
    }

    /**
     * @covers PHPExiftool\Reader::files
     * @covers PHPExiftool\Reader::buildQuery
     */
    public function testFiles()
    {
        $file = self::$tmpDir . '/hello.exiftool';
        $this->object->files($file);

        $splfile = $this->object->files(self::$tmpDir . '/hello.exiftool')->first()->getFile();

        $this->assertEquals(realpath($file), $splfile->getPathname());
    }

    /**
     * @covers PHPExiftool\Reader::resetResults
     */
    public function testResetFilters()
    {
        $file = self::$tmpDir . '/hello.exiftool';
        $this->object->files($file)->all();
        $file = self::$tmpDir . '/hello.world';
        $this->object->files($file)->all();

        $this->assertEquals(2, count($this->object->all()));
    }

    /**
     * @covers PHPExiftool\Reader::ignoreDotFiles
     * @covers PHPExiftool\Reader::all
     */
    public function testIgnoreVCS()
    {
        $this->object->in(self::$tmpDir . '3');
        $this->assertEquals(1, count($this->object->all()));
    }

    /**
     * @covers PHPExiftool\Reader::ignoreDotFiles
     * @covers PHPExiftool\Reader::all
     */
    public function testIgnoreDotFiles()
    {
        $this->object->in(self::$tmpDir . '3');
        $this->assertEquals(1, count($this->object->all()));

        $this->object->ignoreDotFiles()->in(self::$tmpDir . '3');
        $this->assertEquals(0, count($this->object->all()));
    }

    /**
     * @covers PHPExiftool\Reader::in
     * @covers PHPExiftool\Reader::buildQuery
     * @covers PHPExiftool\Reader::all
     */
    public function testIn()
    {
        $reader = new Reader();
        $reader->in(self::$tmpDir);
        $this->assertEquals(3, count($reader->all()));

        $reader = new Reader();
        $reader->in(self::$tmpDir . '/dir');
        $this->assertEquals(1, count($reader->all()));
    }

    /**
     * @covers PHPExiftool\Reader::exclude
     * @covers PHPExiftool\Reader::computeExcludeDirs
     * @covers PHPExiftool\Reader::buildQuery
     * @covers PHPExiftool\Reader::all
     */
    public function testExclude()
    {
        $reader = new Reader();
        $reader
            ->in(self::$tmpDir)
            ->exclude(self::$tmpDir . '/dir');

        $this->assertEquals(2, count($reader->all()));
    }

    /**
     * @dataProvider getExclude
     * @covers PHPExiftool\Reader::computeExcludeDirs
     * @covers PHPExiftool\Reader::all
     */
    public function testComputeExcludeDirs($dir)
    {
        $reader = new Reader();
        $reader
            ->in(self::$tmpDir)
            ->exclude($dir)
            ->all();
    }
{'fraction_non_alphanumeric': 0.1878030585602387, 'fraction_numerical': 0.007553151809026482, 'mean_word_length': 2.134132086499123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7470267', 'n_tokens_mistral': 3481, 'n_tokens_neox': 3428, 'n_words': 505}