mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Small textual changes for #1159
This commit is contained in:
parent
60f2c19d9d
commit
742e03944d
@ -21,17 +21,29 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\FinTS;
|
||||
|
||||
use Fhp\Model\StatementOfAccount\Transaction as FinTSTransaction;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class MetadataParser
|
||||
*/
|
||||
class MetadataParser
|
||||
{
|
||||
function getDescription(FinTSTransaction $transaction)
|
||||
/**
|
||||
* @param FinTSTransaction $transaction
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(FinTSTransaction $transaction): string
|
||||
{
|
||||
//Given a description like 'EREF+AbcCRED+DE123SVWZ+DefABWA+Ghi' or 'EREF+AbcCRED+DE123SVWZ+Def' return 'Def'
|
||||
$finTSDescription = $transaction->getDescription1();
|
||||
if (preg_match('/SVWZ\+([^\+]*)([A-Z]{4}\+|$)/', $finTSDescription, $matches) === 1) {
|
||||
$matches = [];
|
||||
if (1 === preg_match('/SVWZ\+([^\+]*)([A-Z]{4}\+|$)/', $finTSDescription, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
return $finTSDescription;
|
||||
}
|
||||
}
|
@ -23,11 +23,14 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Support\FinTS;
|
||||
|
||||
use Fhp\Model\StatementOfAccount\Transaction as FinTSTransaction;
|
||||
|
||||
use FireflyIII\Support\FinTS\MetadataParser;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class MetadataParserTest
|
||||
*/
|
||||
class MetadataParserTest extends TestCase
|
||||
{
|
||||
|
||||
@ -44,28 +47,43 @@ class MetadataParserTest extends TestCase
|
||||
$this->metadataParser = new MetadataParser();
|
||||
}
|
||||
|
||||
public function testDescriptionIsCorrectlyExtractedFromBeginning()
|
||||
/**
|
||||
* @covers \FireflyIII\Support\FinTS\MetadataParser
|
||||
*/
|
||||
public function testDescriptionIsCorrectlyExtractedFromBeginning(): void
|
||||
{
|
||||
$transaction = $this->createTransactionWithDescription1('SVWZ+DescriptionABWA+xxx');
|
||||
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
||||
}
|
||||
|
||||
public function testDescriptionIsCorrectlyExtractedFromMiddle()
|
||||
{
|
||||
$transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+DescriptionABWA+Ghi');
|
||||
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
||||
}
|
||||
|
||||
public function testDescriptionIsCorrectlyExtractedFromEnd()
|
||||
/**
|
||||
* @covers \FireflyIII\Support\FinTS\MetadataParser
|
||||
*/
|
||||
public function testDescriptionIsCorrectlyExtractedFromEnd(): void
|
||||
{
|
||||
$transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+Description');
|
||||
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
||||
}
|
||||
|
||||
private function createTransactionWithDescription1(string $description1)
|
||||
/**
|
||||
* @covers \FireflyIII\Support\FinTS\MetadataParser
|
||||
*/
|
||||
public function testDescriptionIsCorrectlyExtractedFromMiddle(): void
|
||||
{
|
||||
$transaction = $this->createTransactionWithDescription1('EREF+AbcCRED+DE123SVWZ+DescriptionABWA+Ghi');
|
||||
$this->assertEquals('Description', $this->metadataParser->getDescription($transaction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description1
|
||||
*
|
||||
* @return FinTSTransaction
|
||||
*/
|
||||
private function createTransactionWithDescription1(string $description1): FinTSTransaction
|
||||
{
|
||||
$transaction = $this->mock(FinTSTransaction::class);
|
||||
$transaction->shouldReceive('getDescription1')->atLeast()->once()->andReturn($description1);
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user