Skip to content

Firefly III: a personal finances manager

Test some preprocessors.

James Cole9e1586878b5e
diff --git a/app/Import/Logging/CommandHandler.php b/app/Import/Logging/CommandHandler.php
index c35663e53e..eb1d9c1b7a 100644
--- a/app/Import/Logging/CommandHandler.php
+++ b/app/Import/Logging/CommandHandler.php
@@ -26,6 +26,7 @@ use Illuminate\Console\Command;
use Monolog\Handler\AbstractProcessingHandler;
/**
+ * @codeCoverageIgnore
* Class CommandHandler.
*/
class CommandHandler extends AbstractProcessingHandler
diff --git a/app/Import/MapperPreProcess/TagsComma.php b/app/Import/MapperPreProcess/TagsComma.php
index d3d2e4165a..43d628c577 100644
--- a/app/Import/MapperPreProcess/TagsComma.php
+++ b/app/Import/MapperPreProcess/TagsComma.php
@@ -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;
}
}
diff --git a/app/Import/MapperPreProcess/TagsSpace.php b/app/Import/MapperPreProcess/TagsSpace.php
index cd897e7c67..d8967ee9fb 100644
--- a/app/Import/MapperPreProcess/TagsSpace.php
+++ b/app/Import/MapperPreProcess/TagsSpace.php
@@ -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;
}
}
diff --git a/tests/Unit/Import/MapperPreProcess/TagsCommaTest.php b/tests/Unit/Import/MapperPreProcess/TagsCommaTest.php
new file mode 100644
index 0000000000..c3deeb1516
--- /dev/null
+++ b/tests/Unit/Import/MapperPreProcess/TagsCommaTest.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * TagsCommaTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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);
+
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php b/tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php
new file mode 100644
index 0000000000..207b5151cb
--- /dev/null
+++ b/tests/Unit/Import/MapperPreProcess/TagsSpaceTest.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * TagsSpaceTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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);
+ }
+
+}
\ No newline at end of file