<commit_before><?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\Input;

/**
 * @covers PharIo\Phive\ComposerCommand
 */
class ComposerCommandTest extends \PHPUnit_Framework_TestCase {

    public function testLetsPharServiceInstallExpectedPhars() {

        $workingDirectory = $this->getDirectoryMock();

        $config = $this->getComposerCommandConfigMock();
        $config->method('getTargetDirectory')->willReturn($workingDirectory);
        $config->method('makeCopy')->willReturn(false);
        $config->method('getComposerFilename')->willReturn(new Filename('foo'));

        $requestedPhar1 = $this->getRequestedPharMock();
        $requestedPhar2 = $this->getRequestedPharMock();

        $composerService = $this->getComposerServiceMock();
        $composerService->method('findCandidates')
            ->willReturn([$requestedPhar1, $requestedPhar2]);

        $pharService = $this->getPharServiceMock();
        $pharService->expects($this->at(0))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar1),
                $workingDirectory,
                false
            )->willReturn($this->getPharMock());
        $pharService->expects($this->at(1))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar2),
                $workingDirectory,
                false
            )->willReturn($this->getPharMock());

        $input = $this->getInputMock();
        $input->method('confirm')->willReturn(true);

        $command = new ComposerCommand(
            $config,
            $composerService,
            $pharService,
            $this->getPhiveXmlConfigMock(),
            $this->getEnvironmentMock(),
            $input
        );

        $command->execute();
    }

    public function testLetsPharServiceInstallExpectedPharsGlobally() {

        $config = $this->getComposerCommandConfigMock();
        $config->method('installGlobally')->willReturn(true);
        $config->method('makeCopy')->willReturn(false);
        $config->method('getComposerFilename')->willReturn(new Filename('foo'));

        $environment = $this->getEnvironmentMock();
        $environment->method('getBinaryName')
            ->willReturn('/usr/bin/php');

        $requestedPhar1 = $this->getRequestedPharMock();
        $requestedPhar2 = $this->getRequestedPharMock();

        $composerService = $this->getComposerServiceMock();
        $composerService->method('findCandidates')
            ->willReturn([$requestedPhar1, $requestedPhar2]);

        $pharService = $this->getPharServiceMock();
        $pharService->expects($this->at(0))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar1),
                '/usr/bin',
                false
            );
        $pharService->expects($this->at(1))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar2),
                '/usr/bin',
                false
            );

        $input = $this->getInputMock();
        $input->method('confirm')->willReturn(true);

        $command = new ComposerCommand(
            $config,
            $composerService,
            $pharService,
            $this->getPhiveXmlConfigMock(),
            $environment,
            $input
        );

        $command->execute();
    }

    public function testDoesNotInstallPharsIfUserDidNotConfirm() {

        $workingDirectory = $this->getDirectoryMock();

        $config = $this->getComposerCommandConfigMock();
        $config->method('getTargetDirectory')->willReturn($workingDirectory);<commit_msg>fix test failing in scrutinizer<commit_after><?php
namespace PharIo\Phive;

use PharIo\Phive\Cli\Input;

/**
 * @covers PharIo\Phive\ComposerCommand
 */
class ComposerCommandTest extends \PHPUnit_Framework_TestCase {

    public function testLetsPharServiceInstallExpectedPhars() {

        $workingDirectory = $this->getDirectoryMock();

        $config = $this->getComposerCommandConfigMock();
        $config->method('getTargetDirectory')->willReturn($workingDirectory);
        $config->method('makeCopy')->willReturn(false);
        $config->method('getComposerFilename')->willReturn(new Filename('foo'));

        $requestedPhar1 = $this->getRequestedPharMock();
        $requestedPhar2 = $this->getRequestedPharMock();

        $composerService = $this->getComposerServiceMock();
        $composerService->method('findCandidates')
            ->willReturn([$requestedPhar1, $requestedPhar2]);

        $pharService = $this->getPharServiceMock();
        $pharService->expects($this->at(0))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar1),
                $workingDirectory,
                false
            )->willReturn($this->getPharMock());
        $pharService->expects($this->at(1))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar2),
                $workingDirectory,
                false
            )->willReturn($this->getPharMock());

        $input = $this->getInputMock();
        $input->method('confirm')->willReturn(true);

        $command = new ComposerCommand(
            $config,
            $composerService,
            $pharService,
            $this->getPhiveXmlConfigMock(),
            $this->getEnvironmentMock(),
            $input
        );

        $command->execute();
    }

    public function testLetsPharServiceInstallExpectedPharsGlobally() {

        $config = $this->getComposerCommandConfigMock();
        $config->method('installGlobally')->willReturn(true);
        $config->method('makeCopy')->willReturn(false);
        $config->method('getComposerFilename')->willReturn(new Filename('foo'));

        $environment = $this->getEnvironmentMock();
        $environment->method('getBinaryName')
            ->willReturn(__DIR__ . '/php');

        $requestedPhar1 = $this->getRequestedPharMock();
        $requestedPhar2 = $this->getRequestedPharMock();

        $composerService = $this->getComposerServiceMock();
        $composerService->method('findCandidates')
            ->willReturn([$requestedPhar1, $requestedPhar2]);

        $pharService = $this->getPharServiceMock();
        $pharService->expects($this->at(0))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar1),
                __DIR__,
                false
            );
        $pharService->expects($this->at(1))
            ->method('install')
            ->with(
                $this->identicalTo($requestedPhar2),
                __DIR__,
                false
            );

        $input = $this->getInputMock();
        $input->method('confirm')->willReturn(true);

        $command = new ComposerCommand(
            $config,
            $composerService,
            $pharService,
            $this->getPhiveXmlConfigMock(),
            $environment,
            $input
        );

        $command->execute();
    }

    public function testDoesNotInstallPharsIfUserDidNotConfirm() {

        $workingDirectory = $this->getDirectoryMock();

        $config = $this->getComposerCommandConfigMock();
        $config->method('getTargetDirectory')->willReturn($workingDirectory);
{'fraction_non_alphanumeric': 0.14346164346164347, 'fraction_numerical': 0.004368004368004368, 'mean_word_length': 2.336520947176685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 141, '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': '3866546', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1959, 'n_words': 238}