<commit_before><?php
use LinusShops\Prophet\Commands\Scry;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

/**
 * 
 *
 * @author <NAME>
 * @date 2015-05-04
 * @company Linus Shops
 */

namespace LinusShops\Prophet;

use LinusShops\Prophet\Commands\Scry;
use LinusShops\Prophet\Commands\Validate;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class ProphetCommandTest extends \PHPUnit_Framework_TestCase
{
    private $path = './magento';
    private $modulePath = '/vendor/linusshops/prophet-magento-test-module';

    public function getJson()
    {
        return <<<JSON
{
    "modules": [
        {
            "path": "vendor/linusshops/prophet-magento-test-module",
            "name": "test-module"
        }
    ]
}
JSON;
    }

    public function getPhpUnitXml()
    {
        return <<<XML
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true">
    <testsuites>
        <testsuite name="Prophet Test Suite">
            <directory suffix="Test.php">./tests/</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>./src</directory>
        </whitelist>
    </filter>
</phpunit>
XML;

    }

    public function getJsonPath()
    {
        return $this->path.'/prophet.json';
    }

    public function makePhpunitXml()
    {
        if (!file_exists($this->path.'/'.$this->modulePath.'/phpunit.xml')) {
            file_put_contents(
                $this->path.'/'.$this->modulePath.'/phpunit.xml',
                $this->getPhpUnitXml()
            );
        }
    }

    public function destroyPhpunitXml()
    {
        if (file_exists($this->path.'/'.$this->modulePath.'/phpunit.xml')) {
            unlink($this->path.'/'.$this->modulePath.'/phpunit.xml');
        }
    }

    public function setUp()
    {
        if (file_exists($this->getJsonPath())) {
            unlink($this->getJsonPath());
        }

        file_put_contents($this->getJsonPath(), $this->getJson());
    }

    public function tearDown()
    {
        if (file_exists($this->getJsonPath())) {
            unlink($this->getJsonPath());
        }
    }

    public function testScryFullExecution()
    {
        $this->makePhpunitXml();
        $output = shell_exec("./prophet scry -p ./magento");

        $this->assertRegExp('/OK \(1 test, 1 assertion\)/', $output);
        $this->destroyPhpunitXml();
    }

    public function testValidateCommand()
    {
        $this->makePhpunitXml();

        $application = new Application();
        $application->add(new Validate());

        $command = $application->find('validate');
        $commandTester = new CommandTester($command);
        $commandTester->execute(array(
            'command' => $command->getName(),
            '--path' => './magento'
        ));

        $output =  $commandTester->getDisplay();

        $this->assertRegExp('/test-module validated/', $output);

        $this->destroyPhpunitXml();
    }

    public function testValidateCommandWithoutPhpunitXml()
    {
        $this->destroyPhpunitXml();
        $application = new Application();
        $application->add(new Validate());

        $command = $application->find('validate');
        $commandTester = new CommandTester($command);
        $commandTester->execute(array(
            'command' => $command->getName(),
            '--path' => './magento'
        ));

        $output = $commandTester->getDisplay();

        $this->assertRegExp('/does not contain a phpunit.xml/', $output);
    }
}<commit_msg>Test validation if module path is invalid.<commit_after><?php
use LinusShops\Prophet\Commands\Scry;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

/**
 * 
 *
 * @author <NAME>
 * @date 2015-05-04
 * @company Linus Shops
 */

namespace LinusShops\Prophet;

use LinusShops\Prophet\Commands\Scry;
use LinusShops\Prophet\Commands\Validate;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class ProphetCommandTest extends \PHPUnit_Framework_TestCase
{
    private $path = './magento';
    private $modulePath = '/vendor/linusshops/prophet-magento-test-module';

    public function getJson()
    {
        return <<<JSON
{
    "modules": [
        {
            "path": "vendor/linusshops/prophet-magento-test-module",
            "name": "test-module"
        }
    ]
}
JSON;
    }

    public function getJsonWithInvalidPath()
    {
        return <<<JSON
{
    "modules": [
        {
            "path": "vendor/linusshops/prophet-magento-fake-module",
            "name": "fake-module"
        }
    ]
}
JSON;
    }

    public function getPhpUnitXml()
    {
        return <<<XML
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true">
    <testsuites>
        <testsuite name="Prophet Test Suite">
            <directory suffix="Test.php">./tests/</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>./src</directory>
        </whitelist>
    </filter>
</phpunit>
XML;

    }

    public function getJsonPath()
    {
        return $this->path.'/prophet.json';
    }

    public function makePhpunitXml()
    {
        if (!file_exists($this->path.'/'.$this->modulePath.'/phpunit.xml')) {
            file_put_contents(
                $this->path.'/'.$this->modulePath.'/phpunit.xml',
                $this->getPhpUnitXml()
            );
        }
    }

    public function destroyPhpunitXml()
    {
        if (file_exists($this->path.'/'.$this->modulePath.'/phpunit.xml')) {
            unlink($this->path.'/'.$this->modulePath.'/phpunit.xml');
        }
    }

    public function setUp()
    {
        if (file_exists($this->getJsonPath())) {
            unlink($this->getJsonPath());
        }

        file_put_contents($this->getJsonPath(), $this->getJson());
    }

    public function tearDown()
    {
        if (file_exists($this->getJsonPath())) {
            unlink($this->getJsonPath());
        }
    }

    public function testScryFullExecution()
    {
        $this->makePhpunitXml();
        $output = shell_exec("./prophet scry -p ./magento");

        $this->assertRegExp('/OK \(1 test, 1 assertion\)/', $output);
        $this->destroyPhpunitXml();
    }

    public function testValidateCommand()
    {
        $this->makePhpunitXml();

        $application = new Application();
        $application->add(new Validate());

        $command = $application->find('validate');
        $commandTester = new CommandTester($command);
        $commandTester->execute(array(
            'command' => $command->getName(),
            '--path' => './magento'
        ));

        $output =  $commandTester->getDisplay();

        $this->assertRegExp('/test-module validated/', $output);

        $this->destroyPhpunitXml();
    }

    public function testValidateCommandWithoutPhpunitXml()
    {
        $this->destroyPhpunitXml();
        $application = new Application();
        $application->add(new Validate());

        $command = $application->find('validate');
        $commandTester = new CommandTester($command);
        $commandTester->execute(array(
            'command' => $command->getName(),
            '--path' => './magento'
        ));

        $output = $commandTester->getDisplay();

        $this->assertRegExp('/does not contain a phpunit.xml/', $output);
    }

    public function testValidateCommandWithInvalidPath()
    {
        file_put_contents($this->getJsonPath(), $this->getJsonWithInvalidPath());
        $application = new Application();
        $application->add(new Validate());

        $command = $application->find('validate');
        $commandTester = new CommandTester($command);
        $commandTester->execute(array(
            'command' => $command->getName(),
            '--path' => './magento'
        ));

        $output = $commandTester->getDisplay();

        $this->assertRegExp('/is not valid/', $output);
    }
}
{'fraction_non_alphanumeric': 0.15937344604674292, 'fraction_numerical': 0.0032322227747389356, 'mean_word_length': 2.328506412908564, 'pattern_counts': {'":': 9, '<': 52, '<?xml version=': 2, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '4012680', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2422, 'n_words': 387}