<commit_before><?php
/**
 * This file is part of the Gerrie package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Gerrie\Tests\Component\Configuration;

use Gerrie\Component\Configuration\ConfigurationFactory;

class ConfigurationFactoryTest extends \PHPUnit_Framework_TestCase
{

    protected function getFixtureConfigFilePath()
    {
        $configFile  = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
        $configFile .= 'Fixture' . DIRECTORY_SEPARATOR . 'DummyConfig.yml';
        $configFile = realpath($configFile);

        return $configFile;
    }

    /**
     * @expectedException     \RuntimeException
     * @expectedExceptionCode 1415381521
     */
    public function testGetConfigurationByConfigFileWithInvalidConfigFile()
    {
        ConfigurationFactory::getConfigurationByConfigFile('./doesNotExists.yml');
    }

    public function testGetConfigurationByConfigFileWithValidConfigFile()
    {
        $configFile = $this->getFixtureConfigFilePath();
        $configuration = ConfigurationFactory::getConfigurationByConfigFile($configFile);

        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
        $this->assertEquals('root', $configuration->getConfigurationValue('Database.Username'));
    }

    public function testGetConfigurationByConfigFileAndCommandOptionsAndArguments()
    {
        $mockedMethods = ['isOptionSet', 'getOption', 'getArgument'];
        $argvInputExtended = $this->getMock('Gerrie\Component\Console\ArgvInputExtended', $mockedMethods);
        $argvInputExtended->expects($this->any())
                          ->method('isOptionSet')
                          ->withConsecutive(
                              array($this->equalTo('config-file')),
                              array($this->equalTo('database-host')),
                              array($this->equalTo('database-user')),
                              array($this->equalTo('database-pass')),
                              array($this->equalTo('database-port')),
                              array($this->equalTo('database-name'))
                          )
                          ->willReturnOnConsecutiveCalls(
                              $this->returnValue(true),
                              $this->returnValue(true),
                              $this->returnValue(true),
                              $this->returnValue(false),
                              $this->returnValue(true),
                              $this->returnValue(false)
                          );

        $argvInputExtended->expects($this->any())
                          ->method('getOption')
                          ->withConsecutive(
                              array($this->equalTo('database-host')),
                              array($this->equalTo('database-user')),
                              array($this->equalTo('database-port'))
                          )
                          ->willReturnOnConsecutiveCalls(
                              $this->returnValue('HOST'),
                              $this->returnValue('USER'),
                              $this->returnValue('PORT')
                          );

        $argvInputExtended->expects($this->any())
                          ->method('getArgument')
                          ->with($this->equalTo('instances'))
                          ->will($this->returnValue(array()));

        $configFile = $this->getFixtureConfigFilePath();
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);

        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);

        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
        $this->assertEquals('gerrie', $configuration->getConfigurationValue('Database.Name'));
    }
}<commit_msg>Added unit test for Configuration default object<commit_after><?php
/**
 * This file is part of the Gerrie package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Gerrie\Tests\Component\Configuration;

use Gerrie\Component\Configuration\ConfigurationFactory;

class ConfigurationFactoryTest extends \PHPUnit_Framework_TestCase
{

    protected function getFixtureConfigFilePath()
    {
        $configFile  = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
        $configFile .= 'Fixture' . DIRECTORY_SEPARATOR . 'DummyConfig.yml';
        $configFile = realpath($configFile);

        return $configFile;
    }

    /**
     * @expectedException     \RuntimeException
     * @expectedExceptionCode 1415381521
     */
    public function testGetConfigurationByConfigFileWithInvalidConfigFile()
    {
        ConfigurationFactory::getConfigurationByConfigFile('./doesNotExists.yml');
    }

    public function testGetConfigurationByConfigFileWithValidConfigFile()
    {
        $configFile = $this->getFixtureConfigFilePath();
        $configuration = ConfigurationFactory::getConfigurationByConfigFile($configFile);

        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
        $this->assertEquals('root', $configuration->getConfigurationValue('Database.Username'));
    }

    protected function getArgvInputExtendedMockObject($isConfigFileOptionSet)
    {
        $mockedMethods = ['isOptionSet', 'getOption', 'getArgument'];
        $argvInputExtended = $this->getMock('Gerrie\Component\Console\ArgvInputExtended', $mockedMethods);
        $argvInputExtended->expects($this->any())
            ->method('isOptionSet')
            ->withConsecutive(
                array($this->equalTo('config-file')),
                array($this->equalTo('database-host')),
                array($this->equalTo('database-user')),
                array($this->equalTo('database-pass')),
                array($this->equalTo('database-port')),
                array($this->equalTo('database-name'))
            )
            ->willReturnOnConsecutiveCalls(
                $this->returnValue($isConfigFileOptionSet),
                $this->returnValue(true),
                $this->returnValue(true),
                $this->returnValue(false),
                $this->returnValue(true),
                $this->returnValue(false)
            );

        $argvInputExtended->expects($this->any())
            ->method('getOption')
            ->withConsecutive(
                array($this->equalTo('database-host')),
                array($this->equalTo('database-user')),
                array($this->equalTo('database-port'))
            )
            ->willReturnOnConsecutiveCalls(
                $this->returnValue('HOST'),
                $this->returnValue('USER'),
                $this->returnValue('PORT')
            );

        $argvInputExtended->expects($this->any())
            ->method('getArgument')
            ->with($this->equalTo('instances'))
            ->will($this->returnValue(array()));

        return $argvInputExtended;
    }

    public function testGetConfigurationByConfigFileAndCommandOptionsAndArguments()
    {
        $argvInputExtended = $this->getArgvInputExtendedMockObject(true);

        $configFile = $this->getFixtureConfigFilePath();
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);

        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);

        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
        $this->assertEquals('gerrie', $configuration->getConfigurationValue('Database.Name'));
    }

    public function testGetConfigurationByConfigFileAndCommandOptionsAndArgumentsWithoutConfigFileOption()
    {
        $argvInputExtended = $this->getArgvInputExtendedMockObject(false);

        $configFile = $this->getFixtureConfigFilePath();
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);

        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);

        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
    }
}
{'fraction_non_alphanumeric': 0.12787371543595719, 'fraction_numerical': 0.002118868524208073, 'mean_word_length': 2.6433809340023156, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 125, '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': '4334412', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2209, 'n_words': 295}