<commit_before><?php

namespace Wikp\PaymentMtgoxBundle\Tests\Console\Command;

use Wikp\PaymentMtgoxBundle\Console\Command\ExchangeCalculator;
use Symfony\Component\DependencyInjection\Container;
use Wikp\PaymentMtgoxBundle\Mtgox\Exchange;

class ExchangeCalculatorTest extends \PHPUnit_Framework_TestCase
{
    /** @var \Wikp\PaymentMtgoxBundle\Console\Command\ExchangeCalculator */
    private $command;

    public function setUp()
    {
        $this->command = new ExchangeCalculator();

    }

    public function testValidParams()
    {
        $this->setContainer($this->getExchangeMock(false, 10, 'USD', 1000));
        $this->command->run($this->getInputMock(), $this->getOutputMock());
    }

    private function getOutputMock()
    {
        $mock = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
            ->getMockForAbstractClass();

        return $mock;
    }

    private function getInputMock($fromBtc = true, $currency = 'BTC', $amount = 10)
    {
        $mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')
            ->getMockForAbstractClass();

        $mock->expects($this->at(1))
            ->method('getOption')
            ->with($this->equalTo('from-btc'))
            ->will($this->returnValue($fromBtc));

        $mock->expects($this->at(2))
            ->method('getOption')
            ->with($this->equalTo('currency'))
            ->will($this->returnValue($currency));

        $mock->expects($this->at(1))
            ->method('getArgument')
            ->with($this->equalTo('amount'))
            ->will($this->returnValue($amount));

        return $mock;
    }

    private function setContainer(Exchange $mock)
    {
        $container = new Container();
        $container->set('wikp_payment_mtgox.exchange', $mock);

        $this->command->setContainer($container);
    }

    private function getExchangeMock($fromBtc, $amount, $currency, $expectedAmount)
    {
        $mock = $this->getMockBuilder('Wikp\PaymentMtgoxBundle\Mtgox\Exchange')
            ->disableOriginalConstructor()
            ->setMethods(array('convertFromBitcoins', 'convertToBitcoins'))
            ->getMock();

        if ($fromBtc) {
            $mock->expects($this->once())
                ->method('convertFromBitcoins')
                ->with($this->equalTo($amount), $this->equalTo($currency))
                ->will($this->returnValue($expectedAmount));
            $mock->expects($this->never())
                ->method('convertToBitcoins');
        } else {
            $mock->expects($this->once())
                ->method('convertToBitcoins')
                ->with($this->equalTo($amount), $this->equalTo($currency))
                ->will($this->returnValue($expectedAmount));
            $mock->expects($this->never())
                ->method('convertFromBitcoins');
        }

        return $mock;
    }
}<commit_msg>exchange test<commit_after><?php

namespace Wikp\PaymentMtgoxBundle\Tests\Console\Command;

use Wikp\PaymentMtgoxBundle\Console\Command\ExchangeCalculator;
use Symfony\Component\DependencyInjection\Container;
use Wikp\PaymentMtgoxBundle\Mtgox\Exchange;

class ExchangeCalculatorTest extends \PHPUnit_Framework_TestCase
{
    /** @var \Wikp\PaymentMtgoxBundle\Console\Command\ExchangeCalculator */
    private $command;

    public function setUp()
    {
        $this->command = new ExchangeCalculator();
    }

    public function testValidParams()
    {
        $this->setContainer($this->getExchangeMock(true, 10, 'EUR', 1000));
        $this->command->run($this->getInputMock(), $this->getOutputMock());
    }

    private function getOutputMock()
    {
        $mock = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
            ->getMockForAbstractClass();

        $mock->expects($this->any())
            ->method('writeln')
            ->with("10 BTC = <info>1000 EUR</info>");

        return $mock;
    }

    private function getInputMock($fromBtc = true, $currency = 'EUR', $amount = 10)
    {
        $mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')
            ->setMethods(array('getOption', 'getArgument'))
            ->getMockForAbstractClass();

        $mock->expects($this->any())
            ->method('getOption')
            ->will(
                $this->returnCallback(
                    function ($name) use ($currency, $fromBtc) {
                        if ('from-btc' == $name) {
                            return $fromBtc;
                        } elseif ('currency' == $name) {
                            return $currency;
                        }
                    }
                )
            );

        $mock->expects($this->any())
            ->method('getArgument')
            ->will($this->returnValue($amount));

        return $mock;
    }

    private function setContainer(Exchange $mock)
    {
        $container = new Container();
        $container->set('wikp_payment_mtgox.exchange', $mock);

        $this->command->setContainer($container);
    }

    private function getExchangeMock($fromBtc, $amount, $currency, $expectedAmount)
    {
        $mock = $this->getMockBuilder('Wikp\PaymentMtgoxBundle\Mtgox\Exchange')
            ->disableOriginalConstructor()
            ->setMethods(array('convertFromBitcoins', 'convertToBitcoins'))
            ->getMock();

        if ($fromBtc) {
            $mock->expects($this->once())
                ->method('convertFromBitcoins')
                ->with($this->equalTo($amount), $this->equalTo($currency))
                ->will($this->returnValue($expectedAmount));
            $mock->expects($this->never())
                ->method('convertToBitcoins');
        } else {
            $mock->expects($this->once())
                ->method('convertToBitcoins')
                //->with($this->equalTo($amount), $this->equalTo($currency))
                ->will($this->returnValue($expectedAmount));
            $mock->expects($this->never())
                ->method('convertFromBitcoins');
        }

        return $mock;
    }
}
{'fraction_non_alphanumeric': 0.15451275343361676, 'fraction_numerical': 0.004087638979725311, 'mean_word_length': 2.3154471544715447, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 121, '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': '6650107', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1649, 'n_words': 231}