<commit_before><?php
/**
 * @copyright 2018
 * @author Stefan "eFrane" Graupner <<EMAIL>>
 */

namespace Tests\Unit\Batch;


use EFrane\ConsoleAdditions\Batch\Batch;
use EFrane\ConsoleAdditions\Batch\InstanceCommandAction;
use EFrane\ConsoleAdditions\Batch\ProcessAction;
use EFrane\ConsoleAdditions\Batch\StringCommandAction;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Process\Process;
use Tests\TestCommand;

class BatchTest extends BatchTestCase
{
    public function testAdd()
    {
        $sut = new Batch($this->app, $this->output);
        $sut->add('list');

        $this->assertEquals(1, count($sut->getActions()));
        $this->assertIsArray($sut->getActions());
        $sut->add('help');

        $this->assertEquals(
            [
                (new StringCommandAction('list'))->setApplication($this->app),
                (new StringCommandAction('help'))->setApplication($this->app),
            ],
            $sut->getActions()
        );
    }

    public function testRunOne()
    {
        $sut = new Batch($this->app, $this->output);

        try {
            $action = new StringCommandAction('list');
            $action->setApplication($this->app);


            $sut->runOne($action);
        } catch (\Exception $e) {
        }

        $expected = <<<HD
testApp
<commit_msg>Add version guard around php 7.1 failing assertion<commit_after><?php
/**
 * @copyright 2018
 * @author Stefan "eFrane" Graupner <<EMAIL>>
 */

namespace Tests\Unit\Batch;


use EFrane\ConsoleAdditions\Batch\Batch;
use EFrane\ConsoleAdditions\Batch\InstanceCommandAction;
use EFrane\ConsoleAdditions\Batch\ProcessAction;
use EFrane\ConsoleAdditions\Batch\StringCommandAction;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Process\Process;
use Tests\TestCommand;

class BatchTest extends BatchTestCase
{
    public function testAdd()
    {
        $sut = new Batch($this->app, $this->output);
        $sut->add('list');

        $this->assertEquals(1, count($sut->getActions()));

        if (PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 3) {
            $this->assertIsArray($sut->getActions());
        }
        
        $sut->add('help');

        $this->assertEquals(
            [
                (new StringCommandAction('list'))->setApplication($this->app),
                (new StringCommandAction('help'))->setApplication($this->app),
            ],
            $sut->getActions()
        );
    }

    public function testRunOne()
    {
        $sut = new Batch($this->app, $this->output);

        try {
            $action = new StringCommandAction('list');
            $action->setApplication($this->app);


            $sut->runOne($action);
        } catch (\Exception $e) {
        }

        $expected = <<<HD
testApp

{'fraction_non_alphanumeric': 0.14607532558958114, 'fraction_numerical': 0.004927842309046111, 'mean_word_length': 2.6576576576576576, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 47, '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': '4416185', 'n_tokens_mistral': 861, 'n_tokens_neox': 828, 'n_words': 146}