<commit_before><?php

namespace N98\Magento\Command\Installer;

use RuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
use N98\Magento\Command\PHPUnit\TestCase;

class InstallCommandTest extends TestCase
{

    /**
     * @var string Installation Directory
     */
    protected $installDir;

    /**
     * Create temp dir for install
     */
    public function setup()
    {
        $installDir = sys_get_temp_dir() . "/mageinstall";
        if (is_readable($installDir)) {
            $result = rmdir($installDir);
            if (!$result) {
                throw new RuntimeException(
                    sprintf('Failed to remove temporary install dir %s', var_export($installDir))
                );
            }
        }

        $this->installDir = $installDir;
    }

    /**
     * If all database config is passed in via options and the database validation fails,
     * test that an exception was thrown
     */
    public function testInstallFailsWithInvalidDbConfigWhenAllOptionsArePassedIn()
    {
        $application = $this->getApplication();
        $application->add(new InstallCommand());
        $command = $this->getApplication()->find('install');
        $command->setCliArguments(
            array(
                '--dbName=magento',
                '--dbHost=hostWhichDoesntExist',
                '--dbUser=user',
                '--dbPass=<PASSWORD>',
            )
        );

        $commandTester = new CommandTester($command);

        try {
            $commandTester->execute(
                array(
                    'command'                   => $command->getName(),
                    '--noDownload'              => true,
                    '--installSampleData'       => 'no',
                    '--useDefaultConfigParams'  => 'yes',
                    '--installationFolder'      => $this->installDir,
                    '--dbHost'                  => 'hostWhichDoesNotExists',
                    '--dbUser'                  => 'user',
                    '--dbPass'                  => '<PASSWORD>',
                    '--dbName'                  => 'magento',
                )
            );
        } catch (\InvalidArgumentException $e) {
            $this->assertEquals("Database configuration is invalid", $e->getMessage());
            $display = $commandTester->getDisplay(true);
            $this->assertContains('SQLSTATE', $display);
            return;
        }

        $this->fail('InvalidArgumentException was not raised');
    }

    /**
     * Remove directory made by installer
     */
    public function tearDown()
    {
        if (is_readable($this->installDir)) {
            @rmdir($this->installDir);
        }
    }


}
<commit_msg>Polish<commit_after><?php

namespace N98\Magento\Command\Installer;

use N98\Magento\Command\PHPUnit\TestCase;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Tester\CommandTester;

class InstallCommandTest extends TestCase
{
    /**
     * @var string Installation Directory
     */
    protected $installDir;

    /**
     * Create temp dir for install
     */
    public function setup()
    {
        $installDir = sys_get_temp_dir() . "/mageinstall";
        if (is_readable($installDir)) {
            $result = rmdir($installDir);
            if (!$result) {
                throw new RuntimeException(
                    sprintf('Failed to remove temporary install dir %s', var_export($installDir))
                );
            }
        }

        $this->installDir = $installDir;
    }

    /**
     * If all database config is passed in via options and the database validation fails,
     * test that an exception was thrown
     */
    public function testInstallFailsWithInvalidDbConfigWhenAllOptionsArePassedIn()
    {
        $application = $this->getApplication();
        $application->add(new InstallCommand());
        $command = $this->getApplication()->find('install');
        $command->setCliArguments(
            array(
                '--dbName=magento',
                '--dbHost=hostWhichDoesntExist',
                '--dbUser=user',
                '--dbPass=<PASSWORD>',
            )
        );

        $commandTester = new CommandTester($command);

        try {
            $commandTester->execute(
                array(
                    'command'                  => $command->getName(),
                    '--noDownload'             => true,
                    '--installSampleData'      => 'no',
                    '--useDefaultConfigParams' => 'yes',
                    '--installationFolder'     => $this->installDir,
                    '--dbHost'                 => 'hostWhichDoesNotExists',
                    '--dbUser'                 => 'user',
                    '--dbPass'                 => '<PASSWORD>',
                    '--dbName'                 => 'magento',
                )
            );
        } catch (\InvalidArgumentException $e) {
            $this->assertEquals("Database configuration is invalid", $e->getMessage());
            $display = $commandTester->getDisplay(true);
            $this->assertContains('SQLSTATE', $display);

            return;
        }

        $this->fail('InvalidArgumentException was not raised');
    }

    /**
     * Remove directory made by installer
     */
    public function tearDown()
    {
        if (is_readable($this->installDir)) {
            @rmdir($this->installDir);
        }
    }
}

{'fraction_non_alphanumeric': 0.12250045036930284, 'fraction_numerical': 0.0014411817690506215, 'mean_word_length': 1.5775301764159704, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485157', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1385, 'n_words': 276}