<commit_before><?php

namespace AqBanking\Command;

use AqBanking\Bank;
use AqBanking\BankCode;
use AqBanking\Command\ShellCommandExecutor\Result;
use AqBanking\User;

require_once 'ShellCommandTestCase.php';

class AddUserCommandTest extends ShellCommandTestCase
{
    public function testCanAddAqBankingUser()
    {
        $userId = 'mustermann';
        $userName = 'Max Mustermann';
        $bankCodeString = '12345678';
        $hbciUrl = 'https://hbci.example.com';

        $shellCommandExecutorMock = $this->getShellCommandExecutorMock();

        $expectedCommand =
            'aqhbci-tool4'
            . ' adduser'
            . ' --username="' . $userName . '"'
            . ' --bank=' . $bankCodeString
            . ' --user=' . $userId
            . ' --tokentype=pintan'
            . ' --server=' . $hbciUrl
        ;

        $shellCommandExecutorMock
            ->shouldReceive('execute')->once()
            ->with($expectedCommand)
            ->andReturn(new Result(array(), array(), 0));

        $sut = new AddUserCommand();
        $sut->setShellCommandExecutor($shellCommandExecutorMock);

        $sut->execute(new User($userId, $userName, new Bank(new BankCode($bankCodeString), $hbciUrl)));

        // To satisfy PHPUnit's "strict" mode - if Mockery didn't throw an exception until here, everything is fine
        $this->assertTrue(true);
    }

    /**
     * @expectedException \AqBanking\Command\AddUserCommand\UserAlreadyExistsException
     */
    public function testThrowsExceptionIfUserAlreadyExists()
    {
        $userId = 'mustermann';
        $userName = 'Max Mustermann';
        $bankCodeString = '12345678';
        $hbciUrl = 'https://hbci.example.com';

        $shellCommandExecutorMock = $this->getShellCommandExecutorMock();

        $expectedCommand =
            'aqhbci-tool4'
            . ' adduser'
            . ' --username="' . $userName . '"'
            . ' --bank=' . $bankCodeString
            . ' --user=' . $userId
            . ' --tokentype=pintan'
            . ' --server=' . $hbciUrl
        ;<commit_msg>Made test a bit more readable<commit_after><?php

namespace AqBanking\Command;

use AqBanking\Bank;
use AqBanking\BankCode;
use AqBanking\Command\ShellCommandExecutor\Result;
use AqBanking\User;

require_once 'ShellCommandTestCase.php';

class AddUserCommandTest extends ShellCommandTestCase
{
    public function testCanAddAqBankingUser()
    {
        $userId = 'mustermann';
        $userName = 'Max Mustermann';
        $bankCodeString = '12345678';
        $hbciUrl = 'https://hbci.example.com';

        $bankCode = new BankCode($bankCodeString);
        $bank = new Bank($bankCode, $hbciUrl);
        $user = new User($userId, $userName, $bank);

        $shellCommandExecutorMock = $this->getShellCommandExecutorMock();

        $expectedCommand =
            'aqhbci-tool4'
            . ' adduser'
            . ' --username="' . $userName . '"'
            . ' --bank=' . $bankCodeString
            . ' --user=' . $userId
            . ' --tokentype=pintan'
            . ' --server=' . $hbciUrl
        ;

        $shellCommandExecutorMock
            ->shouldReceive('execute')->once()
            ->with($expectedCommand)
            ->andReturn(new Result(array(), array(), 0));

        $sut = new AddUserCommand();
        $sut->setShellCommandExecutor($shellCommandExecutorMock);

        $sut->execute($user);

        // To satisfy PHPUnit's "strict" mode - if Mockery didn't throw an exception until here, everything is fine
        $this->assertTrue(true);
    }

    /**
     * @expectedException \AqBanking\Command\AddUserCommand\UserAlreadyExistsException
     */
    public function testThrowsExceptionIfUserAlreadyExists()
    {
        $userId = 'mustermann';
        $userName = 'Max Mustermann';
        $bankCodeString = '12345678';
        $hbciUrl = 'https://hbci.example.com';

        $shellCommandExecutorMock = $this->getShellCommandExecutorMock();

        $expectedCommand =
            'aqhbci-tool4'
            . ' adduser'
            . ' --username="' . $userName . '"'
            . ' --bank=' . $bankCodeString
            . ' --user=' . $userId
            . ' --tokentype=pintan'
            . ' --server=' . $hbciUrl
        ;
{'fraction_non_alphanumeric': 0.13621418506341004, 'fraction_numerical': 0.008924377642085486, 'mean_word_length': 2.1594955489614245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 4, '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': '2269586', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1224, 'n_words': 223}