<commit_before><?php

namespace Liip\RD\Tests\Unit\Version;

use Liip\RD\VCS\Git;

class GitTest extends \PHPUnit_Framework_TestCase
{
    protected $testDir;

    protected function setUp()
    {
        // Create a temp folder and extract inside the git test folder
        $tempDir = tempnam(sys_get_temp_dir(),'');
        if (file_exists($tempDir)) {
            unlink($tempDir);
        }
        mkdir($tempDir);
        chdir($tempDir);
        exec('unzip '.__DIR__.'/gitRepo.zip');
        exec('git checkout .');
        $this->testDir = $tempDir;
    }

    public function testGetAllModificationsSince()
    {
        $vcs = new Git();
        $modifs = $vcs->getAllModificationsSince('1.1.0');
        $this->assertContains("Add a third file", $modifs[0]);
        $this->assertContains("Modification of the first file", $modifs[1]);
    }

    public function testGetLocalModifications()
    {
        $vcs = new Git();
        exec('touch foo');
        $modifs = $vcs->getLocalModifications();
        $this->assertContains('foo', implode($modifs));
    }

    public function testGetTags()
    {
        $vcs = new Git();
        $this->assertEquals(array("1.0.0","1.1.0"), $vcs->getTags());
    }

    public function testCreateTag()
    {
        $vcs = new Git();
        $vcs->createTag('2.0.0');
        $this->assertEquals(array("1.0.0","1.1.0","2.0.0"), $vcs->getTags());
    }

    public function testSaveWorkingCopy()
    {
        $vcs = new Git();
        $vcs->createTag('2.0.0');
        $this->assertEquals(array(), $vcs->getAllModificationsSince('2.0.0'));
        exec('rm file2');
        $vcs->saveWorkingCopy('Remove the second file');
        $this->assertCount(1,$vcs->getAllModificationsSince('2.0.0'));
    }

    public function testGetCurrentBranch()
    {
        $vcs = new Git();
        $this->assertEquals('master', $vcs->getCurrentBranch());
        exec("git co -b foo");
        $this->assertEquals('foo', $vcs->getCurrentBranch());
        exec("git co master");
        $this->assertEquals('master', $vcs->getCurrentBranch());
    }

    /**
     * @expectedException \Liip\RD\Exception
     * @expectedExceptionMessage Not currently on any branch
     */

    public function testGetCurrentBranchWhenNotInBranch()
    {
        $vcs = new Git();
        exec("git co 9aca70b");
        $vcs->getCurrentBranch();
    }


    protected function tearDown()
    {
        // Remove the test folder
        exec('rm -rf '.$this->testDir);
        chdir(__DIR__);
    }


}<commit_msg>Fixing git test and test output clean up<commit_after><?php

namespace Liip\RD\Tests\Unit\Version;

use Liip\RD\VCS\Git;

class GitTest extends \PHPUnit_Framework_TestCase
{
    protected $testDir;

    protected function setUp()
    {
        // Create a temp folder and extract inside the git test folder
        $tempDir = tempnam(sys_get_temp_dir(),'');
        if (file_exists($tempDir)) {
            unlink($tempDir);
        }
        mkdir($tempDir);
        chdir($tempDir);
        exec('unzip '.__DIR__.'/gitRepo.zip');
        exec('git checkout .');
        $this->testDir = $tempDir;
    }

    public function testGetAllModificationsSince()
    {
        $vcs = new Git();
        $modifs = $vcs->getAllModificationsSince('1.1.0');
        $this->assertContains("Add a third file", $modifs[0]);
        $this->assertContains("Modification of the first file", $modifs[1]);
    }

    public function testGetLocalModifications()
    {
        $vcs = new Git();
        exec('touch foo');
        $modifs = $vcs->getLocalModifications();
        $this->assertContains('foo', implode($modifs));
    }

    public function testGetTags()
    {
        $vcs = new Git();
        $this->assertEquals(array("1.0.0","1.1.0"), $vcs->getTags());
    }

    public function testCreateTag()
    {
        $vcs = new Git();
        $vcs->createTag('2.0.0');
        $this->assertEquals(array("1.0.0","1.1.0","2.0.0"), $vcs->getTags());
    }

    public function testSaveWorkingCopy()
    {
        $vcs = new Git();
        $vcs->createTag('2.0.0');
        $this->assertEquals(array(), $vcs->getAllModificationsSince('2.0.0'));
        exec('rm file2');
        $vcs->saveWorkingCopy('Remove the second file');
        $this->assertCount(1,$vcs->getAllModificationsSince('2.0.0'));
    }

    public function testGetCurrentBranch()
    {
        $vcs = new Git();
        $this->assertEquals('master', $vcs->getCurrentBranch());
        system("git checkout -b foo &> /dev/null");
        $this->assertEquals('foo', $vcs->getCurrentBranch());
        exec("git checkout master &> /dev/null");
        $this->assertEquals('master', $vcs->getCurrentBranch());
    }

    /**
     * @expectedException \Liip\RD\Exception
     * @expectedExceptionMessage Not currently on any branch
     */

    public function testGetCurrentBranchWhenNotInBranch()
    {
        $vcs = new Git();
        exec("git checkout 9aca70b &> /dev/null");
        $vcs->getCurrentBranch();
    }


    protected function tearDown()
    {
        // Remove the test folder
        exec('rm -rf '.$this->testDir);
        chdir(__DIR__);
    }


}
{'fraction_non_alphanumeric': 0.16291698991466252, 'fraction_numerical': 0.014352211016291699, 'mean_word_length': 2.447192513368984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '1774182', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1609, 'n_words': 310}