Test some preprocessors.

This commit is contained in:
James Cole
2018-01-05 17:51:05 +01:00
parent 5d54939bd4
commit 9e1586878b
5 changed files with 111 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ use Illuminate\Console\Command;
use Monolog\Handler\AbstractProcessingHandler;
/**
* @codeCoverageIgnore
* Class CommandHandler.
*/
class CommandHandler extends AbstractProcessingHandler

View File

@@ -34,6 +34,11 @@ class TagsComma implements PreProcessorInterface
*/
public function run(string $value): array
{
return explode(',', $value);
$set = explode(',', $value);
$set = array_map('trim', $set);
$set = array_filter($set, 'strlen');
$return = array_values($set);
return $return;
}
}

View File

@@ -34,6 +34,11 @@ class TagsSpace implements PreProcessorInterface
*/
public function run(string $value): array
{
return explode(' ', $value);
$set = explode(' ', $value);
$set = array_map('trim', $set);
$set = array_filter($set, 'strlen');
$return = array_values($set);
return $return;
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* TagsCommaTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\MapperPreProcess;
use FireflyIII\Import\MapperPreProcess\TagsComma;
use Tests\TestCase;
/**
* Class TagsCommaTest
*/
class TagsCommaTest extends TestCase
{
/**
* \FireflyIII\Import\MapperPreProcess\TagsComma::run
*/
public function testBasic()
{
$input = 'some,tags, with, spaces ,and,without,,';
$output = ['some', 'tags', 'with', 'spaces', 'and', 'without'];
$mapper = new TagsComma();
$result = $mapper->run($input);
$this->assertEquals($output, $result);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* TagsSpaceTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Import\MapperPreProcess;
use FireflyIII\Import\MapperPreProcess\TagsComma;
use FireflyIII\Import\MapperPreProcess\TagsSpace;
use Tests\TestCase;
/**
* Class TagsSpaceTest
*/
class TagsSpaceTest extends TestCase
{
/**
* \FireflyIII\Import\MapperPreProcess\TagsSpace::run
*/
public function testBasic()
{
$input = 'some tags with spaces,and without ';
$output = ['some', 'tags', 'with', 'spaces,and', 'without'];
$mapper = new TagsSpace();
$result = $mapper->run($input);
$this->assertEquals($output, $result);
}
}