<commit_before><?php

namespace Pvra\tests\Console\Commands;

require_once TEST_FILE_ROOT . 'NonImplementingNodeWalker.php';

use Symfony\Component\Console\Tester\CommandTester;

class FileCommandTest extends PvraBaseCommandTestBase
{
    protected $commandToTest = 'analyse:file';

    public function testSimpleExecuteWithSingleNodeWalker()
    {
        /** @var CommandTester $commandTester */
        list($commandTester) = $this->getBareInstances();
        $commandTester->execute([
            'target' => TEST_FILE_ROOT . '5.4/all54.php',
            '--analyser' => ['Php56Features'],
        ]);

        $out = trim($commandTester->getDisplay(true));
        $this->assertTrue(strpos($out, 'Required version: 5.6.0') !== false);
        $this->assertSame(1, substr_count($out, 'Variadic arguments'));
        $this->assertSame(0, substr_count($out, '5.4.0'));
    }

    public function testSimpleExecuteWithSingleMatchingNodeWalker()
    {
        $out = trim($this->execute([
            'target' => TEST_FILE_ROOT . '5.4/all54.php',
            '--analyser' => ['Php54Features'],
        ])->getDisplay(true));

        $this->assertTrue(strpos($out, 'PHP 5.6.0') === false);
        $this->assertSame(41, substr_count($out, '5.4.0'));
        $this->assertTrue(strpos($out, 'Required version: 5.4.0') !== false);
    }

    public function testSimpleExecuteWithSingleMatchingNodeWalkerAndPreferredRelativePath()
    {
        $out = trim($this->execute([
            'target' => TEST_FILE_ROOT . '5.4/all54.php',
            '--analyser' => ['Php54Features'],
            // output format should not differ
            '--preferRelativePaths' => true,
        ])->getDisplay(true));

        $this->assertTrue(strpos($out, 'PHP 5.6.0') === false);
        $this->assertSame(19, preg_match_all('/(^\\s+[\\w]+: [\\w\\\\s$ ]+\\d\\.\\d+\\.\\d+ in .+:\\d+$)/m', $out));
    }

    public function testAliasedAnalyserExecution()
    {
        $out = trim($this->execute([
            'target' => TEST_FILE_ROOT . '5.6/all56.php',
            '--analyser' => ['php-5.3'],
        ])->getDisplay(true));

        $this->assertTrue(stripos($out, 'PHP 5.6') === false);
        $this->assertTrue(stripos($out, 'PHP 5.5') === false);
        $this->assertTrue(stripos($out, 'PHP 5.4') === false);
        $this->assertSame(2, substr_count($out, 'PHP 5.3'));
    }<commit_msg>Fix failing test<commit_after><?php

namespace Pvra\tests\Console\Commands;

require_once TEST_FILE_ROOT . 'NonImplementingNodeWalker.php';

use Symfony\Component\Console\Tester\CommandTester;

class FileCommandTest extends PvraBaseCommandTestBase
{
    protected $commandToTest = 'analyse:file';

    public function testSimpleExecuteWithSingleNodeWalker()
    {
        /** @var CommandTester $commandTester */
        list($commandTester) = $this->getBareInstances();
        $commandTester->execute([
            'target' => TEST_FILE_ROOT . '5.4/all54.php',
            '--analyser' => ['Php56Features'],
        ]);

        $out = trim($commandTester->getDisplay(true));
        $this->assertTrue(strpos($out, 'Required version: 5.6.0') !== false);
        $this->assertSame(1, substr_count($out, 'Variadic arguments'));
        $this->assertSame(0, substr_count($out, '5.4.0'));
    }

    public function testSimpleExecuteWithSingleMatchingNodeWalker()
    {
        $out = trim($this->execute([
            'target' => TEST_FILE_ROOT . '5.4/all54.php',
            '--analyser' => ['Php54Features'],
        ])->getDisplay(true));

        $this->assertTrue(strpos($out, 'PHP 5.6.0') === false);
        $this->assertSame(41, substr_count($out, '5.4.0'));
        $this->assertTrue(strpos($out, 'Required version: 5.4.0') !== false);
    }

    public function testSimpleExecuteWithSingleMatchingNodeWalkerAndPreferredRelativePath()
    {
        $out = trim($this->execute([
            'target' => TEST_FILE_ROOT . '5.4/all54.php',
            '--analyser' => ['Php54Features'],
            // output format should not differ
            '--preferRelativePaths' => true,
        ])->getDisplay(true));

        $this->assertTrue(strpos($out, 'PHP 5.6') === false);
        $this->assertTrue(strpos($out, 'PHP 5.3') === false);
        $this->assertTrue(stripos($out, 'Running analysis for "./tests/testFiles/5.4/all54.php"') !== false);
        $this->assertSame(20, preg_match_all('/^(\\|\\s*5\\.4\\.0\\s*\\|[\\s\\w$:{}()]*5\\.4\\.0\\s*\\|\\s\\d+\\s*\\|)$/m', $out));
    }

    public function testAliasedAnalyserExecution()
    {
        $out = trim($this->execute([
            'target' => TEST_FILE_ROOT . '5.6/all56.php',
            '--analyser' => ['php-5.3'],
        ])->getDisplay(true));

        $this->assertTrue(stripos($out, 'PHP 5.6') === false);
        $this->assertTrue(stripos($out, 'PHP 5.5') === false);
        $this->assertTrue(stripos($out, 'PHP 5.4') === false);
        $this->assertSame(2, substr_count($out, 'PHP 5.3'));
    }
{'fraction_non_alphanumeric': 0.19563459983831852, 'fraction_numerical': 0.025262732417138237, 'mean_word_length': 2.7634980988593156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '1073144', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1619, 'n_words': 252}