mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-20 19:42:02 +00:00
Test some preprocessors.
This commit is contained in:
@@ -26,6 +26,7 @@ use Illuminate\Console\Command;
|
|||||||
use Monolog\Handler\AbstractProcessingHandler;
|
use Monolog\Handler\AbstractProcessingHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* Class CommandHandler.
|
* Class CommandHandler.
|
||||||
*/
|
*/
|
||||||
class CommandHandler extends AbstractProcessingHandler
|
class CommandHandler extends AbstractProcessingHandler
|
||||||
|
@@ -34,6 +34,11 @@ class TagsComma implements PreProcessorInterface
|
|||||||
*/
|
*/
|
||||||
public function run(string $value): array
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,11 @@ class TagsSpace implements PreProcessorInterface
|
|||||||
*/
|
*/
|
||||||
public function run(string $value): array
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
tests/Unit/Import/MapperPreProcess/TagsCommaTest.php
Normal file
49
tests/Unit/Import/MapperPreProcess/TagsCommaTest.php
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php
Normal file
49
tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user