<commit_before><?php

namespace Test\Synapse\CliCommand;

use PHPUnit_Framework_TestCase;

use Synapse\CliCommand\AbstractCliCommand;
use Synapse\CliCommand\CliCommand;
use Synapse\CliCommand\CliCommandOptions;
use Synapse\CliCommand\CliCommandResponse;

class CliCommandTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->setUpExecutor();
        $this->command = new CliCommand($this->executor);
        $this->options = new CliCommandOptions;
    }

    public function setUpExecutor()
    {
        $this->executor = $this->getMockBuilder('Synapse\CliCommand\CliCommandExecutor')
                             ->disableOriginalConstructor()
                             ->getMock();
    }

    public function createResponseObject($output, $returnCode)
    {
        return new CliCommandResponse([
            'output'      => $output,
            'return_code' => $returnCode,
        ]);
    }

    public function testCommandGivesExpectedResponse()
    {
        $command  = 'pwd \'foo\' \'bar\'=\'baz\' \'9999\' 2>&1';
        $expected = '/current/working/directory';

        $this->executor
            ->expects($this->any())
            ->method('execute')
            ->with(
                $this->equalTo($command),
                $this->equalTo(null),
                $this->equalTo(null)
            )
            ->will($this->returnValue(
                $this->createResponseObject($expected, 0)
            ));

        $this->command->setBaseCommand('pwd \'foo\' \'bar\'=\'baz\' \'9999\'');

        $response = $this->command->run();

        $this->assertEquals($expected, (string) $response->getOutput());
        $this->assertEquals(true, $response->getSuccessfull());
        $this->assertEquals(0, (int) $response->getReturnCode());
        $this->assertNotEmpty($response->getStartTime());
        $this->assertNotEmpty($response->getElapsedTime());
    }

    public function testCommandErrorGivesExpectedResponse()
    {
        $command  = 'stat /foo 2>&1';<commit_msg>#112 | escapeshellcmd doesn’t work like that<commit_after><?php

namespace Test\Synapse\CliCommand;

use PHPUnit_Framework_TestCase;

use Synapse\CliCommand\AbstractCliCommand;
use Synapse\CliCommand\CliCommand;
use Synapse\CliCommand\CliCommandOptions;
use Synapse\CliCommand\CliCommandResponse;

class CliCommandTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $this->setUpExecutor();
        $this->command = new CliCommand($this->executor);
        $this->options = new CliCommandOptions;
    }

    public function setUpExecutor()
    {
        $this->executor = $this->getMockBuilder('Synapse\CliCommand\CliCommandExecutor')
                             ->disableOriginalConstructor()
                             ->getMock();
    }

    public function createResponseObject($output, $returnCode)
    {
        return new CliCommandResponse([
            'output'      => $output,
            'return_code' => $returnCode,
        ]);
    }

    public function testCommandGivesExpectedResponse()
    {
        $command  = 'pwd foo bar=baz 9999 2>&1';
        $expected = '/current/working/directory';

        $this->executor
            ->expects($this->any())
            ->method('execute')
            ->with(
                $this->equalTo($command),
                $this->equalTo(null),
                $this->equalTo(null)
            )
            ->will($this->returnValue(
                $this->createResponseObject($expected, 0)
            ));

        $this->command->setBaseCommand('pwd foo bar=baz 9999');

        $response = $this->command->run();

        $this->assertEquals($expected, (string) $response->getOutput());
        $this->assertEquals(true, $response->getSuccessfull());
        $this->assertEquals(0, (int) $response->getReturnCode());
        $this->assertNotEmpty($response->getStartTime());
        $this->assertNotEmpty($response->getElapsedTime());
    }

    public function testCommandErrorGivesExpectedResponse()
    {
        $command  = 'stat /foo 2>&1';
{'fraction_non_alphanumeric': 0.14033798677443057, 'fraction_numerical': 0.007592456527063434, 'mean_word_length': 2.406171809841535, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1209229', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1089, 'n_words': 182}