<commit_before><?php
/**
 * ProjectVersion.php
 * @author: <EMAIL>
 */

namespace Tests;

class ProjectVersionMock extends \FMUP\ProjectVersion
{
    public function __construct()
    {

    }
}

class ProjectVersionTest extends \PHPUnit_Framework_TestCase
{
    public function testGetInstance()
    {
        $reflector = new \ReflectionClass('\FMUP\ProjectVersion');
        $method = $reflector->getMethod('__construct');
        $this->assertTrue($method->isPrivate(), 'Construct must be private');
        try {
            $reflector->getMethod('__clone')->invoke(\FMUP\ProjectVersion::getInstance());
            $this->fail('Clone must fail');
        } catch (\ReflectionException $e) {
            $this->assertEquals(
                'Trying to invoke private method FMUP\ProjectVersion::__clone() from scope ReflectionMethod',
                $e->getMessage()
            );
        }

        $version = \FMUP\ProjectVersion::getInstance();
        $this->assertInstanceOf('\FMUP\ProjectVersion', $version);
        $version2 = \FMUP\ProjectVersion::getInstance();
        $this->assertSame($version, $version2);
        return $version;
    }

    public function testGetWhenFileDontExists()
    {
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(array('getComposerPath'))->getMock();
        $projectVersion->method('getComposerPath')->willReturn('nonexistent_file');

        $reflection = new \ReflectionProperty('\FMUP\ProjectVersion', 'instance');
        $reflection->setAccessible(true);
        $reflection->setValue($projectVersion);

        $this->setExpectedException('\LogicException', "composer.json does not exist");
        $projectVersion->get();
    }

    public function testGetWhenStructureIsBad()
    {
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(array('getComposerPath'))->getMock();
        $projectVersion->method('getComposerPath')->willReturn(__FILE__);

        $reflection = new \ReflectionProperty('\FMUP\ProjectVersion', 'instance');
        $reflection->setAccessible(true);
        $reflection->setValue($projectVersion);

        $this->setExpectedException('\LogicException', 'composer.json invalid structure');
        /** @var $projectVersion \FMUP\ProjectVersion */
        $projectVersion->get();
    }

    public function testGetAndName()
    {
        $filePath = __DIR__ . DIRECTORY_SEPARATOR . '.files' . DIRECTORY_SEPARATOR . 'composer.json';
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $version = uniqid();
        $data = <<<COMPOSER
{
    "name":"ProjectTest$version",
    "version":"$version"
}
COMPOSER;
        file_put_contents($filePath, $data);
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(array('getComposerPath'))->getMock();
        $projectVersion->method('getComposerPath')->willReturn($filePath);

        $reflection = new \ReflectionProperty('\FMUP\ProjectVersion', 'instance');
        $reflection->setAccessible(true);
        $reflection->setValue($projectVersion);

        /** @var $projectVersion \FMUP\ProjectVersion */
        $this->assertSame('ProjectTest' . $version, $projectVersion->name());
        $this->assertSame($version, $projectVersion->get());
        unlink($filePath);
    }

    public function testGetComposerPath()
    {
        $method = new \ReflectionMethod('\Tests\ProjectVersionMock', 'getComposerPath');
        $method->setAccessible(true);
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(null)->getMock();

        /** @var $projectVersion \FMUP\ProjectVersion */
        $this->assertRegExp(
            '#/lib/\.\./\.\./\.\./\.\./composer\.json$#',
            $method->invoke($projectVersion)
        );
    }
}
<commit_msg>add missing unit test<commit_after><?php
/**
 * ProjectVersion.php
 * @author: <EMAIL>
 */

namespace Tests;

class ProjectVersionMock extends \FMUP\ProjectVersion
{
    public function __construct()
    {

    }
}

class ProjectVersionTest extends \PHPUnit_Framework_TestCase
{
    public function testGetInstance()
    {
        $reflector = new \ReflectionClass('\FMUP\ProjectVersion');
        $method = $reflector->getMethod('__construct');
        $this->assertTrue($method->isPrivate(), 'Construct must be private');
        try {
            $reflector->getMethod('__clone')->invoke(\FMUP\ProjectVersion::getInstance());
            $this->fail('Clone must fail');
        } catch (\ReflectionException $e) {
            $this->assertEquals(
                'Trying to invoke private method FMUP\ProjectVersion::__clone() from scope ReflectionMethod',
                $e->getMessage()
            );
        }

        $version = \FMUP\ProjectVersion::getInstance();
        $this->assertInstanceOf('\FMUP\ProjectVersion', $version);
        $version2 = \FMUP\ProjectVersion::getInstance();
        $this->assertSame($version, $version2);
        return $version;
    }

    public function testGetWhenFileDontExists()
    {
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(array('getComposerPath'))->getMock();
        $projectVersion->method('getComposerPath')->willReturn('nonexistent_file');

        $reflection = new \ReflectionProperty('\FMUP\ProjectVersion', 'instance');
        $reflection->setAccessible(true);
        $reflection->setValue($projectVersion);

        $this->setExpectedException('\LogicException', "composer.json does not exist");
        $projectVersion->get();
    }

    public function testGetWhenStructureIsBad()
    {
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(array('getComposerPath'))->getMock();
        $projectVersion->method('getComposerPath')->willReturn(__FILE__);

        $reflection = new \ReflectionProperty('\FMUP\ProjectVersion', 'instance');
        $reflection->setAccessible(true);
        $reflection->setValue($projectVersion);

        $this->setExpectedException('\LogicException', 'composer.json invalid structure');
        /** @var $projectVersion \FMUP\ProjectVersion */
        $projectVersion->get();
    }

    public function testComposerPath()
    {
        $reflection = new \ReflectionMethod('\FMUP\ProjectVersion', 'getComposerPath');
        $reflection->setAccessible(true);

        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(null)->getMock();
        $this->assertRegExp('~/../../../../composer.json$~', $reflection->invoke($projectVersion));
    }

    public function testGetAndName()
    {
        $filePath = __DIR__ . DIRECTORY_SEPARATOR . '.files' . DIRECTORY_SEPARATOR . 'composer.json';
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $version = uniqid();
        $data = <<<COMPOSER
{
    "name":"ProjectTest$version",
    "version":"$version"
}
COMPOSER;
        file_put_contents($filePath, $data);
        $projectVersion = $this->getMockBuilder('\Tests\ProjectVersionMock')->setMethods(array('getComposerPath'))->getMock();
        $projectVersion->method('getComposerPath')->willReturn($filePath);

        $reflection = new \ReflectionProperty('\FMUP\ProjectVersion', 'instance');
        $reflection->setAccessible(true);
        $reflection->setValue($projectVersion);

        /** @var $projectVersion \FMUP\ProjectVersion */
        $this->assertSame('ProjectTest' . $version, $projectVersion->name());
        $this->assertSame($version, $projectVersion->get());
        unlink($filePath);
    }
}

{'fraction_non_alphanumeric': 0.15541250656857594, 'fraction_numerical': 0.0005254860746190226, 'mean_word_length': 3.2224070992789793, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 95, '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': '6685617', 'n_tokens_mistral': 2067, 'n_tokens_neox': 2072, 'n_words': 303}