Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Tests/Unit/Segment/MinimaleVorlaufzeitSEPALastschriftTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Fhp\Tests\Unit\Segment;

use Fhp\Segment\BME\HIBMESv1;
use Fhp\Segment\DME\HIDMESv1;
use Fhp\Segment\DSE\MinimaleVorlaufzeitSEPALastschrift;

class MinimaleVorlaufzeitSEPALastschriftTest extends \PHPUnit\Framework\TestCase
{
/**
* Real response from Postbank, as also used by the Postbank integration tests. Both segments
* are only offered in version 1, which is what the parameters below describe: one day of lead
* time for FNAL/RCUR and for FRST/OOFF, at most 30 days.
*/
public const REAL_POSTBANK_HIDMES = "HIDMES:36:1:3+1+1+0+1:30:1:30:1000:J:J'";
public const REAL_POSTBANK_HIBMES = "HIBMES:37:1:3+1+1+0+1:30:1:30:1000:J:J'";

public function testGetMinimalLeadTimeFromVersion1()
{
$parameter = HIDMESv1::parse(static::REAL_POSTBANK_HIDMES)->getParameter();

$recurring = $parameter->getMinimalLeadTime('RCUR');
$this->assertInstanceOf(MinimaleVorlaufzeitSEPALastschrift::class, $recurring);
$this->assertEquals(1, $recurring->minimaleSEPAVorlaufzeit);

// Version 1 states the lead time per sequence type and carries neither of the two codes
// that version 2 encodes, so they stay unset.
$this->assertNull($recurring->unterstuetzteSEPALastschriftartenCodiert);
$this->assertNull($recurring->sequenceTypeCodiert);

$this->assertEquals(1, $parameter->getMinimalLeadTime('FRST')->minimaleSEPAVorlaufzeit);
}

public function testGetMinimalLeadTimeFromVersion1B2B()
{
$parameter = HIBMESv1::parse(static::REAL_POSTBANK_HIBMES)->getParameter();

$this->assertEquals(1, $parameter->getMinimalLeadTime('RCUR')->minimaleSEPAVorlaufzeit);
$this->assertEquals(1, $parameter->getMinimalLeadTime('OOFF')->minimaleSEPAVorlaufzeit);
}

/**
* The B2B variant of the coded format has no field for the direct debit type, so the parser
* passes none.
*/
public function testParseCodedB2B()
{
$parsed = MinimaleVorlaufzeitSEPALastschrift::parseCodedB2B('1;2;120000');

$this->assertEquals(2, $parsed['B2B']['RCUR']->minimaleSEPAVorlaufzeit);
$this->assertEquals('120000', $parsed['B2B']['FNAL']->cutOffZeit);
$this->assertNull($parsed['B2B']['RCUR']->unterstuetzteSEPALastschriftartenCodiert);
$this->assertEquals(1, $parsed['B2B']['RCUR']->sequenceTypeCodiert);
}

public function testParseCoded()
{
$parsed = MinimaleVorlaufzeitSEPALastschrift::parseCoded('0;1;2;120000');

$this->assertEquals(2, $parsed['CORE']['RCUR']->minimaleSEPAVorlaufzeit);
$this->assertEquals(0, $parsed['CORE']['RCUR']->unterstuetzteSEPALastschriftartenCodiert);
$this->assertEquals(1, $parsed['CORE']['RCUR']->sequenceTypeCodiert);
}
}
8 changes: 4 additions & 4 deletions src/Segment/DSE/MinimaleVorlaufzeitSEPALastschrift.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class MinimaleVorlaufzeitSEPALastschrift
['FRST', 'OOFF'],
];

/** Must be 0,1,2 */
public int $unterstuetzteSEPALastschriftartenCodiert;
/** Must be 0,1,2, or null when the segment does not state it (version 1, and B2B in general) */
public ?int $unterstuetzteSEPALastschriftartenCodiert = null;

/** Must be 0,1,2 */
public int $sequenceTypeCodiert;
/** Must be 0,1,2, or null when the segment does not state it (version 1) */
public ?int $sequenceTypeCodiert = null;

/** In Days */
public int $minimaleSEPAVorlaufzeit;
Expand Down