<commit_before><?php

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

namespace Composer\Test;

use Symfony\Component\Process\Process;
use Composer\Util\Filesystem;
use Symfony\Component\Finder\Finder;

/**
 * @group slow
 */
class AllFunctionalTest extends \PHPUnit_Framework_TestCase
{
    protected $oldcwd;
    protected $oldenv;
    protected $testDir;
    private static $pharPath;

    public function setUp()
    {
        $this->oldcwd = getcwd();
        chdir(__DIR__.'/Fixtures/functional');
    }

    public function tearDown()
    {
        chdir($this->oldcwd);
        $fs = new Filesystem;
        if ($this->testDir) {
            $fs->removeDirectory($this->testDir);
            $this->testDir = null;
        }
        if ($this->oldenv) {
            $fs->removeDirectory(getenv('COMPOSER_HOME'));
            putenv('COMPOSER_HOME='.$this->oldenv);
            $this->oldenv = null;
        }
    }

    public static function setUpBeforeClass()
    {
        self::$pharPath = sys_get_temp_dir().'/composer-phar-test/composer.phar';
    }

    public static function tearDownAfterClass()
    {
        $fs = new Filesystem;
        $fs->removeDirectory(dirname(self::$pharPath));
    }

    public function testBuildPhar()
    {
        if (defined('HHVM_VERSION')) {
            $this->markTestSkipped('Building the phar does not work on HHVM.');
        }

        $fs = new Filesystem;
        $fs->removeDirectory(dirname(self::$pharPath));
        $fs->ensureDirectoryExists(dirname(self::$pharPath));
        chdir(dirname(self::$pharPath));

        $proc = new Process('php '.escapeshellarg(__DIR__.'/../../../bin/compile'), dirname(self::$pharPath));
        $exitcode = $proc->run();
        if ($exitcode !== 0 || trim($proc->getOutput())) {
            $this->fail($proc->getOutput());
        }
        $this->assertTrue(file_exists(self::$pharPath));
    }

    /**
     * @dataProvider getTestFiles
     * @depends testBuildPhar
     */
    public function testIntegration(\SplFileInfo $testFile)
    {
        $testData = $this->parseTestFile($testFile);

        $this->oldenv = getenv('COMPOSER_HOME');
        putenv('COMPOSER_HOME='.$this->testDir.'home');

        $cmd = 'php '.escapeshellarg(self::$pharPath).' --no-ansi '.$testData['RUN'];
        $proc = new Process($cmd, __DIR__.'/Fixtures/functional');
        $exitcode = $proc->run();

        if (isset($testData['EXPECT'])) {
            $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: '.$proc->getErrorOutput());
        }
        if (isset($testData['EXPECT-REGEX'])) {
            $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: '.$proc->getErrorOutput());
        }
        if (isset($testData['EXPECT-ERROR'])) {<commit_msg>Raise timeout to 5 minutes<commit_after><?php

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

namespace Composer\Test;

use Symfony\Component\Process\Process;
use Composer\Util\Filesystem;
use Symfony\Component\Finder\Finder;

/**
 * @group slow
 */
class AllFunctionalTest extends \PHPUnit_Framework_TestCase
{
    protected $oldcwd;
    protected $oldenv;
    protected $testDir;
    private static $pharPath;

    public function setUp()
    {
        $this->oldcwd = getcwd();
        chdir(__DIR__.'/Fixtures/functional');
    }

    public function tearDown()
    {
        chdir($this->oldcwd);
        $fs = new Filesystem;
        if ($this->testDir) {
            $fs->removeDirectory($this->testDir);
            $this->testDir = null;
        }
        if ($this->oldenv) {
            $fs->removeDirectory(getenv('COMPOSER_HOME'));
            putenv('COMPOSER_HOME='.$this->oldenv);
            $this->oldenv = null;
        }
    }

    public static function setUpBeforeClass()
    {
        self::$pharPath = sys_get_temp_dir().'/composer-phar-test/composer.phar';
    }

    public static function tearDownAfterClass()
    {
        $fs = new Filesystem;
        $fs->removeDirectory(dirname(self::$pharPath));
    }

    public function testBuildPhar()
    {
        if (defined('HHVM_VERSION')) {
            $this->markTestSkipped('Building the phar does not work on HHVM.');
        }

        $fs = new Filesystem;
        $fs->removeDirectory(dirname(self::$pharPath));
        $fs->ensureDirectoryExists(dirname(self::$pharPath));
        chdir(dirname(self::$pharPath));

        $proc = new Process('php '.escapeshellarg(__DIR__.'/../../../bin/compile'), dirname(self::$pharPath));
        $exitcode = $proc->run();
        if ($exitcode !== 0 || trim($proc->getOutput())) {
            $this->fail($proc->getOutput());
        }
        $this->assertTrue(file_exists(self::$pharPath));
    }

    /**
     * @dataProvider getTestFiles
     * @depends testBuildPhar
     */
    public function testIntegration(\SplFileInfo $testFile)
    {
        $testData = $this->parseTestFile($testFile);

        $this->oldenv = getenv('COMPOSER_HOME');
        putenv('COMPOSER_HOME='.$this->testDir.'home');

        $cmd = 'php '.escapeshellarg(self::$pharPath).' --no-ansi '.$testData['RUN'];
        $proc = new Process($cmd, __DIR__.'/Fixtures/functional', null, null, 300);
        $exitcode = $proc->run();

        if (isset($testData['EXPECT'])) {
            $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: '.$proc->getErrorOutput());
        }
        if (isset($testData['EXPECT-REGEX'])) {
            $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: '.$proc->getErrorOutput());
        }
        if (isset($testData['EXPECT-ERROR'])) {
{'fraction_non_alphanumeric': 0.16661162483487452, 'fraction_numerical': 0.0009907529722589167, 'mean_word_length': 2.702322738386308, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 77, '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': '515360', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1863, 'n_words': 335}